← All guides

Hex to RGB: How Color Codes Work

A hex color like #4F46E5 is three pairs of hex digits, each a 0–255 value for red, green and blue. Learn to convert hex to RGB by hand and instantly.

A hex color code splits into three pairs — red, green and blue — each a value from 0 to 255. For example, #4F46E5 becomes rgb(79, 70, 229): 4F = 79, 46 = 70, E5 = 229.

Reading a hex code

A full hex color is #RRGGBB:

  • RR — red channel, 00 to FF (0–255)
  • GG — green channel
  • BB — blue channel

Each pair is a base-16 (hexadecimal) number, where the digits run 0–9 then A–F (A = 10, F = 15). So FF = 15×16 + 15 = 255, the brightest a channel can be.

Convert a pair by hand

Take the pair 4F: the first digit is 4 (×16 = 64), the second is F (=15). 64 + 15 = 79. Repeat for each pair to get the three RGB values.

Shorthand and alpha

  • #abc is shorthand for #aabbcc — each digit is doubled.
  • #RRGGBBAA adds a fourth pair for alpha (opacity), 00 transparent to FF opaque.

Why two notations exist

Hex is compact and common in CSS and design tools; rgb() is easier to read and lets you tweak one channel or add transparency with rgba(). They describe the exact same color.

Convert instantly

Paste any hex or RGB value into the color converter to switch between HEX, RGB and HSL live. Building a palette? Try the color palette generator. Related: Number base converter.