objectives
By the end you'll be able to…
- Explain why files are compressed.
- Describe how lossy compression works and give examples.
- Describe how lossless compression works and give examples.
- Compare lossy and lossless, and choose the right one for a scenario.
why compress?
Why do we compress files?
Compression means reducing the size of a file so it takes up less space on secondary storage.
Two big reasons:
- Storage. Fit more files on the same device — phones, tablets, laptops, servers.
- Speed. Send data faster across a network — quicker uploads, downloads and streaming.
There are two methods of compression:
- Lossy — throws data away.
- Lossless — reorganises data so the original can be recovered.
lossy
Lossy compression
- Data is lost to reduce the file size.
- Irreversible — the original file cannot be recovered from the compressed version.
- Can shrink files dramatically, but at the cost of quality.
- Only suitable when a drop in quality is acceptable — images, video and sound.
Example: in a photograph, lossy compression groups similar colours together, reducing the total number of colours without a big visible change.
Original JPG: 824 KB
50% lossy compression: 76 KB (looks nearly identical)
80% lossy compression: 38 KB (quality noticeably drops)
🖱️ demo
Slide to compress
Drag the slider to increase the level of lossy compression. Watch the file size drop — and the quality with it.
Notice how small changes at low levels don't hurt the picture much — but pushing compression too high loses detail you can't get back.
lossless
Lossless compression
- Data is encoded, not lost.
- Reversible — the original file can be recovered exactly.
- Reduces file size, but not as much as lossy.
- Used where any loss of quality is unacceptable — documents, code, spreadsheets, some images.
A common technique: look for patterns and repetition. Repeating characters can be replaced with a single character + a count.
"EEEEE" → E5. Same information, fewer characters. When the file is opened, the algorithm reverses this to get "EEEEE" back.
When you open a compressed document, the software decompresses it automatically. Formats like .docx, .pdf, .zip and .png all use lossless compression.
compare
Lossy vs Lossless
| Lossy | Lossless | |
|---|---|---|
| What happens | Data is thrown away | Data is re-encoded |
| Reversible? | No — original is lost | Yes — original recovered exactly |
| Size reduction | Large | Smaller |
| Quality | Reduced | Unchanged |
| Best for | Images, video, sound | Documents, code, some images |
| Example formats | JPG, MP3, MP4 | PNG, ZIP, DOCX, PDF |
Flip cards
practice
Exam-style practice
Q1. Give two reasons why files are compressed.
Q2. Sarah records an audio file and emails it to a friend for proofing. Explain two reasons why using lossy compression is beneficial. [4]
Lossy means data is lost [1] but the difference in sound quality is unlikely to be noticed by humans [1].
Q3. Explain why lossless compression is preferred for word-processed documents.
Q4. Describe how lossless compression can reduce the size of a text file.
// end of topic 7 — compression