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.
Storage units
Data is measured in bytes. Each unit from a kibibyte upwards is 1024 times the one before, because 1024 is 2¹⁰.
| Unit | Size |
|---|---|
| bit | a single 0 or 1 |
| nibble | 4 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.
- 1Multiply to get bitspixels × colour depth, or samples per second × bits × seconds
- 2÷ 8 for bytes8 bits in a byte
- 3÷ 1024 for each unit upbytes → 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.
| Original | RLE | Values stored |
|---|---|---|
WWWWWWBBBWWWW | 6W 3B 4W | 13 → 6 |
AAAAAAAABBC | 8A 2B 1C | 11 → 6 |
ABCD | 1A 1B 1C 1D | 4 → 8 (bigger!) |
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.