Docs

Topic 1 · Data representation

File sizes and compression

Storage units from bits to exbibytes, calculating image and sound file sizes, and lossy versus lossless compression.

Lesson 4 of 4Syllabus 1.3updated October 31, 2026

Storage units

Data is measured in bytes. Each unit from a kibibyte upwards is 1024 times the one before, because 1024 is 2¹⁰.

UnitSize
bita single 0 or 1
nibble4 bits
byte (B)8 bits
kibibyte (KiB)1024 bytes
mebibyte (MiB)1024 KiB
gibibyte (GiB)1024 MiB
tebibyte (TiB)1024 GiB
pebibyte (PiB)1024 TiB
exbibyte (EiB)1024 PiB

Exam tip. To go down a unit, multiply by 1024. To go up a unit, divide by 1024. To go from bits to bytes, divide by 8.

Calculating file sizes

Image: size in bits = resolution (width × height) × colour depth.

A 1920 × 1080 photo at 24-bit colour: 1920 × 1080 × 24 = 49,766,400 bits ÷ 8 = 6,220,800 bytes ÷ 1024 ÷ 1024 ≈ 5.93 MiB.

Sound: size in bits = sample rate × sample resolution × length in seconds.

One minute at 44,100 Hz and 16 bits: 44,100 × 16 × 60 = 42,336,000 bits ÷ 8 = 5,292,000 bytes ≈ 5.05 MiB.

  1. 1
    Multiply to get bits
    pixels × colour depth, or samples per second × bits × seconds
  2. 2
    ÷ 8 for bytes
    8 bits in a byte
  3. 3
    ÷ 1024 for each unit up
    bytes → KiB → MiB → GiB

Why compress?

Compression makes files smaller. Smaller files:

  • use less storage space on a device or server
  • take less time to upload, download, and stream
  • use less bandwidth, so networks are less congested

Lossless compression

Lossless compression shrinks a file without losing any data. When it is decompressed you get the exact original back. It is used for text, program files, and anything where every bit matters.

Run-length encoding (RLE) is one lossless method. It replaces runs of the same value with a count and the value.

OriginalRLEValues stored
WWWWWWBBBWWWW6W 3B 4W13 → 6
AAAAAAAABBC8A 2B 1C11 → 6
ABCD1A 1B 1C 1D4 → 8 (bigger!)
RLE works best with long runs, such as simple images with large areas of one colour.

Lossy compression

Lossy compression permanently removes data that people are unlikely to notice. The file gets much smaller, but the original can never be fully restored. It suits photos, music, and video, not text or code.

Lossy methods include reducing the resolution or colour depth of an image, reducing the sample rate or resolution of a sound, and removing sounds the human ear cannot hear (as MP3 does).

Key idea. Lossless: smaller, original fully restored. Lossy: much smaller, some data gone for good.

Key terms

Kibibyte
1024 bytes (KiB).
Compression
Reducing the size of a file.
Lossless
Compression where no data is lost and the original can be restored exactly.
Lossy
Compression that permanently removes some data.
Run-length encoding
Lossless compression that stores repeated values as a count and the value.

Check yourself

How many bytes are in 3 KiB?Show answer

3 × 1024 = 3072 bytes.

Calculate the size in bytes of a 100 × 50 image with a colour depth of 8 bits.Show answer

100 × 50 × 8 = 40,000 bits ÷ 8 = 5000 bytes.

Why should a text document not be compressed with lossy compression?Show answer

Lossy compression removes data permanently, so characters would be lost and the text would no longer make sense.

Compress RRRRGGGGGGBB with RLE.Show answer

4R 6G 2B.