Data compression: lossy vs lossless

Cambridge IGCSE Computer Science (0478) · lesson 8 of 35 · 25 min

Why Compress Data?

Uncompressed files are large. A 3-minute CD-quality audio track is ~30 MB; a 4K video is gigabytes per minute. Compression reduces file size to save storage space and reduce transmission time. There are two fundamentally different approaches:

Lossless vs Lossy Compression

Run-Length Encoding (RLE) — Lossless

RLE replaces consecutive repeated values with a count and the value. It works well for images with large areas of the same colour (e.g. simple graphics, fax transmissions).

Apply RLE to: AAAABBBCCDDDDDD

Original: 15 characters

Encoded: 4A 3B 2C 6D = 8 characters

Saving: 7 characters (47% reduction)

Huffman Coding — Lossless

Huffman coding assigns shorter binary codes to more frequent characters and longer codes to rarer ones. The result is a variable-length code that is always shorter than fixed-length encoding for typical data.

Used in ZIP, PNG, and as part of JPEG and MP3 compression.

Lossy Compression in Practice

JPEG works by dividing an image into 8×8 pixel blocks, applying a mathematical transform (DCT), and discarding high-frequency detail that the human eye is less sensitive to. The “quality” setting controls how aggressively data is discarded.

MP3 uses psychoacoustic models to remove sounds that humans cannot hear well — sounds masked by louder sounds, very high frequencies, and quiet sounds during loud passages.

Which compression method allows perfect reconstruction of the original file?

  • Lossy
  • Lossless
  • Both
  • Neither

Answer: Lossless
Lossless compression preserves all original data.

JPEG is an example of which type of compression?

  • Lossless
  • Lossy
  • Run-length encoding
  • Huffman coding

Answer: Lossy
JPEG discards some image data permanently — it is lossy.

RLE is most effective when:

  • Data has many different values
  • Data has long runs of repeated values
  • Data is random
  • Data is already compressed
  • Answer: 1

RLE replaces runs of identical values with a count+value pair.


Previous lesson: Representing sound: sampling rate and bit depth
Back to Cambridge IGCSE Computer Science (0478)
Next lesson: Network types: LAN, WAN, PAN