Omni Calculator logo

How many HEX codes are there?

There are 16,777,216 possible HEX codes. To easily work out this number, it's better to switch to the RGB system. Recall in RGB, which is just a different way of writing down HEX, there are three positions, each taking an integer value between 0 and 255. Hence, there are:

  • 256 choices at place R;
  • 256 choices at place G; and
  • 256 choices at place B.

In total, we have 256 × 256 × 256 = 16,777,216 possible combinations, which means this is the exact number of HEX codes.

🙋 If you are familiar with combinatorics, you surely have recognized the computation of possible HEX codes as an example of variations with repetition and when order matters. Learn more with Omni's combinations with repetition calculator.

You can easily see from the computation above what it would take to build a color system with a bigger number of HEX codes. It suffices to use more than 28=2562^8 = 256 values per RGB position. For instance:

  • Imagine we doubled this number to 29=5122^9 = 512 values. How many HEX codes would we get? The computation now reads:

    (29)3=227=134,217,728(2^9)^3 = 2^{27} = 134,217,728

  • Let's go even further and boost the initial value to 210=10242^{10} = 1024 values. How many HEX codes can we produce? An analogous calculation as above yields a whopping number:

    (210)3=230=1,073,741,824(2^{10})^3 = 2^{30} = 1,073,741,824

Hence, the number of HEX colors depends on the underlying number of values we can assign to each of the three primitive components. However, increasing the number of HEX colors in this way would require a different (longer) encoding procedure!

Since RGB and HEX are two different ways of describing the same color system, the number of HEX colors is equal to that of RGB colors. To determine the number of HEX codes, we calculate the number of combinations for choosing 3 out of 256 values with repetition, where order matters.

If you are not sure what we mean when saying RGB and HEX and different representations of the same color system, check out the explanation provided by our RGB to HEX converter.

Another equivalent color system is HSL, which you can discover with Omni's color converter.

There are 216 web-safe colors, which is way fewer than the number of HEX codes. This notion goes back to the early days of the web, when many screens could only display 256 colors.

The 216 colors arise as combinations of the 6 specific values: 00, 33, 66, 99, CC, FF in hexadecimal. We select three such values and combine them to obtain a hexadecimal color. However, modern screens can display millions of colors, so web-safe colors are more a relic of web design history than a real-life necessity.

Researchers estimate that an average human can distinguish up to 10 million colors, which is the same order of magnitude as the number of possible HEX codes. This result is linked to the number of rods and cones in our retina. Cones are responsible for color detection, and a typical human has three types of cones — red, green, and blue. However, some people have four cone types in their retinas, which allows them to see even 100 times more colors!

This article was written by Anna Szczepanek and reviewed by Steven Wooding.