Converting a hex code to RGB comes up constantly in web and design work — a client hands you a brand color as a hex code, but the tool you're working in only accepts RGB, or vice versa. The underlying math is simple base conversion, and understanding it removes the need to treat the process as a black box. Once the pattern clicks, it stops feeling like arbitrary math and starts feeling like a simple, repeatable lookup.

The conversion logic

A hex code like #3498DB splits into three pairs: 34, 98, and DB. Each pair is a two-digit hexadecimal (base-16) number, converted to its decimal (base-10) equivalent to get the RGB value for that channel. Hexadecimal digits run 0-9 then A-F, where A=10, B=11, C=12, D=13, E=14, F=15.

A worked example, digit by digit

34 (hex) = 3×16 + 4 = 52    98 (hex) = 9×16 + 8 = 152    DB (hex) = 13×16 + 11 = 219

So #3498DB converts to RGB(52, 152, 219). Each hex pair follows the same pattern: multiply the first digit's decimal value by 16, then add the second digit's decimal value, since each position in a two-digit hex number represents a power of 16 rather than a power of 10 the way decimal numbers work.

Why this manual math rarely matters day to day

In practice, almost nobody does this conversion by hand regularly — browsers, design tools, and dedicated converters (including the one on this page) handle it instantly and far more reliably than manual arithmetic. Understanding the logic matters more for genuinely knowing what's happening under the hood than for actually doing the conversion by hand on a regular basis.

Common situations where this conversion is actually needed

  • A brand guideline provides colors as hex codes, but a specific tool or codebase expects RGB values instead.
  • Working with an image-processing library or canvas API that operates on RGB channel values directly rather than hex strings.
  • Debugging a color rendering issue where comparing exact channel values is easier in RGB than by eye-matching hex codes.

Shorthand 3-digit hex codes

CSS also supports a shorthand 3-digit hex format, like #39D, where each digit is doubled to expand it — #39D expands to #3399DD. This shorthand only works when both digits in each full pair would be identical, which is why not every color has a valid 3-digit shorthand version, only ones where each channel's hex pair happens to repeat the same digit.

What happens with invalid hex input

A malformed hex code — wrong length, or characters outside 0-9 and A-F — typically causes a tool to either reject the input outright or fall back to a default color, rather than attempting to guess at a corrected value, which is worth knowing if a conversion tool suddenly shows an unexpected result after a typo.

Try the Color Convert tool yourself — free, instant, nothing sent anywhere.

Open the tool

Frequently asked questions

Do I need to memorize hexadecimal math to work with colors?

No, virtually every tool used for color work handles this conversion automatically and instantly; understanding the underlying logic is useful for genuine comprehension, but manual conversion is rarely a practical daily requirement.

Why does hex use letters A through F?

Because hexadecimal is base-16, it needs 16 distinct symbols per digit, and since the ordinary decimal digits 0-9 only provide 10, the letters A through F extend the count to represent values 10 through 15 in a single character.

Does every color have a valid 3-digit hex shorthand?

No, only colors where each channel's two hex digits happen to be identical (like 33, 99, DD) can be shortened to a single repeated digit; colors without this pattern must use the full 6-digit format.

Is hex case-sensitive?

No, hex codes are not case-sensitive — #3498DB and #3498db represent the exact same color, and both are valid, though many style guides prefer consistent lowercase or uppercase for readability. This kind of graceful fallback is common across most color tools specifically to avoid a confusing crash over what's usually just a small typo in an otherwise valid-looking value.