The Stacks
BIG IDEA 2: DATA · TOPIC 2.2

2.2 Data Compression

The single most-tested distinction in this Big Idea. Compression shrinks data; the question is always whether the original can be rebuilt.

What you need to know

  • Data compression reduces the number of bits needed to store or transmit data. Fewer bits means less storage and faster transfer.
  • Lossless compression reduces size while allowing complete reconstruction of the original. Used where every bit matters: text, program code, spreadsheets, and formats like PNG and ZIP. It typically achieves smaller savings.
  • Lossy compression permanently removes some data to achieve much greater size reduction. The original cannot be exactly rebuilt, but the loss may be imperceptible. Used for JPEG images, MP3 audio, and streaming video.
  • The trade-off: lossy gives smaller files at the cost of fidelity. The right choice depends on whether exact reconstruction is required and how much quality loss is acceptable.
  • The amount of compression possible depends on the data: highly repetitive data compresses well losslessly (e.g., long runs of the same value); already-random data barely compresses.
  • Decisions about compression are made based on the purpose: archiving a legal document → lossless; sending a photo to a friend → lossy is fine.

Worked example

The text AAAAAAABBBBBCCC can be stored losslessly as 7A5B3C — the original is exactly recoverable from the counts. That's the idea behind run-length encoding, a simple lossless technique. A photo, by contrast, might have thousands of nearly-identical blue-sky pixels; a lossy scheme averages them into fewer values, saving far more space, but the exact original pixels are gone.

Exam tip: If the stem says the file must be "exactly" or "perfectly" restored, or involves text/code/financial records, answer lossless. If it emphasizes minimizing size or transmission time and the data is an image, video, or audio where small quality loss is acceptable, answer lossy. Also remember: compression is about size and speed — not security.

Going deeper

The nuance, edge cases, and connections that turn a 3 into a 5.

  • The CED says the choice between lossy and lossless depends on the purpose: is the goal to minimize size or to preserve every detail? Questions give you a purpose and expect the matching choice.
  • Lossless compression exploits redundancy — patterns, repetition, predictable structure. Text has lots (common letters, repeated words), so it compresses well. Random data has none and barely compresses at all.
  • Lossy compression exploits perception: humans can't hear very high frequencies or see tiny color differences between adjacent pixels, so that data can be dropped without a noticeable change. The "loss" is real but designed to be invisible.
  • Lossy compression is irreversible. Decompressing a JPEG gives you an approximation of the original image, not the original. Compressing it again loses more. This is why editing workflows keep a lossless master.
  • Compression ratio and quality trade off continuously — a lossy algorithm typically has a quality setting. Higher compression = smaller file = more loss. The exam may describe this as a slider or a percentage.
  • Compression is about size (storage) and transmission time (bandwidth). It has nothing to do with security. Compressed data is not encrypted.

Mistakes that cost points

  • Choosing lossy for anything that must be exact. Text documents, program source code, financial records, medical scans for diagnosis, legal archives: lossless. If the stem says "exactly," "perfectly," "identical," or "no data lost," it's lossless.
  • Assuming lossless always gives the smallest file. It's the opposite — lossy compresses far more. Lossless is the safe choice, not the small choice.
  • Confusing compression with encryption. An option saying "compress the file so it can't be read by others" is wrong. Compression doesn't hide data.
  • Thinking a decompressed lossy file is restored. It's not. The detail is gone permanently.

Practice questions

Written in the style of the real exam. Try each one before revealing the answer.

Q1 A hospital needs to store patient X-ray images so that every detail can be recovered exactly for later diagnosis, even if the files take more storage. Which compression approach is most appropriate?
  1. A Lossy compression, because it reduces file size the most
  2. B Lossless compression, because the original image can be fully reconstructed
  3. C No compression is possible for image data
  4. D Encryption, because it makes the file smaller
Show answer

Answer: B. Exact reconstruction is required, so lossless. Encryption is about security, not size.

Q2 Which of the following best describes a trade-off of using lossy compression for a video that will be streamed over a slow connection?
  1. A The video will be larger but higher quality.
  2. B The video will be smaller and faster to transmit, but some detail is permanently lost.
  3. C The video can be perfectly reconstructed, but only after transmission completes.
  4. D The video cannot be played until decompressed by the sender.
Show answer

Answer: B. Lossy = big size reduction (good for slow connections) at the cost of irrecoverable detail.

Key vocabulary

Data compression
reducing the number of bits needed to represent data
Lossless compression
compression from which the original data can be completely reconstructed
Lossy compression
compression that permanently discards some data for greater size reduction