If ever you have a doubt on byte code of an image or size of an image, this is how it calculates of it.
Every image consists of blocks called pixels. As we all know data is always stored informs of bits. So even pixels will consume some bits of memory. For suppose we have only white and black 0 represents white and 1 represents black. So each of these pixels consume one bit of memory. For example: we have an image of size 100X200 pixels.
So total amount of memory in bits is 100*200*1=20,000 bits
A byte is equal to 8 bits.
So total amount of memory in bytes is 20,000/8=2500 bytes.
Now if you want to have shades of grey , definitely we must increase the bits of memory for a pixel. Say we have given 2 bits of memory for a pixel, we can store 4 shades of grey.
00 represents white
11 represent black
01 represents light grey
10 represent dark grey
For example: we have an image of size 100X200 pixels .
Total memory =(100*200*2)/8=5000 bytes
The Similar way if you allocate 3 bits per pixel, we can have 8 shades of color.
000 represent White
001 ,010,011,100,101,110 represent various shades of grey
111 represent black
Total memory =(100*200*3)/8=7500 bytes
From above 3 observations, we can easily derive a formula.
n bits can produce 2^n patterns (2 to the nth power)
Total no of colors= 2^bits (2 to the power bits per pixel).
4 shades of colors=2*2 which is 2 bits per pixel
8 shades of colors=2*2*2 which is 3 bits per pixel
16 shades of colors=2*2*2*2 which is 4 bits per pixel
32 shades of colors=2*2*2*2*2 which is 5 bits per pixel
64 shades of colors=2*2*2*2*2*2 which is 6 bits per pixel
For a general image representation, we need 256 colors. So
256 shades of colors=2*2*2*2*2*2*2*2 which is 8 bits per pixel