How can six short characters name more than 16 million colors? A hex color code like #3498DB is really three numbers in disguise. Each pair of characters sets the strength of red, green or blue light. Once you can read those pairs, you can decode any web color by hand in about a minute.
- A hex code is #RRGGBB: two base-16 digits each for red, green and blue.
- Each pair runs from 00 to FF, which is 0 to 255 in everyday numbers.
- Three channels of 256 values give 256 x 256 x 256 = 16,777,216 colors.
- Shorthand #RGB doubles each digit, and 8-digit #RRGGBBAA adds transparency.
- Example: #3498DB is rgb(52, 152, 219), a mid blue.
What Do the Six Characters After the Hash Mean?
The six characters are three two-digit numbers written in base 16. The first pair sets red, the second sets green, and the third sets blue. The hash sign simply tells the browser that a hex color follows.
Screens build every color by mixing red, green and blue light. A value of 00 means that light is off, and FF means it is at full strength. So #FF0000 is pure red, #000000 is black, and #FFFFFF is white.
Each pair fits in one byte of computer memory. That means a full hex color is exactly three bytes, which is why the format stays so short. Letters are not case sensitive, so #1d4ed8 and #1D4ED8 name the same blue.
Base 16 needs sixteen symbols per place. It uses the digits 0 to 9, then the letters A to F for the values 10 to 15. For a full tour of place value in other bases, see our guide on converting between number bases.
How Does #3498DB Become rgb(52, 152, 219)?
Split the code into pairs, then turn each pair into a number from 0 to 255. Multiply the first digit by 16 and add the second digit. That single rule converts any hex color to RGB.
Take #3498DB, the example used on our converter page. The red pair is 34, so red is 3 x 16 + 4 = 52. The green pair is 98, so green is 9 x 16 + 8 = 152.
The blue pair is DB. Here D stands for 13 and B stands for 11. So blue is 13 x 16 + 11 = 219, and the full color is rgb(52, 152, 219).
Want to check your own codes? The Hex to RGB Converter does the pair math for you and also shows the HSL form. For #3498DB it reports about hsl(204, 70%, 53%).
Every decoded channel must land between 0 and 255. A result like 300 means a digit was misread, often a letter value such as C, which is 12, or E, which is 14.
Why Is the Limit Exactly 16,777,216 Colors?
Each channel has 256 possible values, from 0 to 255. Three channels multiply together: 256 x 256 x 256 = 16,777,216. That is also 16 to the sixth power, one power for each hex digit.
The number 256 comes from two hex digits. Each digit has 16 options, and 16 x 16 = 256. So the largest pair, FF, equals 15 x 16 + 15 = 255.
Look at #FF5733 to see channels at work. Red is FF, or 255, which is full strength. Green is 57, or 87, and blue is 33, or 51. The result is rgb(255, 87, 51), a bright orange red.
Close codes look almost identical. Moving one channel by a single step, such as 51 to 52, is too small for most eyes to notice. That is why designers rarely need all 16.7 million options.
The count also explains the pure extremes. Black is the one code with every channel at 00. White is the one code with every channel at FF. Every other code sits somewhere between those two corners.
When Should You Write #RGB or #RRGGBBAA Instead?
Use the 3-digit shorthand when each pair has two matching digits. Use the 8-digit form when you need a see-through color. Both are standard in CSS, according to the W3C color specification.
Shorthand Doubles Each Digit
In shorthand, every digit is repeated once. So #ABC expands to #AABBCC, not #ABCABC. Likewise, #F00 is the same pure red as #FF0000.
Shorthand saves space but offers fewer choices. Only 16 x 16 x 16 = 4,096 colors fit in three digits. A code like #3498DB has no shorthand, since none of its pairs repeat a digit.
The Fourth Pair Sets Transparency
An 8-digit code adds an alpha pair at the end. Alpha 00 is fully clear, and FF is fully solid. For example, CC equals 204, and 204 out of 255 is 80 percent opacity.
A 4-digit form such as #F09A also exists, following the same doubling rule. Note that many simple converters, including ours, handle opaque colors only and ignore alpha.
How Do You Turn RGB Numbers Back Into Hex?
Divide each channel by 16. The whole-number answer is the first hex digit, and the remainder is the second. Then join the three pairs after a hash.
Try blue 219 from our first example. 219 divided by 16 is 13 with a remainder of 11. Thirteen is D and eleven is B, so 219 becomes DB.
Now convert rgb(29, 78, 216) as a full practice run. 29 is 1 x 16 + 13, which gives 1D. 78 is 4 x 16 + 14, which gives 4E. 216 is 13 x 16 + 8, which gives D8.
Join the pairs and you get #1D4ED8, a strong royal blue. Pad small values with a leading zero. For instance, 5 becomes 05, never just 5, or the pairs slide out of place.
| Hex pair | Decimal | Channel strength |
|---|---|---|
| 00 | 0 | Off |
| 33 | 51 | 20 percent |
| 80 | 128 | About half |
| CC | 204 | 80 percent |
| FF | 255 | Full |
Keep the order fixed as red, green, then blue. Swapping two pairs creates a completely different color. For example, #3498DB with red and blue swapped becomes #DB9834, a golden orange.
Can a Hex Code Tell You Whether Text Is Readable?
Not by itself, but it gives you the inputs. Readability depends on the contrast ratio between text and background. The ratio is computed from the brightness of both colors.
The W3C accessibility guidelines define contrast as (L1 + 0.05) / (L2 + 0.05). L1 is the relative luminance of the lighter color. The ratio runs from 1:1 for identical colors to 21:1 for black on white.
For normal body text, the guideline asks for at least 4.5:1. Large text needs at least 3:1. The guideline also says not to round, so 4.499:1 does not pass.
Our example blue shows why this matters. #3498DB text on white scores about 3.15:1, so it suits large headings only. The darker #1D4ED8 scores about 6.70:1 and passes for body text.
Tiny changes can flip the result. Gray #767676 on white scores about 4.54:1 and passes. The next step lighter, #777777, scores about 4.48:1 and fails.
Paste any 6-digit or 3-digit code into the Hex to RGB Converter to get its RGB and HSL values, or go the other way from three RGB numbers.
FAQs About Hex Color Codes
What Does a Hex Color Code Mean?
It is a color written as three base-16 numbers after a hash. The first pair sets red, the second sets green, and the third sets blue, each from 00 to FF.
Is Hex Better Than RGB for Web Design?
Neither is better, because both describe the same color. Hex is shorter and easy to copy, while rgb() shows each channel as a plain number from 0 to 255.
How Many Colors Can Hex Codes Show?
Six-digit hex codes show 16,777,216 colors, which is 256 x 256 x 256. The 3-digit shorthand covers only 4,096 of them.
Why Does My Shorthand Hex Code Look Wrong?
Each shorthand digit must be doubled, not repeated as a group. So #ABC means #AABBCC, and reading it as #ABCABC gives a different color.
What Do the Last Two Digits of an 8-Digit Hex Code Do?
They set alpha, or transparency. 00 is fully clear and FF is fully solid, so CC, which equals 204, gives 80 percent opacity.
Are Hex Color Codes Case Sensitive?
No. #1d4ed8 and #1D4ED8 name exactly the same blue, so you can use either uppercase or lowercase letters.
Can I Use a Hex Code for Printed Materials?
Hex codes describe screen colors made from light. Print uses ink, often measured in CMYK, so printed colors can shift and need a separate proof.
Sources
References Used in This Article
This article explains standard sRGB hex notation used in CSS and design tools. Contrast figures are computed with the WCAG formula for text on a white background. Reviewed for accuracy by Prof. Dr. Khalil Mudassar, PhD. Last updated September 27, 2026.
Author
Shakeel Muzaffar is the Founder and Editor-in-Chief of MultiCalculators.com, bringing over 15 years of experience in digital publishing, product strategy, and online tool development. He leads the platform's editorial vision, ensuring every calculator meets strict standards for accuracy, usability, and real-world value. Shakeel personally oversees content quality, formula verification workflows, and the platform's commitment to publishing tools that are genuinely useful for students, professionals, and everyday users worldwide.




