DEV Community

Cover image for Why do the color values range from (0-255) only?
rahul negi
rahul negi

Posted on • Originally published at hashnode.com

Why do the color values range from (0-255) only?

Once upon a time...

Someone asked me this question "Why do the color values range from 0-255 only?".

I was surprised how I never noticed this small thing and began on a quest to know the Truth.

Not Surprisingly, the Truth is so simple.

The Truth

Most of the screens use 24 bits RGB pixels, each pixel has three components in order of** Red, Green, Blue** leaving 8 bits for each color component.

Screenshot (40).png
Check this RGB calculator here.

The minimum and maximum decimal number that can be represented through 8 bits is 0 and 255.



00000000 (binary) = 0 (decimal)
11111111 (binary) = 255 (decimal) 


Enter fullscreen mode Exit fullscreen mode

Each pixel component ranges through 256 different shades of their color (RGB), and each number just sets the brightness/contrast of that pixel component resulting in

256 x 256 x 256 = 16777216 possible colors

I hope you learned something new today, open to comments and suggestions.
Thanks for reading the article.

Top comments (2)

Collapse
 
shaun_chevalier_4717e609a profile image
Shaun Chevalier

What if there were four color components instead of three? How would that change things? Would it still be 0-255?

Collapse
 
grem_ffeaf12e8f33de9e6b06 profile image
grem

No. Because computers use the 24 bit RGB pixels as mentioned, rather than there being 8 bits for 3, there would be 6 bits for 4. That means you can only have 64 different intensities of the colors. If you wanted to keep the same 8 bits but for 4 colors, you would need 32 bit pixels. Some monitors use RGBW (adding white) or RGBY (adding yellow).