Staging: a draft, not the live site
Overview

Week 11 · 11.2 · Thu, Oct 15 · I Do: ACT-style reading

Lossless and Lossy Compression

This section explains two ways a computer makes a file smaller.

What Compression Does

A computer stores every file as a series of bytes, and each byte is 8 bits that hold a number from 0 to 255. A photo, a song and an essay are each a long list of these numbers. Compression is a way of making a file smaller by storing its information in fewer bytes. A smaller file occupies less storage and requires less time to transmit. Compression has two steps: the file is first encoded into a shorter form, and it is later decoded into a form that a program can use.

For example, when a photo is sent as a text message, the phone company may limit the size of the attachment, so an iPhone can compress the photo before sending it. An iPhone can also be set to send lower-quality images, which keep less detail. Copying a file is not an example of compression, because the copy is the same size as the original and holds the same bytes. The two kinds of compression differ in whether the decoded file matches the original exactly.

How Lossless Compression Works

Many files contain repeated patterns. Lossless compression is compression that records repeated patterns in a shorter form, so that the decoded file is identical to the original. For example, the string "AAAAAA" could be written as "6 A" and then rebuilt exactly. ZIP files usually use a lossless method called DEFLATE. First, DEFLATE looks for a string of characters that already appeared earlier in the file. Next, it replaces the repeated string with a short pointer that records how far back the earlier copy is and how long it is. When the file is decompressed, each pointer is replaced with the characters it points to.

For this lesson, the text of the DEFLATE standard was saved as a plain text file of 36,944 bytes. The zipped file took 11,345 bytes, and the unzipped file was 36,944 bytes again with 0 characters different. A zipped essay works the same way, because every character returns to its original position. For this reason, lossless compression is used for text files and computer programs, where one wrong character can change the meaning. A JPEG photo is not lossless, because some of its detail is gone and cannot be rebuilt.

How Lossy Compression Works

Photos, songs and videos are often stored with a different kind of compression, one that gives up some accuracy. Lossy compression is compression that removes some detail, so the decoded file is only close to the original and cannot be rebuilt exactly. JPEG became a standard format for photos in 1992. First, a JPEG encoder splits the photo into blocks of 8 by 8 pixels and turns each block into a set of 64 values. Next, it divides each value by a number from a table and rounds the result. The rounding removes detail, and the example tables in the standard were based on tests of what the human eye notices. Finally, the rounded values are stored in a compact code.

The program that saves a JPEG selects the table, so one photo can be saved with more or less detail. Figure 1 shows one photo of Jackson Square saved three times. Save 1 is 686,688 bytes, save 2 is 190,572 bytes, and save 3 is 85,533 bytes. All three have identical dimensions: 1,280 by 1,631 pixels. Save 3 kept the least detail, and its sky shows visible bands of color. A song from a streaming app is often lossy as well, and Spotify, for example, lists Lossless as a separate quality setting. A zipped essay is not lossy, because every character comes back.

When Detail Is Lost Again

Copying a JPEG file keeps every byte, so it removes no additional detail. Detail is lost again only when the picture is decoded and compressed a second time. Figure 1 also shows a chain of four pictures made to imitate a screenshot of a screenshot. Each step shrank the picture to four-fifths of its width and height and then saved it again as a JPEG. Screenshot 1 is 93,351 bytes, and screenshot 4 is 28,499 bytes. Each step removed additional detail, and no later step restored any of it. By screenshot 4, the lost detail is easy to see in the edges of the clock.

The Oct 6 reading, Ted Chiang's essay "ChatGPT Is a Blurry JPEG of the Web," used this idea of lossy compression to describe a chatbot. Monday's lesson continues that comparison.

Summary

Compression makes a file smaller by storing its information in fewer bytes. Lossless compression, used in ZIP files, gives back every byte of the original, while lossy compression, used in JPEG photos, removes detail that cannot be rebuilt. A JPEG loses more detail only when it is compressed again, as in a screenshot of a screenshot.

Sources: Deutsch, RFC 1951: DEFLATE Compressed Data Format Specification (1996); PKWARE, APPNOTE.TXT .ZIP File Format Specification (2022); CCITT, Recommendation T.81 (1992); JPEG committee, Overview of JPEG 1 (n.d.); NIST, The Binary Prefixes (n.d.); Apple Support, If You Can't Send or Receive Messages (2026); Spotify Support, Audio Quality (n.d.); Chiang, ChatGPT Is a Blurry JPEG of the Web (2023); Highsmith, St. Louis Cathedral on Jackson Square (Library of Congress); classroom data, Three JPEG Saves, Screenshot Chain and ZIP Round Trip (2026).

Figure 1. One public-domain photo of St. Louis Cathedral on Jackson Square (Carol M. Highsmith, Library of Congress) saved as a JPEG at quality 95, 60 and 15, with a chain below of four copies that are each shrunk and saved as a JPEG again to imitate a screenshot of a screenshot.
ACT-style reading · 9 questions

Read the passage on the left. Answer each question by clicking a choice: the right answer turns green, and a wrong one tells you why. Questions point to paragraph numbers, as on the ACT.

1. Main idea

The main purpose of the passage is to:

2. Detail

According to the section "What Compression Does," what is the one thing that has definitely changed in a compressed file compared to the original?

3. Detail

According to the section "How Lossless Compression Works," what does the test of a zipped text file show?

4. Sequence

According to the section "How Lossy Compression Works," what does the JPEG encoder do first to each 8 by 8 block of pixels?

5. Comparison

According to the section "How Lossy Compression Works," what is true of the three JPEG saves of the Jackson Square photo?

6. Cause and effect

According to the section "When Detail Is Lost Again," what happens when a JPEG is saved as a JPEG a second time?

7. Detail

According to the Summary section, which of the following correctly distinguishes lossless from lossy compression?

8. Words in context

As used in the section "How Lossy Compression Works," the word compact (in "stored in a compact code") most nearly means:

9. Inference

The passage says Spotify "lists Lossless as a separate quality setting." Based on this detail, which of the following is the best inference?