Alex Oberneyer

Interactive essays / 04

Information
is a surprise.

How much does a message tell you? Start with what you didn’t know. Follow that question to compression, communication, and the limits of prediction.

INFORMATION THEORY4 SMALL EXPERIMENTSSTART WITH BASIC PROBABILITY

“The sun rose.”   “Your coin landed on its edge.”
Similar-sized sentences. Very different amounts of surprise.

01 / One event

The less you expect it,
the more it tells you.

Imagine a friend secretly chooses one of eight equally likely boxes. Learning which box they chose resolves three bits of uncertainty: three well-chosen yes/no answers can identify it.

A bit is a unit of information. One bit distinguishes two equally likely possibilities. Two bits distinguish four; three bits distinguish eight.

For an event with probability p, its surprisal is:

I(x) = −log₂ p(x)x is the observed outcome; p(x) is its probability. Every halving of probability adds one bit of surprise.
Experiment 01

Make an event less likely.

The probability is your model’s expectation before the outcome is revealed.

12.5%
0.1% · rare100% · certain
3.00
bits of surprise

One of eight equally likely outcomes: three bits.

Notice: changing 50% → 25% adds the same one bit as changing 2% → 1%. Information follows a logarithmic scale.

Information is relative to a probability model. What surprises you may be entirely predictable to someone else.

Why a logarithm? And what happens at zero?

Independent events have probabilities that multiply. Their information should add. Logarithms turn multiplication into addition: two independent 50% events have joint probability 25%, giving 1 + 1 = 2 bits.

A certain event has zero surprisal. As probability approaches zero, surprisal grows without bound. An observed event assigned exactly zero probability signals a problem with the model; the slider stops at 0.1%.

02 / A whole source

Surprise, averaged.

A coin that almost always lands heads is easy to predict. A rare tail is very surprising—but it happens rarely. A fair coin keeps you guessing on every toss.

Entropy is the probability-weighted average of the surprise of all possible outcomes. It measures uncertainty before you see the result.

H(X) = Σ p(x) · I(x) = −Σ p(x) log₂ p(x)X is a random variable; Σ adds over its possible outcomes x. For a coin with heads probability p: H₂(p) = −p log₂ p − (1−p) log₂(1−p). Terms with zero probability contribute zero.
Experiment 02

Which coin is hardest to predict?

50%
Always tailsAlways heads
1.000bits per toss, on average
1.00bits if tails occurs
Entropy of a coinEntropy is zero at heads probabilities zero and one, and reaches one bit at probability one half.1.000%50%100%bits / tossProbability of heads
The curve is symmetric: always heads and always tails are equally predictable.

At 50/50, uncertainty is maximal: each toss produces one bit of information.

Try 99% heads. A tail now carries about 6.64 bits of surprise, yet the average is only 0.081 bits per toss. A rare surprise and a highly unpredictable source are different things.

Pause & predict: what about a perfectly alternating coin?

If the sequence is H,T,H,T forever and only the starting phase is unknown, its individual symbols are 50/50. But one bit identifies the entire sequence of known length. Its entropy rate tends to zero as the sequence grows.

The lesson: correlations matter. Marginal symbol entropy is not always the information per symbol in a sequence.

03 / Describing a message

Predictability is
an opportunity to compress.

If every symbol uses two bits, A, B, C and D all cost the same. But when A is common, giving it a shorter code can reduce the average. Rare symbols can afford longer codes.

Use this codebook: A → 0, B → 10, C → 110, D → 111. No codeword starts another codeword, so a receiver can recover the boundaries without spaces. That makes it a prefix code.

Experiment 03

Same alphabet. Different cost.

Choose a 16-symbol message. The codebook stays fixed.

Symbol counts and codewords for the selected message
SymbolCountCode
A80
B410
C2110
D2111

First four symbols: A D A B

0111010

Gaps show boundaries for you; they are not transmitted.

28
bits for these 16 symbols
2-bit code
32 bits
This code
28 bits

Average length: 1.75 bits/symbol. Entropy of the displayed frequencies: 1.75 bits/symbol.

A short code for the common symbol saves 4 bits here: 12.5% of the fixed-length message.

Entropy sets a lower bound on the expected lossless description length for a known source. For independent, identically distributed symbols, coding long blocks can approach H bits per symbol.

That is an average limit—not a promise about every particular file. A practical compressor also has to account for its codebook, message length and other overhead.

Why can’t the “Only A” example reach zero bits?

The fixed code still writes a zero for each A. A source known to emit only A has zero entropy. If the receiver already knows the symbol and message length, no symbol content needs sending.

We deliberately keep the codebook fixed so you can see when it helps and when it wastes bits. The entropy shown uses the message frequencies; it describes a source with those probabilities, not a universal minimum for this particular string.

04 / Sending a message

Noise steals certainty.

A channel carries a signal from sender to receiver. Suppose it independently flips each bit with probability p. The receiver sees a 1—but was a 1 sent, or did a 0 get flipped?

For equally likely input bits, the input has one bit of entropy per channel use. After observing the output, H₂(p) bits of uncertainty remain. The difference is the mutual information: how much the output tells us about the input.

I(X;Y) = H(X) − H(X|Y)
C = 1 − H₂(p)X is the sent bit; Y is the received bit; H(X|Y) is the average uncertainty about X after observing Y. C is the capacity of this binary symmetric channel, in bits per channel use. Equally likely input bits achieve the maximum.
Experiment 04

A channel that sometimes lies.

