Consider an image that is 80 x 100.
Since each pixel is only one of two colors, we can use a single bit for each pixel, calling one color "color 0" and the other color "color 1." That is, the bit-depth is 1. The image is then 80x100x1 bits, or 8,000 bits, or 1,000 bytes. The color table uses 3 bytes (24 bits) to represent each of the two colors or 6 bytes total. The whole image is then 1,006 bytes.
The bit-depth is now two bits (colors are 00, 01, 10 and 11) and so the pixels take up 80x100x2 or 16,000 bits, or 2,000 bytes. The color table has 4 entries, each 3 bytes. Thus, the total is 2,012 bytes. (Exactly twice as big as the previous image.)
The bit-depth is now four (24=16) and so the pixels take up 80x100x4 or 32,000 bits, or 4,000 bytes. The color table has 16 entries, each 3 bytes, for a total of 3x16=48 bytes. Thus, the total is 4,048 bytes.
The bit-depth is now five, because 4 isn't quite enough (24=16) and so the pixels take up 80x100x5 or 40,000 bits, or 5,000 bytes. The color table has 17 entries, each 3 bytes, for a total of 3x17=51 bytes. Thus, the total is 5,051 bytes.
Notice that adding just one color has greatly increased the size of the file, because it increased the bit-depth. Sometimes you can increase the number of colors without increasing the bit-depth, in which case the additional color makes a negligible increase in the file size.
The pattern is that we take the logarithm base two of the number of colors and round it up to the nearest integer. That's the number of bits per pixel. Remember that the logarithm base two of a number x is the number n such that:
2n = xWe can define the logarithm as:
2n = x if and only if log2 x = n
We can measure the "size" of an image in bits in three dimensions: height, width, and depth, where the depth is the number of bits it takes to represent the color of a pixel.