AP CSP Lossless vs. Lossy Compression
AP CSP Lossless vs. Lossy Compression: Complete Guide (2025‑2026)
Compression reduces file size by encoding data more efficiently. Lossless compression preserves every bit of the original — decompressing returns an identical copy. Lossy compression achieves much smaller files by permanently discarding data judged imperceptible to humans. The choice between lossless and lossy depends entirely on whether exact reconstruction matters. This is one of the most reliably tested topics on the AP CSP exam.
Contents
How Each Type Works
Lossless removes redundancy; original fully recoverable. Lossy discards data beyond human perception; smaller files but some information is gone permanently.
- Removes redundancy (repeated patterns)
- Example: run-length encoding (AAABBB → 3A3B)
- Decompression restores 100% of original
- File sizes smaller but not dramatically so
- Required when: exact data matters
- Removes data humans barely notice
- JPEG: blends nearly-identical pixels
- MP3: removes frequencies outside hearing range
- Decompression produces an approximation
- File sizes dramatically smaller
When to Use Each
A hospital stores patient X-rays digitally. A streaming service stores millions of songs for download. Which type of compression should each use, and why?
What would happen if the hospital used lossy compression on X-rays?
The hospital must use lossless. Medical images require exact pixel-level accuracy for diagnosis. Lossy compression could remove subtle patterns that indicate disease, resulting in misdiagnosis. A single missed tumor could be life-threatening. The streaming service can use lossy (MP3, AAC) because listeners cannot hear the discarded frequencies and the dramatic file size reduction (CD-quality audio: 50MB per song → MP3: 5MB) is worth the imperceptible quality loss at normal listening volumes.
The Storage-Quality Tradeoff
- Text files and code (ZIP, GZIP)
- Medical images (X-rays, MRI scans)
- Legal/financial documents
- Raw photo editing (PNG, TIFF)
- Database backups
- Scientific data collections
- Web photos (JPEG) — file size critical
- Streaming audio (MP3, AAC, OGG)
- Streaming video (MP4, HEVC)
- Video calls (quality vs. bandwidth)
- Social media image uploads
A photographer takes a raw photo (100MB). She saves it as JPEG at high quality (8MB). She opens the JPEG, makes minor edits, and saves it as JPEG again (7.5MB). She repeats this 10 times.
What happens to image quality after each save?
Each JPEG save is a new round of lossy compression. Each save introduces additional artifacts. After 10 saves, the image may show visible degradation — color banding, blurring around edges, and blocking artifacts — even though each individual step seemed fine. This is called “generation loss.” Professionals work in lossless formats (RAW, TIFF, PNG) and only export to JPEG as the final step to avoid this cascade.
Common Exam Pitfalls
At appropriate quality settings, lossy compression is imperceptible. JPEG at 90% quality looks identical to the original to most people. The key is that some data is permanently gone, even if humans cannot see the difference.
Once a file is saved as JPEG or MP3, the discarded data is gone. Decompressing a lossy file gives an approximation, not the original. Lossless decompression gives an exact copy.
Both are image formats, but GIF uses lossless compression (though it limits to 256 colors). PNG is also lossless. JPEG is lossy. The format name tells you which type is used.
A compressed file contains the same information (lossless) or a close approximation (lossy). Compression only affects how the data is stored, not what it represents.
Check for Understanding
1. A medical imaging system stores X-rays. Which compression type should it use?
- Lossy, because smaller files save storage costs.
- Lossless, because exact image data is required for accurate diagnosis.
- Lossy, because doctors only need approximate images.
- Either type is acceptable for medical imaging.
2. Which file format uses lossy compression?
- PNG
- ZIP
- JPEG
- FLAC
3. After lossy compression and decompression, the resulting file is:
- Identical to the original.
- An approximation — some data has been permanently lost.
- Larger than the original.
- Identical, but with lower resolution.
4. Consider: I. Lossless compression allows perfect reconstruction of the original file. II. Lossy compression always produces lower visual quality than lossless. III. JPEG uses lossy compression; PNG uses lossless compression.
- I only
- I and III only
- I, II, and III
- II and III only
5. A 40MB audio file is compressed to 4MB using MP3 encoding. What type of compression is this?
- Lossless — the 10x reduction is achievable without data loss.
- Lossy — some audio data has been permanently discarded.
- Either type could achieve this reduction.
- Neither — MP3 is not a compression format.
6. A programmer needs to compress a Python source code file for distribution. Which should they use?
- JPEG, because it produces the smallest files.
- Lossy compression, because small differences in code are unimportant.
- Lossless compression (ZIP/GZIP), because exact data recovery is required.
- Either type, because code can be approximated.
7. Why can lossy compression achieve much smaller file sizes than lossless?
- Lossy compression uses faster processors.
- Lossy compression removes data that humans cannot perceive, discarding more information.
- Lossy compression stores data in a more efficient mathematical format without loss.
- Lossy compression only works on certain file types.
8. A photo is saved as JPEG, edited slightly, and saved as JPEG again. This process is repeated 10 times. The result is:
- Identical to the original since JPEG preserves quality.
- Degraded due to repeated rounds of lossy compression causing cumulative quality loss.
- Larger than the original since each save adds data.
- Smaller than the original since JPEG deduplicates efficiently.
9. Which of the following would be most harmed by using lossy compression?
- A social media profile photo.
- A song downloaded for casual listening.
- A legal contract stored as an image scan.
- A video shared on a streaming platform.
10. FLAC audio is a lossless format; MP3 is lossy. For a file that started as FLAC: converting to MP3 and back to FLAC produces:
- The exact original FLAC file.
- A FLAC file that sounds different because lossy data loss cannot be reversed.
- A smaller FLAC file with no quality difference.
- The FLAC format automatically restores lost MP3 data.
How the AP Exam Tests This
- Identify whether a specific format (PNG, JPEG, ZIP, MP3, FLAC) is lossless or lossy
- Determine which compression type is appropriate for a given use case
- Explain why a medical or legal application requires lossless compression
- I/II/III: which statements about compression types are correct
- Identify the consequence of using lossy compression where exact data is required
FAQ
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
tanner@apcsexamprep.com
Courses
AP CSA, CSP, & Cybersecurity
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com