Connect via MCP →

Enter Calculation

Enter a 6-digit hex code, with or without the leading #.

Formula

Advertisement

Results

RGB Color
rgb(52, 152, 219)
from #3498DB
Red 52
Green 152
Blue 219

What Is Hex to RGB Conversion?

A hex color code is a 6-digit hexadecimal (base-16) representation of a color, commonly used in web design and CSS — for example #3498DB. Each pair of digits encodes one of the three primary color channels: red, green and blue. The RGB model expresses the same color as three decimal numbers between 0 and 255. This converter translates a hex code into its equivalent RGB triplet and shows a live color swatch.

How to Use It

Type or paste a hex color code into the box. You can include the leading # or leave it out — both work. The tool accepts standard 6-digit codes as well as 3-digit shorthand (e.g. #0AF, which expands to #00AAFF). Press calculate to see the red, green and blue values plus a preview swatch.

The Formula Explained

Conversion is a direct base-16 parse. The 6-character string is split into three 2-character pairs. Each pair is read as a hexadecimal number: the first hex digit is multiplied by 16, and the second is added. So a pair "FF" = \(15 \times 16 + 15 = 255\), and "00" = 0. The general formula is

$$\text{value} = (\text{first digit} \times 16) + \text{second digit}$$

where each digit ranges 0–15 (A–F representing 10–15).

$$(R,G,B) = \big(\,\text{hex}_{[1,2]},\ \text{hex}_{[3,4]},\ \text{hex}_{[5,6]}\,\big)_{16}$$

where

$$\left\{ \begin{aligned} R &= \operatorname{int}_{16}\!\left(\text{Hex}_{[1,2]}\right) \\ G &= \operatorname{int}_{16}\!\left(\text{Hex}_{[3,4]}\right) \\ B &= \operatorname{int}_{16}\!\left(\text{Hex}_{[5,6]}\right) \end{aligned} \right.$$
Hex code split into red, green and blue byte pairs
Each hex pair maps to one of the red, green and blue channels (base 16).

Worked Example

Take #3498DB. Split into 34, 98, DB.

$$\text{Red} = 3 \times 16 + 4 = 52$$$$\text{Green} = 9 \times 16 + 8 = 152$$$$\text{Blue} = D(13) \times 16 + B(11) = 208 + 11 = 219$$

The result is rgb(52, 152, 219) — a familiar sky blue.

Color swatch preview alongside R, G, B channel bars
The combined RGB channels produce the final color swatch.

FAQ

Does case matter? No. #abcdef and #ABCDEF produce the same RGB result.

What about 3-digit codes? A 3-digit hex like #F60 is shorthand where each digit is doubled, becoming #FF6600 before conversion.

Why are values capped at 255? Each channel uses two hex digits, and the maximum two-digit hex value, FF, equals 255 — giving 256 possible levels (0–255) per channel.

Last updated: