How to Convert Hex to RGB: A Simple, Accurate Guide
By Shihab Mia July 10, 2026 5 min read
Quick answer
To convert a hex color to RGB, split the six digits into three pairs (red, green, blue) and convert each pair from base 16 to a number from 0 to 255. For each pair, multiply the first digit by 16 and add the second, where A=10, B=11, C=12, D=13, E=14, F=15. Example: #3B82F6 becomes rgb(59, 130, 246), because 3B = 59, 82 = 130, and F6 = 246.
A hex code and an RGB triplet are two ways of writing the exact same color. Hex is compact and common in CSS and design tools, while RGB spells out how much red, green, and blue light the color contains on a 0 to 255 scale. Once you understand the pattern, converting between them by hand takes about ten seconds, and a converter does it instantly.
What a hex color code actually means
A hex color like #3B82F6 is made of three pairs of base-16 digits, one pair each for red, green, and blue. The hash symbol just signals that a color code follows. Reading left to right, the first pair is red, the second is green, and the third is blue.
Base 16 (hexadecimal) uses sixteen symbols instead of the ten we use in everyday counting. After 0 through 9 it keeps going with the letters A through F. So a single hex digit can represent any value from 0 to 15, and a pair of hex digits can represent any value from 00 to FF, which is 0 to 255 in decimal. That 0 to 255 range is exactly the range each channel uses in RGB, which is why the two systems map onto each other so cleanly.
The 16 hex digits and their decimal values
| Hex digit | Decimal value |
|---|---|
| 0 to 9 | 0 to 9 |
| A | 10 |
| B | 11 |
| C | 12 |
| D | 13 |
| E | 14 |
| F | 15 |
The formula for converting one pair
Every two-digit hex pair follows the same rule. The left digit is the "sixteens" place and the right digit is the "ones" place, so the math is simply:
The conversion formula
decimal value = (first digit x 16) + second digit, using A=10, B=11, C=12, D=13, E=14, F=15 for any letter digits.
Take the pair F6. F is 15, so the first digit contributes 15 x 16 = 240. The second digit, 6, contributes 6. Add them: 240 + 6 = 246. That is the red-green-blue value for that channel. If both digits are numbers, like 82, it is even easier: 8 x 16 = 128, plus 2, equals 130. The same method works for all three pairs in any hex code.
Worked example: convert #3B82F6 step by step
- Drop the hash and split into pairs. #3B82F6 becomes three pairs: 3B, 82, and F6.
- Convert the red pair, 3B. The 3 gives 3 x 16 = 48. The B is 11, which adds 11. So 48 + 11 = 59.
- Convert the green pair, 82. The 8 gives 8 x 16 = 128. The 2 adds 2. So 128 + 2 = 130.
- Convert the blue pair, F6. The F is 15, giving 15 x 16 = 240. The 6 adds 6. So 240 + 6 = 246.
- Assemble the result. Put the three numbers in order as rgb(59, 130, 246). That is the same blue as #3B82F6.
That is the entire process. Any six-digit hex code follows these exact five steps. If you would rather skip the arithmetic, a hex to RGB converter returns the values the moment you paste a code, and it never makes a math slip.
Handling shorthand hex codes
You will sometimes see three-digit hex codes like #abc or #f00. These are shorthand, and each single digit is simply doubled to make a full pair. So #abc expands to #aabbcc, and #f00 expands to #ff0000 (pure red). Expand the shorthand first, then convert each pair using the formula above.
- #f00 expands to #ff0000, which is rgb(255, 0, 0), pure red.
- #0f0 expands to #00ff00, which is rgb(0, 255, 0), pure green.
- #fff expands to #ffffff, which is rgb(255, 255, 255), white.
- #000 expands to #000000, which is rgb(0, 0, 0), black.
Common hex to RGB reference chart
These are colors you will run into often. Use them as a sanity check when you convert by hand, or as a quick lookup when you just need a familiar value.
Popular colors in hex and RGB
| Color | Hex code | RGB value |
|---|---|---|
| White | #FFFFFF | rgb(255, 255, 255) |
| Black | #000000 | rgb(0, 0, 0) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Green | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Tailwind blue | #3B82F6 | rgb(59, 130, 246) |
| Slate gray | #64748B | rgb(100, 116, 139) |
| Amber | #F59E0B | rgb(245, 158, 11) |
Common mistakes to avoid
- Reading the pairs in the wrong order. The order is always red, green, blue. Do not let a memorable middle pair trick you into swapping channels.
- Forgetting the letter values. A is 10, not 1, and F is 15, not 6. Mixing these up is the most frequent error when converting by hand.
- Treating hex like normal decimal. The pair 10 in hex is 16 in decimal, not ten. Always apply the times-sixteen rule to the left digit.
- Not expanding shorthand. A three-digit code must be doubled first. #abc is not the same as #0abc00 or any other guess, it is #aabbcc.
- Confusing an 8-digit hex with a color. A code like #3B82F6FF has a fourth pair for alpha (transparency). Convert only the first three pairs for the RGB color itself.
Good to know: why designers use both systems
Hex is popular because it is short and unambiguous in code, so CSS, design apps, and style guides lean on it heavily. RGB is easier to reason about when you want to adjust a color, since you can nudge a single channel up or down by a known amount. Because they describe identical colors, you can move between them freely. If you want a deeper comparison of when to reach for each, see our guide on hex vs RGB.
Converting between number bases is a broader skill worth having. The same base-conversion logic shows up when you convert binary to decimal, where each place is a power of two instead of a power of sixteen. Understanding one makes the other click quickly.
๐จ Try the free tool Hex to RGB Converter Free hex to RGB converter: paste any hex color like #3B82F6 and instantly get rgb(59, 130, 246), rgba, and HSL values with a live swatch and one-click copy.Once you know the pattern, hex to RGB is just three small multiplications and additions. Split into pairs, multiply each first digit by sixteen, add the second, and read the result as red, green, blue. Keep the reference chart handy, watch the common mistakes, and reach for the converter above whenever you want an instant, error-free answer.