Turn the flip probability all the way to 100%. Is always wrong the same as unpredictable?

10%
NeverAlways
0.531bits / channel use
0.469bits of uncertainty left
Capacity of a binary symmetric channelCapacity is one bit at zero and one hundred percent flips, and zero bits at fifty percent flips.1.000%50%100%bits / channel useFlip probability
The theoretical limit, not the error rate of the short example.
SENT / 24 UNCODED BITS
RECEIVED / DASHED = FLIPPED

The interactive example shows one short transmission. Its observed flip rate will vary.

Changing the slider reuses the same random draws, so you can compare settings. “Send another sample” draws fresh noise. No error-correcting code is applied here.

At a 10% flip rate, capacity is about 0.531 bits per channel use. Reliable communication needs coding across many channel uses.

At 50% flips, the output is independent of the input: it tells you nothing. At 100% flips, the receiver can invert every bit and recover the message perfectly—if it knows the channel rule.

Uncertainty is the problem. A predictable transformation can be undone.

Shannon’s channel coding theorem says that rates below capacity can achieve arbitrarily small error probabilities with suitable, sufficiently long codes. Capacity is a limit, not a coding recipe or a guarantee for a short message.

Why add redundancy after removing it?

Compression removes predictable repetition from the source. Error-correcting codes add structured redundancy so a receiver can distinguish plausible messages after noise.

For a simple example, transmit 0 as 000 and 1 as 111, then use majority vote. With independent 10% flips, the decoded-bit error probability becomes 3p²(1−p) + p³ = 2.8%, at a cost of three channel uses per information bit. This elementary repetition code does not reach Shannon’s limit.

05 / Where the idea travels

One language.
Several useful connections.

Bayesian inference

Bayes updates a probability distribution after evidence. Mutual information measures the expected reduction in uncertainty about an unknown quantity from an observation.

A particular observation can increase posterior entropy; the reduction is nonnegative on average.

Explore Bayesian inference →

Prediction & AI

Assign a probability q to the next observed token. Its loss is −log₂ q: low probability means a large penalty. Averaging this gives cross-entropy.

For a true distribution P and a model Q, cross-entropy is H(P) + DKL(P‖Q). DKL is KL divergence, measuring the mismatch between distributions. Good prediction does not by itself establish truth or understanding.

Thermodynamics

Gibbs entropy uses the same probability-weighted logarithmic form, multiplied by Boltzmann’s constant. For Ω equally likely microstates, S = kB ln Ω.

The physical state, constraints and units matter: thermodynamic entropy is measured in J/K; Shannon entropy here is in bits.

Explore physical entropy →

Better questions

In a noiseless guessing game, a question that splits the remaining probability roughly in half has high expected information gain.

The most informative question need not be the most useful one. Decisions also depend on consequences, cost and what you can act on.

A boundary worth remembering

More bits does not mean more meaning.

Random noise can have high entropy and little value. Information theory quantifies uncertainty and dependence; it does not certify usefulness, importance or truth.

06 / Take it with you

Four ideas to keep.

The four quantities in this lesson
QuantityThe question it answers
SurprisalHow unexpected was this outcome?
EntropyHow much surprise do I expect, on average?
Mutual informationHow much does one variable tell me about another?
CapacityWhat reliable information rate can this channel support?

If you want to check your understanding, answer these in your own words before opening the explanations. Return another day and try them without rereading.

1. Can a rare outcome be surprising even when entropy is low?

Yes. With 99% heads, a tail carries about 6.64 bits, but tails happens only 1% of the time. The weighted average is about 0.081 bits per toss.

Look for: a distinction between one outcome and the entire distribution.

2. Does 50/50 symbol frequency mean a file cannot be compressed?

No. A known alternating sequence has equal symbol frequencies but strong dependence. Knowing the initial phase and length determines the rest. Sequence structure matters.

Look for: the independence assumption, not just a frequency count.

3. Which channel is better: 50% flips or 100% flips?

The 100% channel, if its rule is known. Invert every output bit. The 50% channel carries no information about the input under the independent flip model.

Look for: predictability, rather than the raw fraction of wrong bits.

4. Why isn’t a random string automatically a good explanation?

Unpredictability can make a string costly to describe. That does not make it relevant, true or useful. Shannon information and semantic value answer different questions.

5. A link loses bits in bursts. Can you use the same capacity formula?

Not from its average error rate alone. The model here flips bits independently. Bursts introduce memory: knowing one error occurred changes what you expect next. You need a model of that dependence to calculate the actual capacity.

Look for: a failed assumption before applying a familiar formula to a new situation.

Sources & scope

Follow the ideas back.

Interactive examples illustrate standard results from the references below. Models use discrete outcomes, known probabilities and base-2 logarithms. Coin tosses and channel flips are independent unless stated otherwise. The channel’s flip probability is assumed known to the receiver.

  1. Claude Shannon · A Mathematical Theory of Communication (1948)
    The foundational treatment of entropy, coding and communication.
  2. David MacKay · Information Theory, Inference, and Learning Algorithms
    Chapters 2–5 develop probability, entropy, source coding and symbol codes; chapters 8–10 develop dependence and noisy-channel coding.
  3. MIT 6.441 · Information Theory lecture notes
    Entropy and divergence, mutual information, compression and channel capacity, with precise theorem statements.

Continue the essay series: Evolution & culture · Bayesian inference · Causality · Entropy & irreversibility.

The lesson makes no network requests and stores no answers. Once downloaded, this page’s experiments work offline. Navigation and reference links require the corresponding pages or a connection.