A1.1.9 — Compression
What is Compression?
Reducing file size to enable faster transmission over networks, less storage usage, and better application performance.
Lossless vs Lossy
| Feature | Lossless | Lossy |
|---|---|---|
| Data integrity | Original fully preserved — decompressed file is identical. | Some data permanently discarded. |
| Compression ratio | Lower | Higher |
| Reversible? | Yes | No |
| Use case | Backups, documents, archives, source code. | Images, audio, video — where minor quality loss is acceptable. |
| Examples | GIF, TIFF, ZIP, PNG, PDF | JPEG, MP3, MPEG |
Compression Methods
Run-Length Encoding (RLE)
Replaces runs of consecutive identical values with a count and the value.
Example: AAAABBBBCC → 4A4B2C
Type: Lossless. Best for: Data with long repeated sequences — fax images, simple graphics, text files.
Transform Coding
Converts data into a different mathematical representation (e.g. Discrete Cosine Transform in JPEG) that makes redundancy easier to remove.
Type: Usually lossy. Best for: Complex data like photos, audio, video — achieves much higher compression ratios than RLE.
Used in: JPEG, MP3, MPEG.
File Formats Summary
| Type | Formats | Typical use |
|---|---|---|
| Lossless | PNG, GIF, TIFF, ZIP, PDF | Backups, documents, simple graphics |
| Lossy | JPEG, MP3, MPEG | Photos, music, video |
| RLE | Fax format, BMP (uncompressed) | Fax images, simple text |
| Transform coding | JPEG, MP3, MPEG | Photos, audio, video |