Color & Design Guides

How to Convert RGB to HEX Manually (Step by Step)

admin
November 2, 2026 Updated: Nov 3, 2026 5 min read 0 Comments

To convert RGB to HEX by hand, take each of the three RGB values, divide it by 16, and write the quotient and the remainder as hexadecimal digits. Join the three two-digit results together after a #. For example, rgb(255, 99, 71) becomes #FF6347. It takes under a minute once you know the trick, and this guide walks through the method with three fully worked examples.

If you need a whole palette converted and the maths does not interest you, our RGB to HEX Converter does it instantly. But understanding the manual method is genuinely useful: it explains why hex codes look the way they do, and it lets you sanity-check any converter’s output.

What RGB and HEX actually are

RGB and HEX describe exactly the same colours. They are just two ways of writing three numbers:

RGB writes the red, green and blue components in ordinary decimal: rgb(255, 99, 71). Each value runs from 0 (none of that colour) to 255 (full intensity).

HEX writes the same three values in base 16 (hexadecimal), packed into one string: #FF6347. The first pair of digits is red, the second pair is green, the third pair is blue.

So conversion is not really about colour at all — it is about rewriting three decimal numbers, each between 0 and 255, as two hex digits each. As MDN’s guide to CSS colour values explains, hex strings and the rgb() function are simply two syntaxes for the same sRGB colour.

The only maths you need: hexadecimal digits

Hexadecimal counts in sixteens instead of tens, so it needs sixteen digit symbols. It uses 0–9 as normal, then A–F for 10–15.

Decimal 0–9 10 11 12 13 14 15
Hex 0–9 A B C D E F

Every RGB value (0–255) becomes exactly two hex digits, because 255 is FF in hex — the largest two-digit hex number.

Divide the value by 16. The quotient is the first hex digit; the remainder is the second hex digit.

That is the entire method. Here it is applied, step by step.

The 3-step method

  1. Split the colour into its red, green and blue values.
  2. Convert each value by dividing by 16: quotient → first digit, remainder → second digit. If a digit is 10–15, write it as a letter A–F.
  3. Join the three pairs in red-green-blue order and put a # in front.

Worked example 1: rgb(255, 99, 71) → #FF6347 (tomato)

Channel Value ÷ 16 First digit Remainder Second digit Pair
Red 255 15 remainder 15 F 15 F FF
Green 99 6 remainder 3 6 3 3 63
Blue 71 4 remainder 7 4 7 7 47

Join the pairs: #FF6347. Note the red channel: 255 ÷ 16 = 15 remainder 15, and 15 is written F in both positions, giving FF.

Worked example 2: rgb(30, 144, 255) → #1E90FF (dodger blue)

Channel Value ÷ 16 First digit Remainder Second digit Pair
Red 30 1 remainder 14 1 14 E 1E
Green 144 9 remainder 0 9 0 0 90
Blue 255 15 remainder 15 F 15 F FF

Join the pairs: #1E90FF. This example shows the two cases people trip over: a remainder of 14 becomes the letter E, and a remainder of 0 is still written as a digit — the green pair is 90, never just 9.

Worked example 3: rgb(46, 139, 87) → #2E8B57 (sea green)

Channel Value ÷ 16 First digit Remainder Second digit Pair
Red 46 2 remainder 14 2 14 E 2E
Green 139 8 remainder 11 8 11 B 8B
Blue 87 5 remainder 7 5 7 7 57

Join the pairs: #2E8B57. With a letter appearing in two of the three channels, this is a good test case: if your result for the green channel is not 8B, check how you mapped the remainder 11.

Quick conversion table for common colours

Colour RGB HEX
Black rgb(0, 0, 0) #000000
White rgb(255, 255, 255) #FFFFFF
Red rgb(255, 0, 0) #FF0000
Lime rgb(0, 255, 0) #00FF00
Blue rgb(0, 0, 255) #0000FF
Yellow rgb(255, 255, 0) #FFFF00
Magenta rgb(255, 0, 255) #FF00FF
Grey rgb(128, 128, 128) #808080
Orange rgb(255, 165, 0) #FFA500
Rebecca purple rgb(102, 51, 153) #663399

Spot the pattern in the grey row: 128 ÷ 16 = 8 remainder 0, so each channel is 80, giving #808080.

Two shortcuts worth knowing

Leading zeros are mandatory. If a channel value is below 16, its first digit is 0 — and you must write it. rgb(5, 10, 15) converts to #050A0F, not #5AF. A hex colour code is always six digits (or eight with transparency); a five-digit code is invalid.

Three-digit shorthand. When both digits of every pair are identical, CSS lets you write just one digit per channel: #FF6633 becomes #F63, and #FFFFFF becomes #FFF.

What about RGBA and percentage values?

Two variations you may meet:

  • Transparency (alpha): an alpha value can be added as a fourth hex pair, giving an eight-digit code like #FF634780. The alpha is converted the same way, from a 0–255 scale.
  • Percentages: some tools give RGB as percentages, such as rgb(100%, 39%, 28%). Convert each percentage to the 0–255 scale first, then convert as above.

Common mistakes to avoid

  • Dropping the leading zero in pairs like 0A or 05 — the most frequent error, and it breaks or changes the colour.
  • Converting in the wrong order. The pairs must stay red, green, blue. #FF6347 and #47FF63 are completely different colours.
  • Leaving remainders above 9 as numbers. A remainder of 11 is B, not “11” — writing it out makes the code too long.
  • Forgetting that 255 is FF, not 100. Hex digits have no hundreds column; every channel fits in exactly two digits.

Skip the maths when there is a lot of it

Manual conversion is perfect for one colour or for checking a result, but converting a full design palette is slow. Use our RGB to HEX Converter for bulk work, and if you ever need to go the other way — pasting a hex code and getting the RGB triple — our HEX to RGB Converter reverses the process (each pair is multiplied back out: first digit × 16 + second digit).

Frequently asked questions

How do I convert RGB to HEX without a calculator?

Divide each RGB value by 16. Write down the whole-number result (quotient) as the first hex digit and the remainder as the second hex digit, mapping 10–15 to A–F. Join the three pairs after a #.

What is rgb(255, 0, 0) in hex?

#FF0000. Red is at full intensity (255 = FF), and green and blue are both zero (00).

Why do hex colour codes contain letters?

Because hexadecimal is base 16, it needs sixteen symbols for its digits. Numbers only provide ten (0–9), so the letters A–F provide the remaining six, for 10–15.

Is #FFF the same colour as #FFFFFF?

Yes. The three-digit form is shorthand: the browser doubles each digit, so #FFF expands to #FFFFFF (white).

Share this guide:

admin

Senior technical writer and software developer at Free Online Convert, writing about web performance, technical SEO, and browser utilities.

Leave a Reply

Your email address will not be published. Required fields are marked *