Compression
Why files are compressed at all, exactly how lossy and lossless differ, and how to choose correctly between them in any scenario the exam gives you.
Why compress
Compression means reducing the size of a file.
Three reasons it matters:
- Less storage space is used, so more files fit on a device.
- Faster transmission over a network, because there is less data to send.
- Less bandwidth is consumed, which reduces cost and eases congestion.
Streaming video, sending email attachments, loading web pages and backing up a phone all depend on compression working well.
Compressed files take up less storage space and can be transmitted more quickly, because there is less data to send.
- The original file: every byte of the data, nothing thrown away.
- Lossless finds repetition and records it more briefly.
- Unpack it and you get back exactly what you started with.
- Lossy throws data away permanently, and gets much smaller.
Lossy compression
Lossy compression permanently removes some of the data from the file.
The data chosen for removal is data the human eye or ear is least likely to notice:
- In audio, frequencies too high or too quiet for most people to hear
- In images, subtle colour differences the eye cannot easily distinguish
Characteristics
- Much greater size reduction, often to a small fraction of the original
- Some quality is lost, and it is lost permanently
- The original file cannot be recovered
- Repeatedly saving in a lossy format degrades the file further each time
Where it is used
- MP3 and AAC audio
- JPEG images
- MP4 video and most streaming
Once compressed, the removed data is gone. Saving a JPEG back as a PNG does not restore anything, it just stops further loss. This point is worth a mark.
Lossless compression
Lossless compression reduces file size without removing any data. It works by recording the data more efficiently, usually by identifying and encoding repetition.
A simple illustration
Instead of storing:
AAAAAAAABBBBCCCCCCCC
it stores:
8A 4B 8C
Every character can be reconstructed exactly. Nothing has been thrown away, the information has simply been described more compactly.
Characteristics
- The original file is restored perfectly when decompressed
- Less size reduction than lossy
- No loss of quality at all
Where it is used
- ZIP archives
- PNG and GIF images
- FLAC audio
- Any file where every byte matters: program files, spreadsheets, documents, databases
If lossy compression removed part of a program file, the instructions would be corrupted and the program would fail to run. Text documents are the same, a missing word changes the meaning.
Choosing between them
| Lossy | Lossless | |
|---|---|---|
| Data removed | Yes, permanently | No |
| Original recoverable | No | Yes |
| Size reduction | Large | Smaller |
| Quality | Reduced | Unchanged |
| Typical uses | MP3, JPEG, streaming video | ZIP, PNG, FLAC, program files |
Choosing correctly
Ask one question: would losing some data matter?
- Streaming a film to a phone: no, the viewer will not notice, and small files matter enormously. Use lossy.
- Archiving a legal document: yes, absolutely. Use lossless.
- A photographer's master copies: yes, they need to edit them later without accumulated degradation. Use lossless.
- A photograph on a web page: no, small size and fast loading matter more. Use lossy.
Name the type, then say what would happen if you chose the other one. "Lossless must be used because compressing a spreadsheet with lossy compression would permanently remove values, corrupting the data."
- Lossless: the file gets smaller, and decompressing gives back exactly the original.
- Lossy: the file gets much smaller, but detail is thrown away for good, so it cannot be restored exactly.
- Choose lossless when the data must be exact, and lossy when small losses do not matter.
Key terms you must be able to define
- Compression
- Reducing the size of a file so it uses less storage and transmits more quickly.
- Lossy compression
- Compression that permanently removes some data, giving a large size reduction but reduced quality.
- Lossless compression
- Compression that reduces size without losing any data, so the original file can be perfectly restored.
- Bandwidth
- The amount of data that can be transmitted over a network connection in a given time.
- Decompression
- Restoring a compressed file so it can be used.
Flashcards
Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.
Reach the top grade on this topic
This topic is generous with marks provided you write with precision.
Say permanently. Lossy compression does not just reduce quality, it removes data permanently and the original cannot be recovered. That word is often the difference between one mark and two.
Explain the mechanism of lossless. Do not just say "no data is lost". Say that repeated patterns are identified and stored more efficiently, for example by recording a value once with a count, so the original can be reconstructed exactly.
Justify with consequences. The strongest scenario answers say what would go wrong with the wrong choice, not just what is good about the right one.
Know that lossy is not always worse. For a video streaming service, lossy is not a compromise, it is the only workable option. Answers that treat lossy as simply inferior miss the point.
- Define both types in one sentence each, including the word permanently
- Explain the mechanism of lossless with a short example
- Recommend a type for any scenario and justify by naming what would go wrong otherwise
- Give two correct real file formats for each type
Mistakes that cost marks here
- Saying lossy compression 'compresses more of the file'. It removes data, which is why it achieves greater reduction.
- Claiming a lossy file can be restored to its original quality later. It cannot.
- Saying lossless compression 'does not reduce the file size much so it is not useful'. It is essential wherever accuracy matters.
- Giving JPEG as an example of lossless. JPEG is lossy. PNG and GIF are lossless.
- Recommending lossy for a text document or a program file, which would corrupt it.
Lossless compression works by finding repetition. This is why a text file can shrink to a fifth of its size while a file of truly random numbers barely shrinks at all: there is no pattern to exploit.
Knowledge check
Exam-style questions
Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.
- LUses less storage space
- LFaster to transmit or download because less data is sent
Files are compressed so that they take up less storage space on a device, allowing more files to be stored. They are also compressed so that they can be transmitted more quickly across a network, because there is less data to send, which reduces both the download time and the bandwidth used.
- LLossy permanently removes some of the data from the file
- LThe original file cannot be recovered after lossy compression
- LLossless reduces size without removing any data
- LThe original file can be perfectly restored when decompressed
Lossy compression reduces file size by permanently removing some of the data, typically detail that the human eye or ear is unlikely to notice, such as very high frequencies in audio or subtle colour differences in an image. Because the data has been deleted, the original file cannot be recovered from the compressed version. Lossless compression reduces file size without removing any data at all, instead recording the information more efficiently by identifying repetition and encoding it compactly. When a losslessly compressed file is decompressed, the original is restored exactly, byte for byte.
- LLossless compression should be used
- LEvery value in a financial spreadsheet is significant
- LLossy compression would permanently remove data, corrupting the records
- LLossless still reduces the size so it is quicker to email, and the file opens exactly as it was
The company should use lossless compression, for example by placing the spreadsheet in a ZIP archive. In a financial spreadsheet every single figure is significant, and the accountant needs the file to be exactly as it was created. Lossy compression works by permanently discarding data that is judged unimportant, and applied to a spreadsheet this would destroy or alter values, producing records that are inaccurate and legally worthless. Lossless compression still makes the file meaningfully smaller, so it attaches and sends more quickly and is less likely to hit an email size limit, but when the accountant decompresses it the spreadsheet is restored exactly as it was, with every value intact.
- LIt identifies repeated data or patterns within the file
- LThe repetition is recorded more efficiently, for example storing a value once with a count
- LThe original can be reconstructed exactly from this record
Lossless compression works by finding repetition within the data rather than throwing anything away. The algorithm identifies patterns and sequences that occur more than once, and records them more efficiently, for example by storing a repeated value a single time together with a count of how many times it should appear, or by building an index of common sequences and replacing each occurrence with a short reference to that index. Because the record contains everything needed to rebuild the original, decompression reconstructs the file exactly as it was, so no data is lost.
- LLossy gives a much greater reduction in file size than lossless
- LSmaller files use less bandwidth, allowing streaming without buffering
- LLess storage is needed on the servers, reducing cost
- LSome quality is permanently lost
- LThe removed data is chosen to be least noticeable to viewers, so the impact is limited
- LConcludes that lossy is appropriate here, with a caveat such as keeping lossless masters
Using lossy compression is the right decision for a streaming service. Lossy compression achieves a far greater reduction in file size than lossless could, often reducing a film to a small fraction of its original size, and this directly determines whether streaming is viable at all. Smaller files require far less bandwidth per viewer, which means films start quickly and play without buffering even on slower home connections, and it also means the service can serve many more simultaneous viewers from the same infrastructure. Storage costs fall too, since a library of thousands of films takes up a fraction of the space it otherwise would. The cost is that quality is permanently reduced and the original cannot be recovered from the compressed copy. However, lossy video compression is designed to discard the information the human visual system is least sensitive to, so on a typical television or phone screen most viewers notice little or no difference. On balance the decision is correct, because without lossy compression streaming at scale would be impossible. The service should, however, retain uncompressed or losslessly compressed master copies of each film, so that higher quality versions can be produced in future as bandwidth improves, rather than being permanently limited by today's compressed files.