Hexadecimal Numeral System (Base-16)

The hexadecimal numeral system (often called hex) is a base-16 number system.

The word hexadecimal combines the Greek prefix hexa- (“six”) with the Latin word decimal (“ten”), referring to its base of 16. A numeral system’s base tells you how many unique symbols it uses before counting continues in the next place value. Decimal (base-10) uses 10 symbols: 0–9. Hexadecimal (base-16) uses 16 symbols: 0–9 and A–F.

The hexadecimal numeral system (often called hex) is a base-16 number system. Since hexadecimal needs 16 symbols but only ten digits exist (0–9), the letters A through F are used to represent the remaining six values.

Hexadecimal Numeral System Symbols

Since hexadecimal needs 16 symbols but uses only the numbers 0–9, the letters A through F are used to represent the remaining six values.

DecimalHexadecimal
00
11
22
33
44
55
66
77
88
99
10A
11B
12C
13D
14E
15F

Beyond F

After F (15), counting continues with 10, just as decimal continues from 9 to 10. In hexadecimal, 10 represents 16 in decimal.

Why Use Hexadecimal?

Computers store all data as binary (0s and 1s). While binary is efficient for computers, long strings of 0s and 1s are difficult for people to read and write. Hexadecimal provides a much more compact way to represent binary. Each hexadecimal digit corresponds to exactly four binary digits (bits).

BinaryHexadecimal
1010A
1111F
11001010CA
Hexadecimal provides a much more compact way to represent binary. Each hexadecimal digit corresponds to exactly four binary digits (bits).

Because every hexadecimal digit represents four bits, programmers commonly use hexadecimal when working with memory addresses, machine code, colors, and other binary data.

RGB and Hexadecimal Colors

The RGB color system represents colors by combining red (R), green (G), and blue (B) light.

Each color component is stored in one byte (8 bits). Since 8 bits can represent 256 different values, each component can have a value from 0 to 255. RGB colors are commonly written as (R, G, B), where each number represents the intensity of the red, green, or blue component. Specific colors are represented by changing the component values.

The darkest values are 0, and maximum intensity values are 255:

  • (255, 255, 255) is white because all three components are at their maximum value.
  • (0, 0, 0) is black because all three components are at their minimum value.

Here are some straightforward (R, G, B) values with components at either maximum or minimum value:

  • Red: (255, 0, 0)
  • Green: (0, 255, 0)
  • Blue: (0, 0, 255)
  • Yellow: (255,255,0)
  • Magenta: (255,0,255)
  • Cyan: (0,255,255)

Hexadecimal Colors

If you’ve worked with HTML, CSS, or looked at colors in a graphics application such as Adobe Photoshop, you’ve probably seen colors represented as a hexadecimal value preceded with a hash (or pound) sign, such as #FFFFFF. 

If you've worked with HTML, CSS, or looked at colors in a graphics application such as Adobe Photoshop, you've probably seen colors also represented as a hexadecimal value preceded with a hash or pound sign, such as #FFFFFF. 

Because each component is stored as one byte, RGB colors are often written in hexadecimal as #RRGGBB, where each pair of hexadecimal digits represents one color component (a single byte is represented by two hexadecimal digits). This is similar to the RGB system (R, G, B) in that the colors are grouped as red, green, and then blue.

  • RR = red intensity
  • GG = green intensity
  • BB = blue intensity

Minimum and Maximum Color Intensity

In RGB and Hexadecimal the minimum value is the same: 0. However, the RGB maximum value of 255 is represented in Hexadecimal as FF (remember that hexadecimal uses the digits 0-9, then A-F).

  • 255 RGB = FF hexadecimal (maximum value)
  • 0 RGB = 00 hexadecimal (minimum value)

If all values are 0 (minimum intensity) the color will be black #000000. If all values are F (maximum intensity), then the color will be white (#FFFFFF).

RRGGBB
Black000000
WhiteFFFFFF

Example colors:

  • #FF0000 = Red
  • #00FF00 = Green
  • #0000FF = Blue

Hexadecimal Color Example: Shades of Red

Let’s look at five shades of red.

  • First, note that each has the same value for the green and blue components (00). The only difference are the red values.
  • Next, remember that the minimum value is 0; values closer to 0 will be darker.
  • And finally, keep in mind that the maximum value is F. As values move closer to F they will increase in intensity.

#330000

RRGGBB
330000

#660000

RRGGBB
660000

#990000

RRGGBB
990000

#CC0000

RRGGBB
CC0000

#FF0000

RRGGBB
FF0000

Gray Shades

Aside from white (#FFFFFF) and black (#000000), if all 6 digits are the same value, the color will be a shade of gray.

Examples:

#222222

RRGGBB
222222

#666666

RRGGBB
666666

#AAAAAA

RRGGBB
AAAAAA

#DDDDDD

RRGGBB
DDDDDD

Shortened Hexadecimal Color Values

If both values in a pair (RR, GG, BB) are the same value, you can shorten the hexadecimal number to a 3-digit hex. For example, white would be #FFF.

However, if the numbers in a pair are not the same you can’t shorten the code and still have the same color. For example, #29A7D9 and #2AD are similar but they are not the same color.

A six-digit hex color can only be shortened to 3 digits when each pair contains identical digits.

  • #FFFFFF = #FFF
  • #33AA99 = #3A9
  • #29A7D9 cannot become #2AD

Lowercase or Uppercase?

Hexadecimal values can be written in either uppercase or lowercase, and both will work the same way (i.e., #FFFFFF and #ffffff). The convention depends on the language, ecosystem, and what the hex value represents.

For most programmers lowercase is preferred for consistency and readability. However, uppercase remains common in embedded systems, hardware documentation, and some legacy codebases.

In this article uppercase is used so that the letters A-F are easier to read.

Hexadecimal Numeral System Prefixes and Suffixes

To avoid confusion with decimal, octal and other numbering systems, hexadecimal numbers are sometimes written with an “h” after the number, or “0x” as a prefix. For example, 63h and 0x63 mean 63 hexadecimal. Additionally, hexadecimal colors use “#” as a prefix (#FFFFFF).

Summary

Hexadecimal Numeral System is a base-16 numbering system that uses the symbols 0–9 and A–F. Each hexadecimal digit represents 16 possible values, while two hexadecimal digits represent one byte (0–255). In web design, RGB colors are written in hexadecimal as #RRGGBB, where higher values produce brighter colors and equal red, green, and blue values create shades of grey.

Expand Your Knowledge

Scroll to Top