Pixels: a picture made of squares
A computer cannot store a drawing the way paper does. So it cuts the picture into a grid of tiny squares. Each square is a pixel (picture element). Each pixel holds one colour.
The grid size is the resolution. A picture 800 pixels wide and 600 pixels high has 800 x 600 = 480,000 pixels. More pixels give a sharper picture, but also a bigger file.
Pixels are stored row by row, like words in a book. Every pixel is just a number or a few numbers.
RGB: a colour as three numbers
A screen makes every colour by mixing three lights: red, green and blue. This is the RGB model. Each light has a strength from 0 (off) to 255 (full).
- (255, 0, 0) is pure red.
- (0, 0, 0) is black. (255, 255, 255) is white.
- (255, 255, 0) is yellow: red and green together.
- (128, 128, 128) is grey: all three equal.
Why 255? Each number uses 8 bits, and 8 bits can count from 0 to 255, which is 256 values.
Colour depth: how many bits for each pixel
Colour depth (bit depth of a picture) is the number of bits used for one pixel. With b bits you can make 2b different colours.
- 1 bit: 2 colours (black and white).
- 2 bits: 4 colours.
- 8 bits: 256 colours.
- 24 bits (8 each for R, G, B): about 16.7 million colours. This is called true colour.
Fewer bits means the colours are squeezed into steps, so a smooth sky turns into bands. Size of a picture = pixels x bits per pixel (divide by 8 for bytes).
Sound: sampling rate and bit depth
Sound is a wave of air pressure. A microphone turns it into a wave of electricity. The computer then samples it: it measures the height of the wave many times a second.
Sampling rate is the number of samples every second, in hertz (Hz). A CD uses 44,100 Hz. A phone call uses about 8,000 Hz, so it sounds thin.
Bit depth is how many bits store each sample. 8 bits give 256 height levels. CDs use 16 bits, which give 65,536 levels. More bits give a smoother, quieter background.
A good rule: to keep a sound, sample at least twice its highest pitch. People hear up to about 20,000 Hz, so 44,100 Hz is enough.
Size of sound = sampling rate x bit depth x seconds x channels (stereo has 2 channels).
Try it: measure a wave by hand
In the 3D, go to the last step. Set samples to 6, then to 48. See how the blue bars follow the wave better. Now lower the sound bits to 1 and see the steps. On paper: draw a 8 x 8 grid, colour it as a smiley with two colours, and write 0 or 1 in each square. You just encoded a picture with 1 bit per pixel.
Key formulas and definitions
- colours = 2^b (b = bits per pixel)
- picture size (bits) = width x height x bits per pixel
- true colour = 24 bits = 3 x 8 bits (R, G, B)
- sound size (bits) = sampling rate x bit depth x seconds x channels
- 1 byte = 8 bits; 1 KB = 1024 bytes
Worked examples
1. How many colours can 1, 2 and 8 bits per pixel show?
2^1 = 2, 2^2 = 4, 2^8 = 256 colours.
2. A black-and-white picture is 10 x 10 pixels. How many bits and bytes is it?
Black and white needs 1 bit per pixel. 10 x 10 x 1 = 100 bits. 100 / 8 = 12.5 bytes.
3. Write pure yellow and dark grey in RGB (use 64 for dark grey).
Yellow = red + green = (255, 255, 0). Dark grey has equal values: (64, 64, 64).
4. Find the size of a 800 x 600 picture in true colour (24 bits).
Pixels = 800 x 600 = 480,000. Bits = 480,000 x 24 = 11,520,000. Bytes = 11,520,000 / 8 = 1,440,000 bytes, about 1.44 MB.
5. A voice is recorded at 8,000 Hz, 8 bits, one channel, for 10 seconds. How many bytes?
Bits = 8,000 x 8 x 10 x 1 = 640,000. Bytes = 640,000 / 8 = 80,000 bytes.
6. How big is 1 minute of CD sound (44,100 Hz, 16 bits, stereo)?
Bits = 44,100 x 16 x 60 x 2 = 84,672,000. Bytes = 84,672,000 / 8 = 10,584,000 bytes, about 10.6 MB.
Common mistakes
- Thinking a pixel keeps a picture of a colour. It keeps numbers.
- Forgetting to divide by 8 when the question asks for bytes.
- Mixing up sampling rate (how often we measure) and bit depth (how finely we write each measure).
- Forgetting the 2 channels of stereo sound.