by Samy (Kondasamy Jayaraman)

Module 34 · Compression

Beginner · by Samy (Kondasamy Jayaraman)

Repeats shrink, noise doesn’t

Compression replaces what a file repeats with something shorter. Here you pack Larkspur’s price list and pictures for a slow line, and meet the files no method can shrink.

Read as

The whole idea in one example

Same packing, two files

The price list

shrinks

691 → 485

Bytes, before and after.

Random bytes

grows

512 → 864

No repeats to replace.

Both packed by this site’s own pointers-then-short-codes coder, the shape of DEFLATE. The random file is seeded noise made for this site.

How it works

Four ideas carry the module

  1. 1 Count the bytes

    A few bytes fill most of a text

    RFC 3629: in UTF-8, the US-ASCII characters (plain English letters, digits and punctuation) take one byte each.

    Source, checked 25 October 2026

  2. 2 Point back

    Repeats become pointers

    Jacob Ziv and Abraham Lempel published the pointer method now called LZ77 in 1977, in IEEE Transactions on Information Theory.

    Source, checked 25 October 2026

  3. 3 Short codes

    Merge the two lightest piles

    David Huffman published his method for building minimum-redundancy codes in the Proceedings of the IRE in 1952.

    Source, checked 25 October 2026

  4. 4 Some files won’t shrink

    Random bytes only grow

    RFC 1951: no lossless compression algorithm can compress every possible input data set.

    Source, checked 25 October 2026

The story

Larkspur’s nightly send

Larkspur Supply Co.’s catalogue and pictures are too big to send each night; the team finds that compression replaces repeats, so repeated text shrinks and random bytes can’t. You’re on the team that packs it.

4
site files on one slow line each night
691
bytes in Larkspur Supply Co.’s price list before packing
485
bytes after our pointers and short codes
4
plans fit the nightly budget in chapter 7

Your path

The chapters

  1. Chapter 1

    Counting the bytes

    What is a file made of, and where could it be smaller?

  2. Chapter 2

    Point back

    How does pointing back at earlier bytes make a file smaller?

  3. Chapter 3

    Short codes for common letters

    How does Huffman’s rule give the commonest letters the shortest codes?

  4. Chapter 4

    Both at once

    How close does our pair of coders get to real gzip?

  5. Chapter 5

    Already squeezed

    Why can’t any method shrink every file?

  6. Chapter 6

    Throwing some away

    How does throwing detail away make a picture small, and what does it cost?

  7. Chapter 7

    Pack the nightly send

    Which setting per file fits the budget, with the picture still close enough?

Who it’s for

  • Engineers
  • Product managers
  • Analysts
  • No code needed

Anyone who has zipped a file or waited on a slow download, and wants to know why some files shrink and others won’t. No maths needed.