Hex to RGB: How Color Codes Actually Convert

#FE7825 and rgb(254, 120, 37) are the same color written two ways. Converting between them is a mechanical process you can do in your head once you see the structure — and understanding it makes every color tool you use less mysterious.

Here is what each part of a hex code means, how to convert in both directions by hand, why a third format exists, and which one to reach for in real work.

Color Converter tool showing hex #FE7825 recognized and converted to rgb(254, 120, 37) with a Copy button

Reading a hex code

A hex color splits into three pairs: #FE7825 is FE, 78, 25 — red, green, blue in that order. Each pair is a number written in base 16, running from 00 (none of that color) to FF (maximum). That gives 256 levels per channel and about 16.7 million possible colors.

Base 16 uses sixteen digits: 0 through 9, then A for 10, B for 11, C for 12, D for 13, E for 14, F for 15. A pair works like any two-digit number, except the first digit counts sixteens instead of tens. So FE is (15 × 16) + 14 = 254. That is the entire conversion.

Converting hex to RGB by hand

Take each pair, multiply the first digit by 16, add the second. For #FE7825: FE gives (15 × 16) + 14 = 254. 78 gives (7 × 16) + 8 = 120. 25 gives (2 × 16) + 5 = 37. The result is rgb(254, 120, 37).

Two shortcuts make this fast. Doubled pairs are easy anchors: 00 is 0, 33 is 51, 66 is 102, 99 is 153, CC is 204, FF is 255. And any pair starting with 8 or higher means that channel is more than half strength, which is usually all you need to know when eyeballing whether a color leans red, green, or blue.

Converting RGB back to hex

Reverse the arithmetic: divide each channel by 16 for the first digit, and the remainder is the second. For 120: 120 ÷ 16 is 7 remainder 8, giving 78. For 37: 37 ÷ 16 is 2 remainder 5, giving 25. Remember to convert remainders of 10 to 15 into A through F — 254 gives 15 remainder 14, which is FE, not 1514.

Always pad single digits with a leading zero. The number 5 becomes 05, not 5, because each channel must occupy exactly two characters for the code to parse.

Short hex, and where alpha fits

Three-digit codes like #F72 are shorthand: each digit doubles, so #F72 expands to #FF7722. That is why only colors whose pairs happen to be doubled can be written short — #FE7825 has no three-digit form.

Modern CSS also accepts eight-digit hex, where the last pair is alpha transparency: #FE7825CC is that orange at 80% opacity, since CC is 204 out of 255. The equivalent in RGB notation is rgba(254, 120, 37, 0.8), and current browsers also accept rgb(254 120 37 / 80%) with the newer space-separated syntax.

The third format: HSL

Hex and RGB are the same numbers in different notation, which means neither is good for reasoning about color. Ask for a slightly darker, slightly softer version of #FE7825 and you are guessing at three interacting channels.

HSL solves that by describing color as hue (position on the color wheel, 0 to 360 degrees), saturation (intensity, 0 to 100%), and lightness (0% black to 100% white). Our orange becomes roughly hsl(28, 99%, 57%). Now darker means lowering the last number and softer means lowering the middle one — one dial each. Every palette formula in our Color Palette generator works in HSL for exactly this reason.

Which format to use where

Hex for interchange: brand guidelines, design handoffs, anywhere a color needs to be copied as one compact token. RGB when you are working with transparency or manipulating channels programmatically, since the numbers map directly to how screens emit light. HSL when you are generating variations — hover states, disabled states, dark mode equivalents, or full tint and shade ramps.

All three are valid CSS everywhere, so there is no performance or compatibility reason to prefer one. Pick per task and convert freely.

Named colors and the odd ones out

CSS also accepts around 140 named colors — red, tomato, rebeccapurple, papayawhip — which map to fixed hex values. They are convenient for prototypes and terrible for production, since names carry no relationship to your palette and several are genuinely surprising: gray is darker than darkgray, and green is not #00FF00 but a much darker #008000, with the bright version called lime.

One name has a story worth knowing. rebeccapurple (#663399) was added to the CSS specification in 2014 in memory of Rebecca Meyer, the six-year-old daughter of CSS pioneer Eric Meyer, who died of brain cancer. It is the only color in the standard named after a person.

Convert instantly

Our Color Converter accepts any of these formats — hex long or short, rgb(), hsl(), or bare comma-separated numbers — and returns all three with copy buttons and a live swatch. To turn one color into a full range, the Color Shades tool builds 12-step ramps, and the Contrast Checker verifies your text and background pairs pass WCAG before you ship them.

Convert hex to RGB now