Skip to content
hexcolorcodepicker.com

How to Convert HEX to RGB by Hand

The 3 steps

Convert HEX to RGB in 3 steps: split the code into 3 pairs, turn each pair into a decimal, and write the 3 decimals as rgb(). The code #FF5733 splits into FF, 57, and 33, which become 255, 87, and 51, so the answer is rgb(255, 87, 51).

Start by dropping the hash sign, then cut the 6 digits into pairs: the first 2 digits are red, the middle 2 are green, and the last 2 are blue. Each pair is a 2-digit hex number, and each one becomes a decimal from 0 to 255. Write the 3 decimals in order inside rgb(), with commas between them, and you have the RGB form of the same color.

#FF5733 → FF · 57 · 33

Drop the hash, then cut the 6 digits into 3 pairs: red, green, blue.

Step forward and back through the conversion of #FF5733.

Step 1: split into pairs

Split the 6 digits after the hash into 3 pairs of 2 digits. The first pair is red, the second pair is green, and the third pair is blue, so #3B82F6 splits into 3B, 82, and F6.

The order never changes: red always comes first, green second, and blue third. If the code has only 3 digits, expand it first by doubling each digit, so #F53 becomes #FF5533 before you split it. A code with 8 digits has an extra alpha pair at the end, which you set aside for now and handle in our alpha transparency guide. Count the digits before you start: 6 digits means 3 pairs, and anything else needs a fix first.

3B · R82 · GF6 · B

6 digits: 3 pairs, red first, green second, blue third.

Step 2: turn one hex pair into a decimal

Turn a hex pair into a decimal by multiplying the first digit by 16 and adding the second digit. The pair 57 means 5 times 16 plus 7, which is 87. The letters A to F mean 10 to 15, so F6 means 15 times 16 plus 6, which is 246.

Each hex digit is worth 16 times more in the left place than in the right place, because hex is base 16. So a pair XY always equals X times 16 plus Y, where X and Y are the digit values. The pair 00 equals 0, the pair FF equals 255, and the pair 80 equals 128, half of the range. Learn the letter values — A is 10 through F is 15 — and every pair becomes one multiplication and addition.

5 × 16 + 7 = 87

Change either digit: the math line and the 0-to-255 bar update, so you see why 57 is 87 and F6 is 246.

Step 3: write the answer as rgb()

Write the 3 decimals in order as rgb(red, green, blue). For #3B82F6 the decimals are 59, 130, and 246, so the answer is rgb(59, 130, 246). The order is the same as the pairs: red first, green second, blue third.

The rgb() form takes the same 3 numbers in the same order, each from 0 to 255. If a decimal comes out below 0 or above 255, you made an arithmetic slip, because no pair can give a value outside that range. A quick check is to look at the swatch: a high red number should look reddish, and a high blue number should look bluish.

59130246

Three decimal boxes join into rgb() beside the swatch.

Worked examples

Three worked examples show the full method: #FF5733, #3b5bdb, and #3B82F6. Each one splits into pairs, converts each pair with the times-16 rule, and ends as an rgb() value you can check against the swatch.

Work through each example on paper before you read its answer, and check your work pair by pair. The first example is a warm orange-red, the second is a strong blue, and the third is the bright blue used across this site. If one pair is wrong, only that channel is wrong, so you can fix one pair without redoing the whole code. The practice exercises in H2-6 give you 4 more codes to try on your own.

Worked example 1 — #FF5733 = rgb(255, 87, 51)

#FF5733 is rgb(255, 87, 51). FF is 15 × 16 + 15 = 255. 57 is 5 × 16 + 7 = 87. 33 is 3 × 16 + 3 = 51. Red is full, green is about one third, and blue is about one fifth, so the color is a bright orange-red.

Worked example 2 — #3b5bdb = rgb(59, 91, 219)

#3b5bdb is rgb(59, 91, 219). 3b is 3 × 16 + 11 = 59. 5b is 5 × 16 + 11 = 91. db is 13 × 16 + 11 = 219. Lowercase letters mean the same as uppercase, so #3b5bdb and #3B5BDB are the same blue.

Worked example 3 — #3B82F6 = rgb(59, 130, 246)

#3B82F6 is rgb(59, 130, 246). 3B is 3 × 16 + 11 = 59. 82 is 8 × 16 + 2 = 130. F6 is 15 × 16 + 6 = 246. Blue is nearly full, green is about half, and red is low, so the color is a clear bright blue.

rgb(255, 87, 51)

    Tap a card to reveal one line of math at a time.

    Practice exercises with answers

    Try 4 codes on your own, then check your answers below. The codes are #FF0000, #00FF00, #3498DB, and #FF5733 in lowercase. Each one uses the same 3 steps, and each answer is given in full so you can find which pair went wrong.

    Do each exercise on paper before you look at its answer, and write the times-16 math for every pair. The first 2 are pure colors that test whether your pairs are in the right order. The third is a real blue from a worked example in our RGB to HEX conversion guide, so you can cross-check it in both directions. If an answer is wrong, recheck the letter values first, because A through F are the most common slip.

    Practice answers

    1. #FF0000 = rgb(255, 0, 0). FF is 255, 00 is 0, and 00 is 0. Pure red.
    2. #00FF00 = rgb(0, 255, 0). 00 is 0, FF is 255, and 00 is 0. Pure green, also called lime.
    3. #3498DB = rgb(52, 152, 219). 34 is 3 × 16 + 4 = 52. 98 is 9 × 16 + 8 = 152. DB is 13 × 16 + 11 = 219.
    4. #ff5733 = rgb(255, 87, 51). Same as worked example 1; lowercase changes nothing.

    Try one: what is #3498DB in RGB?

    Type 3 decimals. The swatch stays hidden until you answer.

    Reveal the full times-16 working

    34 is 3 × 16 + 4 = 52. 98 is 9 × 16 + 8 = 152. DB is 13 × 16 + 11 = 219. So #3498DB = rgb(52, 152, 219).

    Frequently asked questions

    Each pair equals its first digit times 16 plus its second digit. For the pair XY, the decimal is X × 16 + Y, with A = 10, B = 11, C = 12, D = 13, E = 14, and F = 15. Do that for the red, green, and blue pairs, then write the 3 decimals as rgb().