CS I · Thu Oct 15 · 11.2 · We Do

Before the bell

You are responsible for all of this before the end of class.

  1. The discussion form in the I Do deck. All three sections. If you are here, this should be done.
  2. Your classwork. This form on the right. Section 1 before the exit ticket pops up; Section 2 past the floor.
  3. No Bench Basics today — this is a short or catch-up day.
  4. The exit ticket. It opens 20 minutes before the bell and lives on the last slide of this deck.
Classwork

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

How Small Is Smaller

This reading explains the units that measure the size of a file, from the smallest to the largest.

From Bits to Gigabytes

The smallest unit of digital storage in this reading is the bit. A byte is a group of 8 bits, and file sizes are usually counted in bytes or in larger units built from bytes. A kilobyte (KB) is 1,000 bytes, a megabyte (MB) is 1,000,000 bytes, and a gigabyte (GB) is 1,000,000,000 bytes. From the byte upward, each unit is therefore exactly 1,000 times larger than the unit before it. Some computer programs and operating systems count a kilobyte as 1,024 bytes instead, so two different devices can display slightly different numbers for the same file. The CompTIA Tech+ exam lists the bit, the byte, the KB and the GB among the storage units that it tests.

Measuring the Three Saves

Figure 1 shows one photograph saved three times at different quality settings, and each save produced a file of a different size. Save 1 is 686,688 bytes, which is between 686 KB and 687 KB and less than 1 MB. Save 2, at 190,572 bytes, falls between 190 KB and 191 KB, and save 3, at 85,533 bytes, falls between 85 KB and 86 KB. Measured in bits, save 3 is 684,264 bits, because each of its 85,533 bytes holds 8 bits.

Because save 3 is the smallest of the three files, a fixed amount of storage can hold more copies of it than of either of the others. One gigabyte holds 11,691 complete copies of save 3, with 33,697 bytes remaining, while the same gigabyte holds only 5,247 copies of save 2 and 1,456 copies of save 1. A phone with 64 GB of free space could therefore hold 748,249 copies of save 3, 335,831 copies of save 2 or 93,200 copies of save 1. The smaller file comes at a cost, however, because save 3 also preserved the least detail of the three photographs.

Sources: NIST, The Binary Prefixes (n.d.); Deutsch, RFC 1951 (1996); CompTIA, Tech+ Certification (2024); classroom data, Three JPEG Saves (2026).

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).

Classwork · Section 1 — Reading 2

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

MC 1. (File 1 · zipped essay) You save an essay as a ZIP file. Is that lossless or lossy compression?

  • Lossless
  • Lossy

MC 2. (File 1 · zipped essay) Can you rebuild the original essay exactly from the ZIP file?

  • Yes
  • No

MC 3. (File 2 · JPEG photo) You save a photo as a JPEG. Is that lossless or lossy compression?

  • Lossless
  • Lossy

MC 4. (File 2 · JPEG photo) Can you rebuild the original photo exactly from the JPEG?

  • Yes
  • No

MC 5. (File 3 · song from a streaming app) You play a song in a streaming app on its normal setting. The app lists Lossless as a separate setting. Is the normal setting lossless or lossy compression?

  • Lossless
  • Lossy

MC 6. (File 3 · song from a streaming app) Can you rebuild the original recording exactly from the song on the normal setting?

  • Yes
  • No

MC 7. (File 4 · screenshot of a screenshot) Look at the chain in Figure 1. Each step shrinks the picture and saves it as a JPEG again. Is that lossless or lossy compression?

  • Lossless
  • Lossy

MC 8. (File 4 · screenshot of a screenshot) Can you rebuild the original picture exactly from screenshot 4?

  • Yes
  • No
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.
Classwork · Section 2 — Past the floor

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

CR 1. Put these five file sizes in order from smallest to largest: 1 GB, 686,688 bytes, 3 MB, 1 KB, 85,533 bytes. Use the units from How Small Is Smaller.

Write your answer in your lab notebook, labeled CR 1.

Bench Basics

No bench today

There is no bench on this day. Finish your classwork and move to the exit ticket.

No bench today — the bench pop-up is off for this day.

Classwork

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

Exit Ticket

This opens during your class period.