Series

How Compression Works

From First Principles — Simple to Advanced

Every file on your computer is a sequence of bytes. Compression is the art of finding patterns and redundancy in those bytes and representing them more efficiently. The original data doesn't change — we just find a shorter way to describe it.

This series walks through the most important compression algorithms ever invented, starting from the simplest ideas and building up to the techniques behind modern tools like gzip, bzip2, and zstd. Each page builds on concepts from previous ones.

How to read this series: Start from the top. Each algorithm introduces new ideas that later pages build on. Every page includes fully worked examples — follow along step by step. By the end, you'll understand how virtually all lossless compression works.
  1. 001
    Beginner Run-Length Encoding (RLE)

    The simplest compression algorithm

    7 min
  2. 002
    Beginner Huffman Coding

    Use fewer bits for common symbols

    7 min
  3. 003
    Intermediate LZ77

    Remember what you've seen before

    18 min
  4. 004
    Intermediate LZ78 & LZW

    Build a dictionary as you go

    11 min
  5. 005
    Intermediate DEFLATE

    The engine behind gzip, zip, and PNG

    12 min
  6. 006
    Intermediate Burrows-Wheeler Transform

    A magical rearrangement

    14 min
  7. 007
    Advanced Arithmetic Coding

    Encoding with fractional bits

    11 min
  8. 008
    Advanced ANS & Zstandard

    Modern compression: fast and optimal

    13 min

Deeper Dive Into...

The algorithms above cover lossless compression — shrinking data without losing a single bit. But the rabbit hole goes much deeper.

  1. 009
    Intermediate Information Theory & Entropy

    Measuring the true information content of data

    15 min
  2. 013
    Advanced Kolmogorov Complexity

    The shortest possible description of anything

    15 min
  3. 010
    Intermediate Lossy Compression

    Throwing away what you can't perceive

    18 min
  4. 011
    Intermediate DCT & Image Compression

    The mathematical trick at the heart of JPEG

    19 min
  5. 014
    Intermediate JPEG: End to End

    How DCT, quantization, and Huffman combine to compress photos

    19 min
  6. 012
    Intermediate Delta & Predictive Coding

    Store differences instead of values

    16 min
  7. 015
    Intermediate Video Compression

    Motion estimation, I/P/B frames, and why video files are so small

    18 min

Modern Lossless Formats

How modern compressors combine the building blocks above into practical, high-performance tools.

  1. 016
    Advanced LZSS & LZMA

    From LZ77 refinements to the engine behind 7-Zip

    16 min
  2. 017
    Advanced Zstandard Deep Dive

    Inside the frame format, FSE tables, and dictionary training

    19 min