# Source coding theorem

> Source: https://modeladay.com/models/source-coding-theorem/
> Category: principle | Topics: science | Difficulty: 5/5

## Definition

Lossless compression floors at the source's entropy: average code length can never run under entropy, and squeezing past it always distorts.

## Core Rule

The limit of lossless compression is the source's entropy—average codeword length cannot fall below entropy, and compressing below entropy necessarily causes distortion. Common manifestation: you can approach entropy arbitrarily but never break through it, the theoretical floor of compression.

## Opening Context

You have four letters to send, so you could set aside two bits for every letter. But one letter keeps turning up, and two barely show. Do you really need to spend two places on each of them? Claude Shannon laid out those four letters in a paper and worked through the bill.

The source coding theorem tells you the smallest average cost you can approach when the reader has to recover every symbol exactly. Let's change Shannon's price list and see what saves space. Then we'll try to use the same limit on files of our own.

## How It Works (Preview)

First look at what Shannon put on the table: a source that gives him one letter at a time. Each choice is independent of the last. The first letter comes up half the time, the second a quarter, and the remaining two an eighth each.

In his 1948 paper, Shannon writes a single zero next to the most common letter. The second gets one zero, and the last two get one one zero and one one one. A bit is one position that holds a zero or a one. Join the codes together to send the message.

## When It Fails (Preview)

Before you apply that floor, ask which messages you meant to count. An encoder can have a very different day with one file than with another file the same size.

## Full Lesson, Audio & Practice

Get the full Source coding theorem breakdown, 5-minute audio lesson, interactive mechanism animation, and decision checklist in the ConceptFlow app:
- iOS App Store: https://apps.apple.com/app/conceptflow-mental-models/id6756862333
- Google Play: https://play.google.com/store/apps/details?id=com.juxianyp.conceptflow
- Web page: https://modeladay.com/models/source-coding-theorem/

## Related Mental Models

- [Kolmogorov complexity](https://modeladay.com/models/kolmogorov-complexity/)
- [Bandwidth and SNR](https://modeladay.com/models/bandwidth-and-snr/)
- [Channel capacity](https://modeladay.com/models/channel-capacity/)
