RGB to Hex Calculator
Image editors and many design programs describe a color as three numbers from 0 to 255, but stylesheets and most web tooling want a single six-digit hex code. This calculator converts the other way, taking your red, green and blue channel values and joining them into a hex color code. The method is direct: convert each channel from its decimal value into a two-digit hexadecimal pair, then place red, green and blue side by side. A value of 51 becomes 33, 102 becomes 66 and 204 becomes CC, which join to make 3366CC. Because each channel is exactly one byte, it always maps to two hex digits from 00 to FF, and single-digit results are padded with a leading zero so the code is always six characters. Enter any three values from 0 to 255 and the page returns the hex code with a leading hash, ready to paste into CSS, and a swatch so you can confirm the color visually. Values outside the valid range are clamped to 0 or 255 first. Every result is computed deterministically by converting and concatenating the bytes, never estimated or looked up, so the code updates instantly, with the method and a worked example shown below for verification.
Each channel becomes a two-digit hex pair, joined red then green then blue: hex = R16 + G16 + B16. The values (51, 102, 204) convert to the code #3366CC.
RGB to hex formula
hex = pad(R in base 16) + pad(G in base 16) + pad(B in base 16)
each channel ranges from 0 to 255 (one byte)
pad means a leading zero so each pair is two digits
order is red, then green, then blue
A channel value divided by 16 gives the left hex digit and the remainder gives the right digit. Joining the three padded pairs produces the six-character code.
Worked example
Convert the channel values red 51, green 102 and blue 204 into a hex code.
- Red 51 = 3 x 16 + 3 = 33 in hex
- Green 102 = 6 x 16 + 6 = 66 in hex
- Blue 204 = 12 x 16 + 12 = CC in hex
- Join the pairs: #3366CC
The values (51, 102, 204) give the hex code #3366CC. These are the calculator's default inputs, so the result above matches the widget exactly.
Decimal to hex pair reference
A few common channel values and their two-digit hex pairs.
| Decimal | Hex pair |
|---|---|
| 0 | 00 |
| 51 | 33 |
| 102 | 66 |
| 128 | 80 |
| 204 | CC |
| 255 | FF |
Number bases and digital representation: US National Institute of Standards and Technology (NIST).
RGB to hex calculator: frequently asked questions
How do you convert RGB to hex?
Convert each channel value from 0 to 255 into a two-digit hexadecimal number, then join red, green and blue in that order. For example 51 becomes 33, 102 becomes 66 and 204 becomes CC, giving the hex code 3366CC.
Why two digits per channel?
Each channel ranges from 0 to 255, which is exactly one byte, or 8 bits. Two hex digits represent 8 bits, so each channel always maps to a two-digit pair from 00 to FF. Single-digit results are padded with a leading zero.
What if a value is above 255 or below 0?
Channel values must be whole numbers from 0 to 255. Anything outside that range is clamped to the nearest valid value before conversion, because a byte cannot hold more than 255 or less than 0.
Is the hash part of the hex code?
The hash is a prefix used in CSS and design tools to mark the value as a hex color. The code itself is the six digits. This calculator returns the code with a hash so you can paste it directly into a stylesheet.
Is the result computed automatically?
Yes. The page converts each channel to base 16 and joins the pairs deterministically. No value is estimated or hard-coded, so changing any channel updates the hex code instantly.
Official sources
- Number bases and digital color representation: US National Institute of Standards and Technology (NIST). As at 25 June 2026.
Reviewed by the CalculatorHub team, edited by James Graham, 25 June 2026. See our methodology. This is general information, not financial, tax, legal or investment advice.