Data Compression
- Distinguish lossless from lossy compression and their trade-offs
- Explain why compression reduces storage and transmission costs
- Compute and interpret a compression ratio
Why compress data
Data compression reduces the number of bits needed to store or send information. Smaller data means less storage space, faster transmission over a network, and lower cost. The catch is captured by a central question: can we get the original data back exactly? The answer splits compression into two families, and choosing between them is a trade-off between how small the data gets and how much fidelity is preserved.
Lossless: nothing lost
Lossless compression shrinks data in a way that allows the exact original to be perfectly reconstructed. It works by removing redundancy — for example, replacing a long run of repeated values with a short code that says "repeat this 200 times." Because no information is discarded, lossless is required whenever every bit matters: program files, text documents, spreadsheets, and formats like PNG and ZIP. The downside is that it generally cannot compress as much as the alternative.
Lossy: smaller, but permanent
Lossy compression achieves much smaller sizes by permanently discarding some information — details judged least noticeable to human senses. JPEG images, MP3 audio, and streaming video use it. The original can never be fully recovered, but for photos and music a well-chosen loss is nearly imperceptible while cutting size dramatically. The trade-off is direct: lossy gives smaller files but lower fidelity; lossless preserves everything but stays larger. Never use lossy where exactness matters.
A 2,000 KB image is compressed to 500 KB. Find the compression ratio and the percentage of space saved.
- 1.Compression ratio = original / compressed = 2000 / 500 = 4, i.e. a 4:1 ratio.
- 2.Space saved = original − compressed = 2000 − 500 = 1500 KB.
- 3.Percentage saved = 1500 / 2000 = 0.75 = 75%.
A programmer needs to compress an executable software file so it downloads faster, and the file must run correctly afterward. Which type of compression must be used, and why?
The deciding question is always: must the exact original be recoverable? If yes (text, code, data), use lossless. If some loss is acceptable (photos, music, video), lossy trades fidelity for much smaller size.
A 3,000 KB file is compressed to 750 KB. What is the compression ratio?
Remember the trade-off in one line: lossless = exact but larger; lossy = smaller but permanent loss. For a compression ratio, divide original by compressed — a bigger ratio means a smaller file.
Answer the 2 checkpoints as you read.
Sign in to save your progress