Key Concepts
Lossless Compression
Original data can be perfectly restored
Lossy Compression
Some data permanently removed
Compression Ratio
Lossless: ~20-50%
Lossy: ~70-95%
File Size Reduction
New size = Original × (1 - ratio)
Compressing a Software Installation File
Scenario
A software company needs to compress their 500 MB installation package for download from their website.
Which type of compression should they use, and why?
Solution
Identify the file type
Software installation files contain:
- Executable code (.exe files)
- Configuration files
- Libraries and resources
These are program files - every bit matters!
Consider the consequences of data loss
If even one bit is changed or lost:
- The software might crash
- Security could be compromised
- Features might not work
- The entire installation could fail
Apply the decision rule
Rule: If the file must be exactly the same after decompression, use lossless.
Software files MUST be identical → Use Lossless
Answer
Lossless compression (e.g., ZIP format)
Reason: Software files must be bit-perfect to function correctly. Any data loss would corrupt the installation.
This is why software downloads typically come as .zip, .7z, or self-extracting archives.
Storing Holiday Photos
Scenario
You've taken 200 photos on holiday, each 25 MB in RAW format. Your phone has 5 GB of storage space remaining.
What compression approach would allow you to keep all photos?
Solution
Calculate total uncompressed size
Total size = 200 photos × 25 MB = 5,000 MB (5 GB)
Available space = 5 GB
Problem: Files exactly fill the space with no room left!
Consider lossless compression
Lossless typically reduces photos by 20-40%
Best case: 5,000 × 0.6 = 3,000 MB (3 GB)
This might fit, but photos don't compress well with lossless.
Consider lossy compression (JPEG)
JPEG typically achieves 80-95% compression
At 90% compression: 5,000 × 0.1 = 500 MB
This easily fits with plenty of room to spare!
Assess acceptability of quality loss
Holiday photos are for:
- Viewing on screens
- Sharing on social media
- Printing at normal sizes
Slight quality reduction is not noticeable for these uses.
Answer
Lossy compression (JPEG)
Result: 200 photos at ~2.5 MB each = 500 MB total
Reason: Photos compress very well with JPEG, and the quality difference is imperceptible for normal viewing and sharing.
Professional photographers might keep RAW files for editing, but JPEGs are fine for personal use.
Calculating Compressed File Size
Problem
An uncompressed audio file is 50 MB.
- Lossless compression (FLAC) achieves 40% size reduction
- Lossy compression (MP3 at 320kbps) achieves 80% size reduction
Calculate the file size for each compression method.
Solution
Calculate FLAC (lossless) size
Size reduction = 40%
Remaining size = 100% - 40% = 60%
FLAC size = 50 MB × 0.6 = 30 MB
Calculate MP3 (lossy) size
Size reduction = 80%
Remaining size = 100% - 80% = 20%
MP3 size = 50 MB × 0.2 = 10 MB
Compare the results
FLAC: 30 MB (quality preserved perfectly)
MP3: 10 MB (slight quality loss)
MP3 is 3× smaller than FLAC
Answer
| Format | Type | Size | Quality |
|---|---|---|---|
| FLAC | Lossless | 30 MB | Perfect |
| MP3 320kbps | Lossy | 10 MB | Near-perfect |
For most listeners, MP3 at 320kbps sounds identical to the original, making it the popular choice.
Optimizing Images for a Website
Scenario
A web developer has a product page with 10 images. Each image is currently 2 MB (PNG format).
The page takes 8 seconds to load on average mobile data speeds.
How can compression improve the user experience?
Solution
Calculate current total
Total image data = 10 × 2 MB = 20 MB
This is too large for fast web loading.
Choose compression approach
Product photos can use lossy compression (JPEG) because:
- Photos compress very well as JPEG
- Slight quality loss is invisible on screens
- Faster loading improves sales
Calculate compressed size
JPEG at 85% quality typically achieves 90% reduction
New size per image = 2 MB × 0.1 = 200 KB
Total = 10 × 200 KB = 2 MB
Calculate loading time improvement
Original: 20 MB → 8 seconds
Compressed: 2 MB → approximately 0.8 seconds
That's 10× faster!
Answer
Convert images to JPEG at 85% quality
Result: Page load time reduced from 8 seconds to under 1 second
Impact: Better user experience, lower bounce rate, and improved SEO rankings
Studies show that 53% of mobile users leave a page that takes longer than 3 seconds to load.
Planning Cloud Storage Needs
Scenario
A small business needs to backup:
- 50 GB of documents and spreadsheets
- 200 GB of photos
- 100 GB of video footage
How much cloud storage should they purchase, assuming optimal compression?
Solution
Compress documents (lossless)
Documents must use lossless (data integrity is critical)
ZIP compression typically achieves 60-70% reduction for text
Compressed size = 50 GB × 0.35 = 17.5 GB
Compress photos (lossy acceptable)
For backup purposes, JPEG compression is acceptable
Assuming already compressed at 80% reduction
Compressed size = 200 GB × 0.2 = 40 GB
Compress video (lossy)
Video compresses very well with H.264/MP4
Assuming 85% compression
Compressed size = 100 GB × 0.15 = 15 GB
Calculate total and add buffer
Total compressed = 17.5 + 40 + 15 = 72.5 GB
Add 30% buffer for growth = 72.5 × 1.3 = ~95 GB
Answer
Purchase 100 GB of cloud storage
| File Type | Original | Compressed | Method |
|---|---|---|---|
| Documents | 50 GB | 17.5 GB | Lossless (ZIP) |
| Photos | 200 GB | 40 GB | Lossy (JPEG) |
| Video | 100 GB | 15 GB | Lossy (H.264) |
| Total | 350 GB | 72.5 GB |
Compression reduced storage needs by 79%!
Choosing JPEG Quality Level
Scenario
A photographer is saving a 10 MB RAW image. They have three quality options:
- JPEG 100% quality → 4 MB
- JPEG 80% quality → 1 MB
- JPEG 50% quality → 250 KB
Which should they choose for: (a) their portfolio website, (b) email attachment, (c) thumbnail preview?
Solution
Analyze portfolio website needs
Purpose: Showcase professional work
Requirements: High quality, some loading time acceptable
Best choice: 100% quality (4 MB)
Analyze email attachment needs
Purpose: Share image with client
Requirements: Good quality, must fit email limits (often 10-25 MB)
Best choice: 80% quality (1 MB)
Quality difference barely visible, fits easily in email
Analyze thumbnail needs
Purpose: Quick preview at small size
Requirements: Tiny file size, displayed at 200×200 pixels or less
Best choice: 50% quality (250 KB)
At thumbnail size, quality loss is invisible
Answer
| Use Case | Quality | Size | Reason |
|---|---|---|---|
| Portfolio | 100% | 4 MB | Quality matters most |
| 80% | 1 MB | Good balance | |
| Thumbnail | 50% | 250 KB | Speed matters most |
The "right" compression depends entirely on how the image will be used!
Music Streaming Quality Settings
Scenario
A music streaming service offers different quality levels:
- Low: 96 kbps (0.72 MB per minute)
- Normal: 160 kbps (1.2 MB per minute)
- High: 320 kbps (2.4 MB per minute)
- Lossless: 1,411 kbps (10.6 MB per minute)
How much data would a 3-hour playlist use at each quality?
Solution
Convert duration to minutes
3 hours = 3 × 60 = 180 minutes
Calculate data for each quality
Low: 180 × 0.72 = 130 MB
Normal: 180 × 1.2 = 216 MB
High: 180 × 2.4 = 432 MB
Lossless: 180 × 10.6 = 1,908 MB (1.9 GB)
Compare the implications
If you have 2 GB mobile data per month:
- Low: Could stream ~46 hours
- Normal: Could stream ~27 hours
- High: Could stream ~14 hours
- Lossless: Could stream ~3 hours
Answer
| Quality | 3 Hours | Compression | Best For |
|---|---|---|---|
| Low | 130 MB | Lossy (93%) | Saving data |
| Normal | 216 MB | Lossy (89%) | Casual listening |
| High | 432 MB | Lossy (77%) | Good headphones |
| Lossless | 1.9 GB | Lossless | Audiophiles |
Most people cannot hear the difference between 320 kbps and lossless, but the file size is 4× different!
Understanding Generation Loss
Scenario
A student edits a JPEG photo and saves it. Then edits it again and saves it. They repeat this 10 times.
What happens to the image quality, and why?
Solution
Understand the problem
JPEG is a lossy format. Each time you save:
- The image is recompressed
- More data is discarded
- Quality degrades further
This is called generation loss.
Visualize the degradation
Each save cycle:
- Save 1: Small quality loss (barely visible)
- Save 2-3: Quality loss accumulates
- Save 5-6: Visible artifacts appear
- Save 10: Significant degradation, blocky areas
The solution
To avoid generation loss:
- Edit in a lossless format (PNG, TIFF)
- Only save as JPEG once, at the very end
- Keep the original file unedited
Answer
Effect: After 10 saves, the image quality will be significantly degraded with visible compression artifacts (blocky areas, colour banding, blurring).
Why: JPEG compression discards data each time. These losses accumulate with each save cycle.
Prevention: Always edit in a lossless format and export to JPEG only once as the final step.
This is why professional photographers work with RAW files, not JPEGs!
Practice Problems
Try these on your own, then reveal the answers to check.
Practice 1: Compression Choice
A hospital needs to compress patient medical records (text documents with scanned medical images). Which compression type should they use?
Lossless compression
Medical records must be exact - any data loss could lead to misdiagnosis or legal issues. Even the scanned images should use lossless (PNG) as medical details might be critical.
Practice 2: File Size Calculation
A 4K video file is 8 GB uncompressed. If lossy compression achieves 95% reduction, what is the compressed size?
Remaining size = 100% - 95% = 5%
Compressed size = 8 GB × 0.05 = 400 MB
Practice 3: Storage Planning
A YouTube creator uploads 2 videos per week, each 30 minutes long. Uncompressed, each video is 50 GB. After H.264 compression (90% reduction), how much storage is needed for one year's videos?
Videos per year = 2 × 52 = 104 videos
Compressed size per video = 50 GB × 0.1 = 5 GB
Total = 104 × 5 GB = 520 GB
(Compared to 5,200 GB uncompressed!)
Practice 4: Best Format Choice
A graphic designer creates a logo with flat colours and sharp edges. Should they save it as JPEG or PNG?
PNG (lossless)
Logos with flat colours and sharp edges compress very well with PNG and remain perfectly crisp. JPEG would introduce artifacts around the edges and in solid colour areas.