RGB to Hex Converter
Turn red, green and blue values into a hexadecimal color code used in CSS and design tools.
What the converter returns
You supply three channel values from 0 to 255 and the tool returns the six-digit hex code used by CSS, design tools and image formats. At the defaults red 255, green 100 and blue 50 produce #FF6432, a warm orange.
Each channel takes exactly two hex characters, so the output is always seven characters including the leading hash: one pair for red, one for green, one for blue. The order is fixed and never alphabetical, which is why the code always reads red first.
How one channel becomes two digits
A byte holds values from 0 to 255, and two hex digits also span 0 to 255, because 16 × 16 = 256. The high digit counts how many sixteens fit into the channel and the low digit is what remains. Those two digits are your base-16 representation of the same number.
The leading zero matters. A channel of 10 produces A, which is one character, so the code pads it to 0A. Without that pad the six-digit code would collapse to five digits and every channel after it would shift by one position, which is how a valid color turns into a different valid color.
Worked example: 255, 100, 50
Red is 255: 255 ÷ 16 = 15 remainder 15, and 15 is F, so the pair is FF. Green is 100: 100 ÷ 16 = 6 remainder 4, so the pair is 64. Blue is 50: 50 ÷ 16 = 3 remainder 2, so the pair is 32. Joined in order, the code is #FF6432.
| Channel | Decimal | High digit | Low digit | Hex pair |
|---|---|---|---|---|
| Red | 255 | 15 | 15 | FF |
| Green | 100 | 6 | 4 | 64 |
| Blue | 50 | 3 | 2 | 32 |
Reverse it to check: FF is 15 × 16 + 15 = 255, 64 is 6 × 16 + 4 = 100, and 32 is 3 × 16 + 2 = 50. Any disagreement between the forward and reverse sums means a digit was dropped or a pair was misread.
Channel values that produce letters
Anything at or above 160 has a high digit of 10 or more, so the code contains letters. 165 divides as 10 remainder 5, giving A5. That is why orange, #FFA500, looks so different from red at a glance even though the red channel is identical.
Hex codes you will recognise
| Code | RGB | What it is |
|---|---|---|
| #000000 | 0, 0, 0 | black, every channel off |
| #FFFFFF | 255, 255, 255 | white, every channel full |
| #FF0000 | 255, 0, 0 | pure red |
| #00FF00 | 0, 255, 0 | pure green |
| #0000FF | 0, 0, 255 | pure blue |
| #808080 | 128, 128, 128 | mid grey, all channels equal |
Grey is the useful diagnostic: if the three channel values are equal, the result is neutral and the code repeats the same pair three times. A slight tint appears the moment one channel differs by even 1, which is why 128, 129, 128 is not quite grey.
Where the conversion bites
- Dropping the zero pad, so 10 becomes A instead of 0A and the code shortens by one character
- Entering percentages instead of bytes: 50% of 255 is 127.5, not 50
- Swapping the order to BGR, which is what some camera and OpenCV APIs expect internally
- Assuming the code describes printed ink: hex is light, and a printer converts to CMYK with a different gamut
- Forgetting that alpha adds two more digits, giving #RRGGBBAA rather than a different color
The order mistake is silent because a swapped code still renders something. #FF6432 is orange, while #3264FF is a mid blue; both are valid, and only a side-by-side comparison reveals the transposition. When a color looks wrong but not broken, check channel order first.
The three-digit shorthand
CSS accepts a short form where each digit is doubled: #F64 expands to #FF6644, which is 255, 102, 68. This only works when both digits of every pair are identical, so it covers just 4,096 of the 16.7 million colors. Designers use it for hand-written styles, and tools expand it before storing.
Why the color model is 24-bit
Three channels of eight bits each give 24 bits, and 224 is 16,777,216 distinct colors. That number is the ceiling of the format, not a claim about what a screen can show; most displays cover a subset of it, and wider-gamut panels describe colors in a different space entirely.
The hex code stores the numbers, not the appearance. Two screens given #FF6432 may render visibly different oranges because of panel calibration. For matching across devices you need a color profile, which sits outside the code itself.
CSS also accepts the same three numbers written as rgb(255, 100, 50), and modern syntax allows rgb(255 100 50) with spaces. That form is easier to compute from channel values, while the hex form is more compact and easier to copy. Both describe one color, so switching between them is a formatting choice rather than a conversion.
- 8 bits per channel, so 256 steps from off to full
- 24 bits for three channels, giving 16,777,216 colors
- 32 bits once alpha is added, giving 4,294,967,296 combinations
Rounding and range
The inputs are rounded to whole numbers and clamped to 0–255, so 100.6 becomes 101 and 300 becomes 255. There is no fractional channel in the 8-bit model; if you have a value like 127.5, pick 127 or 128 and accept a one-step difference, which is invisible at normal viewing.
Negative values clamp to 0 rather than wrapping, so an out-of-range calculation produces black rather than a bright color. That behaviour is deliberate: a clamp keeps the result interpretable, while a wrap would turn a small error into a wildly different hue.
Frequently asked questions
How do I convert RGB to hex?
Divide each channel by 16 to get the high digit and take the remainder as the low digit, then join the three pairs in red, green, blue order behind a hash. 255, 100, 50 becomes #FF6432.
What is 255, 255, 255 in hex?
#FFFFFF, which is white. Every channel is at full intensity, and 255 is FF in hex, so the code is three FF pairs.
Why is my code five characters long?
A channel value below 16 produces a single hex digit, and one pad was probably dropped. 10 should be written 0A, so the code stays six digits.
What does #FF0000 mean?
Pure red: 255 in the red channel, 0 in green and 0 in blue. The three pairs read FF, 00 and 00.
How many colors can a hex code represent?
16,777,216, since three 8-bit channels give 224 combinations. Adding an alpha channel takes it to 232, about 4.29 billion.
Is #F64 a valid color?
Yes, as shorthand. It expands to #FF6644, which is 255, 102, 68. The short form only works when both digits in every pair match.
What is 100 in hex?
64. Divide 100 by 16 to get 6 remainder 4, so the high digit is 6 and the low digit is 4. That is the green channel of the default #FF6432.
Why does my color look different on another screen?
The code stores channel values, not a measured appearance. Different panels, brightness settings and color profiles render the same six digits differently.
Can a hex color be negative or above 255?
No. Each channel is one byte, so the valid range is 0 to 255. Inputs outside that range are clamped to the nearest end rather than wrapped.
Method and sources
- 24-bit RGB color model and hexadecimal notation.