OCR J277 · §1.2.4 · Images

Data Representation of Images

Real image files whose size you can calculate to the exact byte.

The idea

Every image below is a real file, stored as a BMP. A BMP stores every pixel with no compression, so its size is the formula plus a small, fixed amount of metadata: the information that tells the computer how to read the pixels.

file size (bytes) = width × height × colour depth ÷ 8 + metadata

How much metadata?

Every BMP starts with a 54-byte header holding the width, height, colour depth and file size. Up to 8-bit, it also stores a colour table: the colour index, 4 bytes for every colour available. At 24-bit each pixel stores its own colour, so there is no table.

A colour table can be picked for the picture, choosing the best colours for that image, or it can be a standard table shared by every picture. The emoji below uses a picked table. The eye and the sunset use the standard 8-bit table, which has 8 reds × 8 greens × 4 blues, as early computers and the early web did. Either way the table holds 256 colours, so the metadata is the same size.

Colour depthHeaderColour tableMetadata
1-bit (2 colours)542 × 4 = 862 bytes
4-bit (16 colours)5416 × 4 = 64118 bytes
8-bit (256 colours)54256 × 4 = 1,0241,078 bytes
24-bit (16.7 million colours)54none54 bytes

Check it yourself

  1. Work out the file size in bytes with the formula, before you look.
  2. Right-click the image and choose Save image as… (or use the download link under it).
  3. Find the saved file. On Windows, right-click it and choose Properties: the Size line shows the exact number of bytes.
  4. Open Check your answer under the image and compare all three numbers.

The pictures are shown enlarged so you can see every pixel. The file you save is the real, tiny one.

A cool emoji, 32 × 32

Flat blocks of colour, only six of them. Look along the row: from 4-bit up the picture does not change at all, but the file keeps growing. Extra colour depth is wasted on a picture that does not use it.

1-bit · 2 colours
emoji-32x32 at 1-bit colour depth
32 × 32 pixels · 1 bit per pixel
Metadata: 62 bytes (54 header + 8 colour table)
Check your answer

32 × 32 × 1 ÷ 8 = 128 bytes of pixels
+ 62 bytes of metadata
= 190 bytes

Download emoji-32x32-1bit.bmp
4-bit · 16 colours
emoji-32x32 at 4-bit colour depth
32 × 32 pixels · 4 bits per pixel
Metadata: 118 bytes (54 header + 64 colour table)
Check your answer

32 × 32 × 4 ÷ 8 = 512 bytes of pixels
+ 118 bytes of metadata
= 630 bytes

Download emoji-32x32-4bit.bmp
8-bit · 256 colours
emoji-32x32 at 8-bit colour depth
32 × 32 pixels · 8 bits per pixel
Metadata: 1,078 bytes (54 header + 1,024 colour table)
Check your answer

32 × 32 × 8 ÷ 8 = 1,024 bytes of pixels
+ 1,078 bytes of metadata
= 2,102 bytes

Download emoji-32x32-8bit.bmp
24-bit · 16.7M colours
emoji-32x32 at 24-bit colour depth
32 × 32 pixels · 24 bits per pixel
Metadata: 54 bytes (54 header only, no colour table)
Check your answer

32 × 32 × 24 ÷ 8 = 3,072 bytes of pixels
+ 54 bytes of metadata
= 3,126 bytes

Download emoji-32x32-24bit.bmp

Drawn in code for this page by Mr Rawson.

An eye, 64 × 64

A photograph holds thousands of different colours. At 4-bit there are only 16 to go round, so the green iris turns grey. The 8-bit version uses the standard 256-colour table, which brings the green back but turns the skin blotchy. At 24-bit every pixel stores its own exact colour, so the skin is smooth again.

1-bit · 2 colours
eye-64x64 at 1-bit colour depth
64 × 64 pixels · 1 bit per pixel
Metadata: 62 bytes (54 header + 8 colour table)
Check your answer

64 × 64 × 1 ÷ 8 = 512 bytes of pixels
+ 62 bytes of metadata
= 574 bytes

Download eye-64x64-1bit.bmp
4-bit · 16 colours
eye-64x64 at 4-bit colour depth
64 × 64 pixels · 4 bits per pixel
Metadata: 118 bytes (54 header + 64 colour table)
Check your answer

64 × 64 × 4 ÷ 8 = 2,048 bytes of pixels
+ 118 bytes of metadata
= 2,166 bytes

Download eye-64x64-4bit.bmp
8-bit · 256 colours
eye-64x64 at 8-bit colour depth
64 × 64 pixels · 8 bits per pixel
Metadata: 1,078 bytes (54 header + 1,024 colour table)
Check your answer

64 × 64 × 8 ÷ 8 = 4,096 bytes of pixels
+ 1,078 bytes of metadata
= 5,174 bytes

Download eye-64x64-8bit.bmp
24-bit · 16.7M colours
eye-64x64 at 24-bit colour depth
64 × 64 pixels · 24 bits per pixel
Metadata: 54 bytes (54 header only, no colour table)
Check your answer

64 × 64 × 24 ÷ 8 = 12,288 bytes of pixels
+ 54 bytes of metadata
= 12,342 bytes

Download eye-64x64-24bit.bmp

Generated for this page on Mr Rawson's own computer with an open image model (Z-Image-Turbo, via mflux). It is not a photograph of a real person.

A sunset, 64 × 64

Long smooth blends of colour, from violet through orange to gold. At 4-bit and at 8-bit (the standard 256-colour table) the sky breaks into stripes. At 24-bit the blend is smooth, and the reflection of the sun appears in the water.

1-bit · 2 colours
sunset-64x64 at 1-bit colour depth
64 × 64 pixels · 1 bit per pixel
Metadata: 62 bytes (54 header + 8 colour table)
Check your answer

64 × 64 × 1 ÷ 8 = 512 bytes of pixels
+ 62 bytes of metadata
= 574 bytes

Download sunset-64x64-1bit.bmp
4-bit · 16 colours
sunset-64x64 at 4-bit colour depth
64 × 64 pixels · 4 bits per pixel
Metadata: 118 bytes (54 header + 64 colour table)
Check your answer

64 × 64 × 4 ÷ 8 = 2,048 bytes of pixels
+ 118 bytes of metadata
= 2,166 bytes

Download sunset-64x64-4bit.bmp
8-bit · 256 colours
sunset-64x64 at 8-bit colour depth
64 × 64 pixels · 8 bits per pixel
Metadata: 1,078 bytes (54 header + 1,024 colour table)
Check your answer

64 × 64 × 8 ÷ 8 = 4,096 bytes of pixels
+ 1,078 bytes of metadata
= 5,174 bytes

Download sunset-64x64-8bit.bmp
24-bit · 16.7M colours
sunset-64x64 at 24-bit colour depth
64 × 64 pixels · 24 bits per pixel
Metadata: 54 bytes (54 header only, no colour table)
Check your answer

64 × 64 × 24 ÷ 8 = 12,288 bytes of pixels
+ 54 bytes of metadata
= 12,342 bytes

Download sunset-64x64-24bit.bmp

Drawn in code for this page by Mr Rawson.

Data Representation of Sound →

← Back to §1.2 Memory and Storage