AP CSP Lossless vs. Lossy Compression

AP CSP Topics › Lossless vs. Lossy

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.

Lossless: original data perfectly recoverable after decompression
Lossy: some data permanently discarded — cannot be fully restored
10xTypical size reduction advantage lossy has over lossless for photos

How Each Type Works

Lossless vs. Lossy: What Happens to the Original Data Lossless Compression Original data fully recoverable Original: 100KB Compressed: 60KB ↓ decompress Restored: 100KB ✓ PNG, ZIP, FLAC, GIF Lossy Compression Some data permanently discarded Original: 100KB Compressed: 8KB ↓ decompress Restored: ~95KB ✗ JPEG, MP3, MP4, HEIC

Lossless removes redundancy; original fully recoverable. Lossy discards data beyond human perception; smaller files but some information is gone permanently.

Lossless Compression
No data lost
  • 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
Lossy Compression
Some data permanently discarded
  • 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

Scenario — Choose the Right Compression

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?

Answer

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

Lossless Use Cases
Exact data required
  • 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
Lossy Use Cases
Human perception allows approximation
  • Web photos (JPEG) — file size critical
  • Streaming audio (MP3, AAC, OGG)
  • Streaming video (MP4, HEVC)
  • Video calls (quality vs. bandwidth)
  • Social media image uploads
Scenario — The Quality Cascade

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?

Answer

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

1
Lossy compression does NOT mean bad quality

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.

2
You CANNOT recover the original from lossy compression

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.

3
GIF is lossless; JPEG is lossy

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.

4
Compression does not affect the inherent meaning of data

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.
Medical images require exact pixel data. Lossy compression could remove diagnostically significant details.

2. Which file format uses lossy compression?

  • PNG
  • ZIP
  • JPEG
  • FLAC
JPEG is lossy. PNG, ZIP, and FLAC are all lossless.

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.
Lossy compression permanently discards data. Decompression produces an approximation.

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
I is correct. III is correct. II is false — lossy compression can produce perceptually identical results at appropriate quality settings.

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.
MP3 is lossy. The dramatic 10x reduction is achieved by discarding audio frequencies below hearing threshold and using perceptual encoding.

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.
Source code requires exact byte-for-byte preservation. A single changed character could cause a syntax error or security vulnerability.

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.
Lossy compression exploits human perceptual limits (color sensitivity, hearing range) to discard large amounts of data that won’t be noticed.

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.
Each JPEG save introduces new artifacts. Repeated saves accumulate quality loss — known as generation loss.

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.
A legal contract requires exact character-level accuracy. Lossy compression could make text unreadable or change characters, making the document legally invalid.

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.
Converting FLAC → MP3 permanently discards audio data. Converting back to FLAC format does not restore the lost data. The file is FLAC-formatted but with MP3-quality content.

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

Is video streaming always lossy?
Almost always yes. H.264, H.265, and VP9 are all lossy video codecs used by Netflix, YouTube, and Zoom. Raw video is so large (a 2-hour film in raw 4K = several terabytes) that lossless transmission is impractical over current networks.
What is run-length encoding?
A simple lossless technique: instead of storing AAABBB, store 3A3B. Works well for images with large uniform areas (like logos or diagrams). Not effective for photos with constantly varying colors.

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

tanner@apcsexamprep.com

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at tanner@apcsexamprep.com