Compression
Why compress?
Smaller files use less storage and transfer faster over a network (less bandwidth).
Lossless compression
- No data is lost — the original is restored exactly.
- Works by storing patterns efficiently:
- Run-Length Encoding (RLE) stores "5 white pixels" instead of listing each.
- Dictionary coding replaces repeated data with shorter codes.
- Used for text, code, spreadsheets (ZIP, PNG, FLAC).
Lossy compression
- Permanently removes data the eye/ear barely notices.
- Much smaller files, but quality is reduced and cannot be recovered.
- Used for photos (JPEG), music (MP3), video (MP4).
Comparison
| Lossless | Lossy | |
|---|---|---|
| Quality | Perfect | Reduced |
| File size | Larger | Smaller |
| Reversible? | Yes | No |
| Use | Text, code | Photos, music, video |
Exam tip
If a question mentions text or program files, the answer is lossless — losing data there would corrupt the file.