Shannon Entropy and Information

Two messages arrive on your phone. The first says: "the sun rose this morning." The second says: "school is cancelled today." Both are short sentences — but one of them is worthless and the other changes your whole day. Why? The first told you something you already knew was practically certain; the second told you something unlikely. In 1948 Claude Shannon turned this everyday intuition into a number: information is surprise, and surprise can be measured, in bits. The theory he built in one legendary paper underpins every ZIP file, every video stream, every phone call — and, as we will keep discovering, a surprising amount of physics.

Measuring surprise: \log_2(1/p)

Suppose an event has probability p. Shannon defined the information content (or surprisal) of seeing it actually happen as

I = \log_2\!\frac{1}{p} \;=\; -\log_2 p \quad \text{bits}.

Why a logarithm? Because it is the only choice that makes information behave the way it obviously should:

The unit comes out beautifully. A fair coin flip has p = \tfrac12 per outcome, so each flip carries \log_2 2 = 1 — exactly one bit. The bit is not just a circuit voltage; it is the natural unit of surprise. And there is a lovely game hiding in the formula: \log_2 n is the number of yes/no questions you need to pin down one possibility out of n equally likely ones. Guessing a secret number from 1–64? Six good questions ("is it bigger than 32?" …) always suffice, because \log_2 64 = 6. Information content is the length of the perfect game of twenty questions.

Entropy: the average surprise of a source

A single event has a surprisal. A source — anything that keeps emitting symbols, like a coin, a die, or someone typing English — has an average surprisal, taken over its probabilities. That average is the Shannon entropy:

H \;=\; \sum_i p_i \log_2\!\frac{1}{p_i} \;=\; -\sum_i p_i \log_2 p_i \quad \text{bits per symbol}.

Each outcome contributes its surprise \log_2(1/p_i), weighted by how often it occurs, p_i. Let's work some examples:

SourceDistributionEntropy H
Fair coin½, ½1 bit
Biased coin0.9, 0.1≈ 0.47 bits
Fair six-sided die⅙ each≈ 2.58 bits
Uniform letters A–Z1/26 each≈ 4.70 bits
English letter frequenciesE 12.7%, T 9.1%, … Z 0.07%≈ 4.1 bits
A coin glued heads-up1, 00 bits

Notice the pattern: uniform is maximal. Any lopsidedness in the probabilities makes the source more predictable and drags the entropy down, all the way to 0 bits for a source that always says the same thing.

The binary entropy curve

For a coin with heads-probability p, the entropy is the binary entropy function

H(p) = -\,p \log_2 p \;-\; (1-p)\log_2(1-p).

Slide p below and watch the dashed line track the entropy of your coin. The curve peaks at exactly 1 bit when p = \tfrac12 (a fair coin is the least predictable coin) and falls symmetrically to 0 at both ends — a coin that always, or never, lands heads tells you nothing at all.

Entropy is the speed limit of compression

Here is why entropy is an engineering number and not just a philosophical one. Suppose your source emits symbols with entropy H bits per symbol, and you want to store its output in as few bits as possible — give short codes to common symbols, long codes to rare ones, exactly as Huffman coding does. How well can you possibly do? Shannon answered exactly:

This is why entropy deserves the name "information": it is the size of what the source is really telling you, once every scrap of redundancy has been squeezed out. Our 90%-heads coin has entropy \approx 0.47 bits per flip, so a clever code can record a million of its flips in about 470,000 bits — under half a bit per flip — and no code in the universe can beat that. A fair coin's flips, at a full 1 bit each, cannot be compressed at all: perfectly random data is incompressible, precisely because every bit of it is a genuine surprise.

Shannon knew his formula measured uncertainty, but he didn't know what to call it. The story goes that he asked John von Neumann, who replied: call it entropy — first, because the same formula already exists in statistical mechanics under that name, and second, "because nobody knows what entropy really is, so in a debate you will always have the advantage." The joke has teeth: Shannon's -\sum p_i \log p_i really is, symbol for symbol, Gibbs's formula for thermodynamic entropy, just with the logarithm rebased and Boltzmann's constant stripped off. That coincidence turns out to be no coincidence at all — bits and joules are connected by a real exchange rate, and pulling on this thread leads to Landauer's principle, Maxwell's demon, and the physics of computation itself.

A tempting misreading: "lots of information = lots of meaning." Shannon's measure says nothing of the sort. A page of random letters — XQJVK ZPWOR… — has maximal entropy: every character is a fresh 4.7-bit surprise, and the page is utterly incompressible. A page of Shakespeare has lower entropy: English is redundant, so much of each letter is predictable filler. Yet the random page means nothing and the Shakespeare means everything. Shannon was completely upfront about this — his theory deliberately ignores what messages mean and measures only how unpredictable they are, because that is what determines the resources (bits, bandwidth, storage) needed to carry them. Entropy measures surprise, not significance. A surprising message may still be gibberish; a profound one may be almost free to transmit.