Ok, I obviously understand basic multiplication and understand why those don't equal. But in web colors, therr is FFFFFF hexadecimal different colors (or rather $16,777,215$ in base $10$). This amount of colors can also be described by using three sets of $255$ (RGB). However, $255 \times 255 \times 255 = 16,581,375$. So does this mean that there is some hexadecimal numbers that both attribute to the same color, or is it that not all of the colors can by shown by the RGB system?

  • 2
    $\begingroup$ You mean "there," not "their." $\endgroup$ – symplectomorphic Jun 7 '14 at 5:09
  • $\begingroup$ an n-digit number in base b have range from 0 to b^n - 1 $\endgroup$ – phuclv Jun 7 '14 at 5:36

Remember, each color can go from $0$ to $255$ which gives it $256$ options (including zero). Because there are $3$ colors, each with $256$ possibilities, there are $256^3$ possibilities or $16,777,216$ possibilities. Because in base $16$ it goes from $000000$ to $FFFFFF$ which is from $0$ to $256^3-1$, not $255^3$.


Because each color channel starts counting from $0$, not $1$, so for instance, $R = 0$ means no red, and $R = 255$ means 100% red. Therefore, each channel has $255 + 1 = 256$ steps in an 8-bit per channel color depth system, which represents a total of $256^3 = 16777216$ possible colors.


Hint: $999999\neq99\cdot99\cdot99$.

  • 5
    $\begingroup$ There are $100$ possible combinations from $00$ to $99$, just like there are $256$ possible combinations from $00$ to $FF$. $\endgroup$ – Lucian Jun 6 '14 at 23:34

It is frequently useful not to think in terms of closed intervals -- i.e. that a byte is an integer in the interval $[0,255]$ -- but in terms of half-open intervals -- i.e. that a byte is an integer in the interval $[0,256)$.

Among the benefits of this is that you will make fewer off-by-one errors related to the size of an interval: in this case, the set of all triples of bytes can be put into one-to-one correspondence (e.g. by concatenating them) with the integers in the interval $[0, 256^3)$.


16777215 is what ye get leaving out one combo of hex digits, eg 000000

$255^3$ ommits things like 00 in any byte, so 16777215 would include 001234, whereas $255^3$ would exclude it (because it has 00 in 00 12 34


A good way to understand this is that you're ignoring the sampling aspect of color quantization. It is easy to understand why.

Suppose that the color values were real numbers ranging from $0.0$ to $255.0$.

Indeed, naively, the "volume" of color might be calculated as $255.0 \times 255.0 \times 255.0$.

But the digitized colors are quantized. This means that you must think of each discrete value as representing a range of real values (all the real values in that range alias to the discrete value). So the digitized color value of 0 might represent all of the intensities centered around $0.5$, say the range $[0, 1)$. Then, next, the intensity value $1$ represents samples in the range $[1, 2)$ and so on. Thus, the value $255$ actually represents intensities around $255.5$, in the range $[255, 256)$.

The actual volume of real intensities is $256.0 \times 256.0 \times 256.0$: from the lowest possible value of zero, to the maximum, which is almost $256$.

In the discrete quantization, there are $256$ integers in the range $0$ to $255$, representing 256 color approximations, from near zero (around $0.5$, possibly as low as $0$) to around 255.5 (as high as $256$).

So, to recap, the number of integer codes ($256$) corresponds to the range span of the real variable that is being sampled ($0.0$ to $256.0$). These codes represent samples centered on the points ${ 0.5, 1.5, 2.5, ..., 255.5 }$, each spanning a range that is about 1 unit wide.

And, yes, not all colors can be shown by the RGB system. This is true for a number of reasons on more than one level, but let us just stick to our simplest reason in light of the foregoing discussion: sampling. There are many colors in the range $[0, 1)$, but we have only one sample value to represent the entire range.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.