1.2.5

Compression

GCSE Computer Science 1.2.5: the need for compression, the difference between lossy and lossless compression, their advantages and disadvantages, and the effect each has on the file.

About 10 minutes to read

The need for compression

Compression means reducing the size of a file. The specification asks for common scenarios where it may be needed, and there are three kinds of reason:

• Storage — smaller files mean more fit on a device, which matters on phones and cameras with fixed capacity. • Transmission — smaller files transfer faster and use less bandwidth, which matters for streaming, video calls, email attachments and downloading over a slow or metered connection. • Cost — less storage bought and less data transferred both cost less, which matters at scale for a business hosting files.

Compression is a trade: the file becomes smaller, but work has to be done to compress it and to decompress it before it can be used.

Compression
reducing the size of a file, so that more fits on a device, files transfer faster and less bandwidth is used

Lossy and lossless

Figure: The two types

How each works, in principle:

Lossy compression removes data the user is unlikely to notice — colours the eye cannot easily distinguish, or sound frequencies outside normal hearing. Because that data is discarded, the file gets much smaller, and the original can never be reconstructed.

Lossless compression finds patterns and records them more efficiently — for example noting that a sequence repeats rather than storing it many times. Nothing is thrown away, so the original file can be rebuilt exactly, but the saving is smaller.

The ability to carry out specific compression algorithms is not required, so you do not need to work through run-length encoding or Huffman coding — only to explain the principle and the trade-off.

Worked example

A user is emailing a set of holiday photographs and a spreadsheet of financial records. Recommend a type of compression for each.

  1. Photographs: ask whether a small quality loss matters. For viewing holiday photos, it does not.
  2. Lossy gives a much greater size reduction, which is what matters for emailing — so lossy for the photographs.
  3. The spreadsheet: ask what happens if data is removed.
  4. Financial figures would be corrupted — a changed digit is not an unnoticeable loss of quality, it is a wrong number.
  5. So lossless, which reduces the size while allowing the file to be restored exactly.

Answer: Lossy for the photographs, because the much greater size reduction matters more than a quality loss the viewer will not notice. Lossless for the spreadsheet, because removing any data would corrupt the figures — the file must be restored exactly.

Common mistake

Lossy compression is not simply "worse". For photographs, music and video it gives a far greater size reduction for a loss most people cannot detect — which is why it is the standard choice for those files. The question is always whether the lost data matters.

Lossy compression
compression that removes data the user is unlikely to notice; the file becomes much smaller but the original can never be reconstructed
Lossless compression
compression that finds patterns and records them more efficiently, so the original file can be reconstructed exactly

Before you practise

  • Compression reduces file size, for storage, for faster transmission and lower bandwidth, and to reduce cost.
  • Lossy permanently removes data: much smaller files, reduced quality, and the original cannot be recovered.
  • Lossless stores data more efficiently: smaller savings, but the original can be restored exactly.
  • Lossy suits photographs, music and video; lossless suits text, spreadsheets and program code.
  • Compressed files must be decompressed before use, which takes processing time.
  • Carrying out specific compression algorithms is not required — only the principles and the trade-off.

Now practise it

Reading is the easy half. Answer questions on 1.2.5 Compression and find out which parts you actually know.