Why doesn't $255 \times 255 \times 255 = 16777215$

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?


Solution 1:

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.

Solution 2:

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

Solution 3:

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$.

Solution 4:

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)$.