How to Convert RGB to HEX, Including Leading Zeros and Clamping
Written by Toolsxulo Team · Last updated November 4, 2026
The RGB to HEX converter takes three numbers from 0 to 255 and returns a six-digit, uppercase HEX code, plus HSL, CMYK, and contrast. It is the reverse of the HEX to RGB converter, and from either page you can move on to the color picker.
Open the tool: RGB to HEX ConverterThe worked color
Enter 242, 183, and 5, and the converter returns #F2B705. Each channel becomes a two-digit hex pair: 242 is F2, 183 is B7, and 5 is 05 — with a leading zero, or the string would be broken. The same swatch is also hsl(45, 96%, 48%), and the contrast is 1.82 on white and 11.55 on black.
Leading zeros, and values outside the range
Every channel has to come out as two digits. That is why 5 is written 05, and 15 is written 0F. If you enter a number larger than 255, the converter clamps it to 255, which is FF. A negative number is clamped to 0. That keeps the code valid, but the color you get is the clamped color, not the original number.
What the converter does not accept
The fields are integers from 0 to 255. It does not read CSS syntax such as rgb(95%, 40%, 2%). If you already have a HEX string and want the channels, use HEX to RGB. If you want to nudge the hue on a wheel, open the color picker.
Frequently asked
- Why do RGB values stop at 255?
- Because each channel is stored in one byte, which allows 256 values, from 0 to 255. That is also why each HEX channel is two digits, from 00 to FF. In this converter, that is the full range you can enter.
- If I average two RGB colors, is that the same as averaging their HEX strings?
- No. Convert each color to three numbers first, average the numbers, then convert back to HEX in the converter. HEX strings are text, not something you can average as they are.
- Can I convert directly from rgb(95%, 40%, 2%)?
- Not in this tool. It takes 0 to 255, not percentages. Convert the percentages to numbers first (95% is about 242), then enter those.
- Does converting RGB to HEX ever lose precision?
- Not when the input is three integers from 0 to 255. Each of those values maps to one HEX pair, and the reverse conversion returns the same numbers.