A1.1.8 · Computer hardware and operation
Compression
By the end you can
Describe lossless and lossy compression, carry out run-length encoding, and explain how transform coding makes a JPEG small.
A1.2.2 showed how big media files are: a minute of CD audio is about 10 MB, and a second of uncompressed HD video over 180 MB. encodes the same information in fewer bits. Smaller files take less storage, and travel faster across networks, which is what makes music and video streaming possible at all.
There are two families, and the difference between them is the most important idea in this section:
- compression removes redundancy, information that is repeated or predictable, and can be reversed exactly. You get back the same bits you started with. Essential for text, programs and databases, where one changed bit could break everything. Examples: ZIP, PNG, FLAC.
- compression also throws away detail that people are unlikely to notice: fine texture in a photo, sounds masked by louder ones. Files get far smaller, but the lost detail is gone for good. Used for photos, music and video. Examples: JPEG images, MP3 audio, H.264 video (usually inside an MP4 file).
Run-length encoding#
is the simplest lossless method. Wherever the same value repeats, store it once with a count. A row of a scanned page that is 20 white pixels, 3 black, then 24 white becomes “20W 3B 24W”: three pairs instead of 47 values. It shines on data with long runs (simple graphics, scanned documents, the zeros at the end of a JPEG block) and fails on varied data: plain text has almost no runs, so adding a count to every character makes it bigger.
The runs
Encoded (count, then the character)
20W3B24W1B12W
Original
60 bytes
Encoded as text
13 bytes · 78% smaller
As (count, value) byte pairs
10 bytes · 83% smaller
→ AAAABCCC
Transform coding: how a JPEG gets small#
is the lossy method behind JPEG images (and, in similar forms, MP3 audio and most video). The idea is to re-describe the image in a way that separates what the eye cares about from what it barely notices, then spend the bits on the first.
Split into blocks
The image is divided into 8 × 8 blocks of pixels, each handled on its own.Transform (DCT)
The discrete cosine transform rewrites each block’s 64 pixel values as 64 frequency coefficients. The top-left one is the block’s average brightness; the others describe patterns of finer and finer detail. Nothing is lost yet: this step can be undone exactly.Quantise
Each coefficient is divided by a step size and rounded. Fine-detail coefficients get big steps (the eye is less sensitive to them), so most become 0. This is where information is lost, and the quality setting chooses the step sizes.Encode
The coefficients are read in a zigzag from low to high frequency, so the zeros bunch up at the end; run-length and Huffman coding then store them compactly (losslessly).
Original
After compression and back
The coefficients kept are roughly what the file has to store; the zeros cost almost nothing after run-length and Huffman coding.
Choosing a method#
Ask whether the data must come back exactly. A program, a spreadsheet or a medical scan: lossless. A holiday photo, a song or a film where small invisible changes are fine: lossy, tuned to the quality needed. And remember that compressing already-compressed data (zipping a JPEG) gains almost nothing: the redundancy has already gone.
Check yourself
Compression
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
5 questions · 18 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Distinguish between lossy and lossless compression.
[2]Distinguish: Make the differences between two things clear.
2.Compress BBBBBBWWWWBBBBBBBBWW using run-length encoding, writing each run as a count followed by the character. Calculate the number of characters saved.
[3]Calculate: Work out the number, showing the working.
3.Explain why lossy compression is used for streaming video.
[3]Explain: Give reasons: say what happens AND why, or how one thing causes another.
4.Describe how transform coding is used to compress an image as a JPEG.
[4]Describe: A detailed account: say what happens, step by step if it is a process.
5.A hospital stores millions of X-ray images and sends them to doctors in other hospitals. Evaluate the use of lossy compression for these images.
[6]Evaluate: Weigh the strengths against the weaknesses (or the benefits against the costs) and reach a judgement that you back up.
Past papers
Old exam questions on this topic
From HL Paper 1, May 2014 to November 2025. These papers were set on the previous syllabus, so the wording may differ from today's exam, but the topic is the same. Find the questions and markschemes in your school's past-paper pack.
| Paper | Question | Marks | About |
|---|---|---|---|
| May 2025 TZ2 | 9(b) | 3 | Compression for large image files |
| November 2025 | 13(c) | 4 | Two limitations of compression |
| May 2023 TZ1 | 11(c) | 3 | Why compress before transmitting |
| May 2022 | 4 | 2 | Why compress before transmitting |
| November 2021 | 6 | 3 | Why compress files sent over a network |
| May 2017 | 7 | 3 | Downsides of compression |
In a nutshell
- Compression encodes data in fewer bits, so it takes less storage and transfers faster.
- Lossless: the original comes back exactly (ZIP, PNG, FLAC). Needed for text, programs, databases.
- Lossy: detail people are unlikely to notice is thrown away for far smaller files (JPEG, MP3, H.264 video). The loss is permanent.
- Run-length encoding (lossless) replaces runs with a count and a value: AAAAA → 5A. Great for long runs; it can make varied data bigger.
- Transform coding (lossy, used in JPEG): 8 × 8 blocks → DCT to frequencies → quantise (drop fine detail) → zigzag, run-length and Huffman coding.
