1.2.5 Compression
Files such as photos, songs and videos can be very big. Compression makes a file smaller, so it takes up less space and is quicker to send.
Why we compress files
Smaller files have several benefits:
- •They take up less storage space, so more files fit on a phone, memory card or server.
- •They are quicker to upload and download, and quicker to send as an email attachment.
- •They use less bandwidth (the amount of data a network can carry in a second). This matters when many people use the same network.
- •They can be streamed more easily. A song or a video that is compressed can play without long pauses, even on a slow connection.
Common scenarios
| Scenario | Why compression is used |
|---|---|
| Emailing photos | Many email systems limit the size of attachments |
| Streaming video or music | Smaller files arrive fast enough to play without stopping |
| A website with many images | Pages load faster and use less data on a phone |
| Storing a large photo collection | More photos fit on the device |
| Downloading a game or program | The download is smaller and quicker |
There are two types of compression: lossy and lossless. You do not need to know how to carry out a particular compression method. You need to know what each type does to a file, and which to choose.
Lossy compression
The data that is removed is chosen so that people are unlikely to notice. For example, a photo may lose small differences in colour that the eye can hardly see. A song may lose very quiet sounds that are hard to hear.
The effect on the file- •The file is much smaller.
- •The quality is lower. If too much data is removed, the picture looks blocky or blurred, or the sound is poor.
- •The data that was removed is gone for good. You cannot get the original back.
| Advantages of lossy | Disadvantages of lossy |
|---|---|
| Makes files much smaller than lossless | Some data is lost for good |
| Saves storage space and download time | Quality is lower |
| Good for streaming and websites | Not suitable when every bit of data matters |
Lossless compression
Lossless compression finds ways to store the same information using fewer bits, and no information is lost. You do not need to know how.
The effect on the file- •The file is smaller, but not as small as with lossy compression.
- •The quality is exactly the same as the original.
- •The original data can be restored in full.
| Advantages of lossless | Disadvantages of lossless |
|---|---|
| No data is lost | Files are bigger than with lossy |
| Original can be restored exactly | Less space saved |
| Best quality | Slower to send and needs more storage than lossy |
Lossy and lossless compared
| Lossy | Lossless | |
|---|---|---|
| Data removed? | Yes, for good | No |
| Can the original be restored? | No | Yes, exactly |
| File size | Much smaller | Smaller, but not as small |
| Quality | Lower | Same as the original |
| Typical file types | JPEG images, MP3 audio, MP4 video | PNG images, FLAC audio, ZIP files |
| Best for | Photos, music and video on the web, where small size matters | Text, programs, spreadsheets, and images where quality must be perfect |
Space saved: 40 - 4 = 36 MB.
The new file is 40 / 4 = 10 times smaller.
Lower quality means some data has been removed for good, so this is lossy compression.
Answer: 36 MB saved, 10 times smaller, lossy
Choosing the right type
Ask two questions:
- 1.Does any data have to be kept? If yes (a program, a spreadsheet, a legal document), use lossless.
- 2.Is a small file more important than perfect quality (a streamed film, a web page photo)? If yes, use lossy.
Exam technique
- •State questions need one fact. For example, "lossy compression removes data permanently".
- •Describe questions need what happens to the file. Say whether data is removed, whether the original can be restored and how the file size changes.
- •Explain questions need a reason, linked to the scenario. Use "because" and the benefit, such as "the file is smaller, so it downloads faster".
- •Compare questions need a point about both types. For example, "lossy files are smaller, but lossless files keep all of the data".
- •Discuss questions (8 marks) need both types, with advantages and disadvantages applied to the scenario, and then a clear conclusion. Do not describe how any algorithm works. The exam does not ask for that.