OCR H446, section 1.3.1 (a)
Compression means storing or sending data using fewer bits than the original. Decompression reverses the process.
Why compress data?
- Save storage space: more files fit on a device or server.
- Send data faster: smaller files download, upload and stream more quickly, and use less bandwidth.
- Reduce costs: less storage to buy, and less data to transfer.
- Make streaming possible: video and music need to arrive fast enough to play without stopping.
Raw images, sound and video are very large. A few minutes of uncompressed video can run to many gigabytes, so compression is essential for the web, streaming and mobile devices.
The compression ratio shows how well it worked:
Example: a 6 MB photo compressed to 1.5 MB has a ratio of (also written 4:1), which is a saving of 75%.
Lossless compression
Lossless compression reduces the size without losing any information. When the file is decompressed, you get exactly the original, bit for bit.
- It works by finding and removing redundancy: patterns and repeated data. Two common methods are run length encoding and dictionary coding (see 1.3.1 (b)).
- Examples of formats: ZIP, PNG, GIF, FLAC (audio), and PDF contents.
- Used for: text documents, program files, spreadsheets, databases and medical images. A single changed character in a program or a number in a spreadsheet could be disastrous.
- Advantage: no loss of quality, and the original can always be rebuilt.
- Disadvantage: the file doesn't get as small as with lossy compression.
Lossy compression
Lossy compression makes the file much smaller by permanently discarding some of the data. When decompressed, you get an approximation of the original, and the lost detail can't be recovered.
It chooses to discard what people are least likely to notice:
- Images (JPEG): fine colour differences and small details that the eye barely sees.
- Sound (MP3, AAC): frequencies that are too high or too quiet to hear, or masked by louder sounds at the same time.
- Video (MPEG, H.264): detail that doesn't change between frames, and fine detail in fast movement.
Most lossy formats let you choose the level of compression: more compression gives a smaller file but lower quality.
- Examples of formats: JPEG, MP3, MP4 and other video formats.
- Used for: photographs, music, video and streaming, where a small loss of quality is acceptable and file size matters.
- Advantages: much smaller files (often 10 times or more), so quicker transfer and less storage.
- Disadvantages:
- the original can't be restored;
- quality is lost, and at high compression you may see blocky artefacts or hear a "tinny" sound;
- repeatedly saving a lossy file makes the quality worse each time.
Comparison
| Lossless | Lossy | |
|---|---|---|
| Data lost? | No | Yes, permanently |
| Original recovered? | Exactly | Only an approximation |
| File size | Smaller | Much smaller |
| Suitable for | Text, programs, data, medical and legal images | Photos, music, video |
| Formats | ZIP, PNG, FLAC | JPEG, MP3, MP4 |
| Main risk | Less saving | Lost quality |
Choosing between them
| Situation | Choice | Reason |
|---|---|---|
| Sending a program installer | Lossless | A single wrong bit could stop it working |
| Streaming a film on a phone | Lossy | It needs a small file to stream smoothly, and small losses aren't noticed |
| Archiving the original of a family photo | Lossless (or the original) | Keeps all the detail, so it can be edited later |
| Posting a photo on a website | Lossy (JPEG) | The page loads faster |
| Compressing a spreadsheet to email | Lossless | Every number must be exact |
Worked example
Task: a photographer has a 24 MB raw photo. A website needs it as small as possible, and the photographer also wants to keep a perfect copy. Recommend what to do.
- Keep the original file, or save a lossless version (such as PNG), as the master copy, because lossless compression keeps every detail.
- For the website, create a lossy JPEG copy, perhaps 1 to 2 MB. This is a compression ratio of , and the loss of quality is hardly noticeable on a screen. Pages with smaller images load faster.
- Always make the JPEG from the original, not from an earlier JPEG, to avoid repeated loss of quality.
Exam tip: the defining difference is whether the original can be recovered exactly. Link each type to a suitable use, and give a reason: lossless where every bit matters (text, programs), lossy where file size matters more than perfect quality (photos, music, video).
Check yourself
What is the difference between lossless and lossy compression?
Lossless compression allows the exact original data to be recovered. Lossy compression permanently removes some data, so only an approximation of the original can be recovered.
Give two reasons for compressing files
Any two of: to save storage space; to send data faster; to use less bandwidth; to reduce costs; to allow streaming.
Why should a program file be compressed using lossless compression?
Any change to the program's data could stop it working, so every bit must be restored exactly.
A 12 MB file compresses to 3 MB. What is the compression ratio?
, so the ratio is 4:1.