Compression
Why compress files?
Compression makes a file smaller. Smaller files:
- take up less storage space, so more fit on a phone or memory stick
- transfer faster over a network or the internet, so web pages load and downloads finish sooner
- use less bandwidth and mobile data, which matters when streaming music and video
- fit within size limits, such as for email attachments
There are two types: lossy and lossless.
Key terms
Lossy compression
Lossy compression permanently removes some of the data. It removes the details people are least likely to notice, such as sounds too quiet or high to hear, or tiny differences between similar colours.
- Advantage: files become much smaller.
- Disadvantages: the original can't be rebuilt, and the quality drops. A heavily compressed photo looks blocky, and compressing it again loses even more.
It's used for photos (JPEG), music (MP3) and video (MP4), where a small loss of quality is fine.
Key terms
Lossless compression
Lossless compression makes a file smaller without losing any data. It finds patterns, such as repeated data, and stores them more efficiently. When the file is decompressed, the original is rebuilt exactly.
- Advantage: no data or quality is lost.
- Disadvantage: files aren't as small as with lossy compression.
It's used for text, programs and spreadsheets, where losing a single character would change the meaning or stop a program working. ZIP files, PNG images and FLAC music are lossless.
You don't need to know how any particular compression method works.
Key terms
Choosing lossy or lossless
| Lossy | Lossless | |
|---|---|---|
| Data removed? | Yes, permanently | No |
| File size | Much smaller | Smaller, but not by as much |
| Original rebuilt? | No | Yes, exactly |
| Suits | Photos, music and video | Text, programs and spreadsheets |
Which would you use?
- Photos to share on social media: lossy. They upload faster, and the small loss of quality won't be noticed on a phone screen.
- A program to download: lossless. Every byte must be exactly right, or it won't run.
- A medical scan: lossless. A doctor needs every detail.
Common mistake
Lossless files are still smaller: the compression just doesn't throw away any data.