July 2026

Everything Is a Guess

Probability started as a gambler's trick for counting dice. It became a grammar for changing your mind, then grew a memory, and - at the very end of this article - turns out to be the same thing as compression, prediction, and the machines that now finish our sentences. This is the whole path, and every step of it is something you can play with.

Here is an uncomfortable fact: humans are catastrophically bad at probability. Not "could use a refresher" bad - wired wrong bad. Doctors, shown a patient with a positive test for a rare disease, routinely overestimate the chance the patient is sick by a factor of ten. Casinos are cathedrals built entirely on the ways our intuition fails. Lotteries are, quite literally, a tax paid by people who feel that this week it might be their turn. We are the only animal that gambles, and we are terrible at it.

What makes this strange is that the fix has existed for centuries, and it isn't hard. There is a small, sturdy body of mathematics that, once you feel it in your hands, quietly corrects almost every one of these mistakes. It tells you when to switch doors, when to ignore a scary test result, when a winning streak means nothing, and when a machine that only predicts the next word is doing something deeper than it looks.

And the origin of that mathematics is my favorite thing about it. Probability was not handed down by philosophers contemplating the nature of certainty. It was invented to settle a gambling dispute. In 1654 a French writer and professional gambler, the , noticed that a betting system that had always worked for him had quietly stopped paying. Baffled, he took the problem to Blaise Pascal. Pascal wrote to Pierre de Fermat. Over a short exchange of letters, two of the sharpest minds of the century worked out the foundations of probability theory - to figure out how to divide the stakes of an interrupted dice game. A branch of mathematics, born to resolve a bar argument.

This article walks the whole path that started with those letters. We'll go from counting the ways things can happen, to changing our minds when evidence arrives, to the handful of shapes chance keeps drawing, to what happens when chance grows a memory - and then, at the end, to the quiet reveal that the whole thing turns into information, compression, and the large language models everyone is currently arguing about. The path keeps going straight past where most probability courses stop, into the machines.

It's long - think of it as a small book, in five parts. There's some math, and none of it is required: every equation arrives only after a demo has already shown you the idea, and you can skim the symbols and lose nothing. The interactive pieces are where the understanding actually lives. Play with them. That's the whole point of doing it this way instead of just telling you.

Part 1 - Feeling Randomness

1.1 Your brain is a pattern-matcher that won't switch off

Let's start with a game instead of a definition. Below are two sequences of 100 coin flips. One of them I generated with an actual (pseudo-)random coin. The other I faked - I wrote it out the way a person does when asked to "be random," trying to make it look convincingly unpredictable. Your job is to spot the real one. Play a few rounds before you read on.

Which one is real randomness?
score 0/0

Teal is heads, taupe is tails. Click the grid you think came from actual coin flips.

If you're like most people, you learned within a few rounds to look for the boring one. The faked sequences feel too even - heads, tails, heads, tails, never settling anywhere for long. The real sequences have clumps: a run of six heads, then a run of five tails, streaks that look suspiciously like a pattern. And that instinct is exactly backwards. The streaky one is almost always the real one.

This is one of the most robust findings in the psychology of randomness. When people are asked to produce a "random" sequence, they alternate far too much - they switch symbols about 60% of the time, when true randomness switches 50% of the time - and they almost never allow a run longer than three or four. But real randomness is streaky. In 100 fair coin flips, the probability of getting a run of at least six-in-a-row is roughly 80%. A run of six isn't a sign that something is wrong. It's a sign that nothing is wrong. Its absence is the anomaly.

Don't take my word for the number - run the experiment. Below are thousands of 100-flip sequences, sorted by their longest run. The pile sits squarely on six, and most of the mass is at six or more. A long streak is the ordinary case; it's the tidy, streak-free sequence that almost never happens.

P(longest run ≥ 6)~ 80%
sequences
3,000
flips each
100
avg longest
7.0
longest run per sequenceheads or tails
0%7%13%20%27%45678910111213141516176longest run length
flips
sequences3,000

Across 3,000 sequences of 100 fair flips, the longest run clusters right around 7.0 - and a run of 6+ shows up in 80% of them. A long streak is the norm, not an anomaly. Its absence is the surprise.

The reason we get this so consistently wrong is that the human brain is a pattern-matching machine that cannot turn itself off. It is spectacularly good at finding structure - faces in clouds, meaning in noise, momentum in a coin - because for most of our evolutionary history a false alarm ("that rustle was a predator") was cheap and a missed signal was fatal. We are the descendants of the ones who saw patterns that weren't there. Randomness, which is defined by the absence of pattern, is precisely the thing this machinery cannot represent.

The most famous casualty of this is the "" in basketball. Every player, coach, and fan knows the feeling: a shooter gets hot, and each made basket seems to make the next one more likely. In 1985, Gilovich, Vallone, and Tversky analyzed the shot data and found... nothing. Makes didn't predict makes; the "hot hand" was, they argued, a cognitive illusion, our pattern-matcher imposing streaks on what was essentially independent trials. It became a textbook example of human irrationality. Case closed, for about thirty years.

Except the story has a beautiful final twist. In 2018, Joshua Miller and Adam Sanjurjo discovered a subtle statistical bias buried in the original analysis. It turns out that if you take a finite sequence of coin flips and measure "what fraction of the flips right after a heads were also heads," the answer is, counterintuitively, less than 50% on average - a selection artifact of looking only at the flips that follow a head. Correcting for it, the hot hand reappears in the data: modest, but real. So the fallacy-spotters had themselves been fooled by a probability subtlety even more delicate than the one they caught. If that doesn't make you humble about your intuition, nothing will. It's the perfect opening note for this whole article: even the experts correcting the mistake were making a subtler version of the same mistake.

That "less than 50% on average" is worth seeing for yourself, because it sounds impossible. Below we generate short fair-coin sequences and, for each, measure the fraction of the flips right after a heads that are also heads. Average that over many sequences and it settles below one half - not because the coin is biased, but because in a short sequence, looking only at the flips that follow a head quietly stacks the deck. That is the exact bug that made the hot hand look like a fallacy.

fraction of post-heads flips that are also heads (averaged per sequence)3,471 sequences counted
0.39450.1055 below the naive 0.5000
0.5
0.300.55
The gap shrinks as sequences get longer, but it never vanishes for any finite k:
0.412
k=3
0.405
k=4
0.406
k=5
0.414
k=6
0.433
k=8
0.445
k=10

Each flip really is an honest 50/50 - the coin has no memory. Yet "what usually follows a heads" comes out below 50%, a pure selection artifact of only measuring the flips that sit right after a heads in a short sequence. This is the bias that made the hot hand look like a fallacy for thirty years, when it may have been real all along.

1.2 What probability actually is: counting the ways

So what is probability, underneath? For the cases we care about here, it's almost embarrassingly concrete: list every equally-likely way the world could turn out, then count the fraction of those ways that give you the outcome you're asking about. That list of possibilities is called the , and most of elementary probability is just the art of counting it correctly.

Roll two dice. People are often surprised that 7 comes up so much more often than 2 or 12, as if the dice had a preference. They don't. It's just counting. There is exactly one way to roll a 2 (both dice show 1) and one way to roll a 12 (both show 6), but there are six different ways to roll a 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1. Out of the 36 equally-likely combinations of two dice, six of them sum to 7 and only one sums to 2. Seven is common because there are more ways to build it. That's the entire mystery. Watch it in the grid below - and roll a few thousand times to see the counts fill in exactly the shape the counting predicts.

Why 7 is the most common roll of two dice
sum 7: 6/36 = 16.7%
36 equally likely outcomes
die A
1
2
3
4
5
6
die B →
1
2
3
4
5
6
7
2
3
4
5
6
7
8
3
4
5
6
7
8
9
4
5
6
7
8
9
10
5
6
7
8
9
10
11
6
7
8
9
10
11
12
Each cell is an ordered pair (die A, die B). Hotter cells are more common sums - the diagonal of 7s is the hottest.
Ways to make each sum (out of 36)
2
3
4
5
6
7
8
9
10
11
12
theoreticalobserved
Roll the dice:0 rolls

A sum is only as likely as the number of ways to make it. Seven has six ways - 1+6, 2+5, 3+4, 4+3, 5+2, 6+1 - so it tops the chart. The extremes have just one way each: 1+1 for 2 and 6+6 for 12. Roll enough times and the observed bars settle onto exactly this shape.

This is precisely the machinery de Méré was missing, and his story is worth telling in full because it is the origin of everything that follows. De Méré had a reliable bet: wager that in four rolls of a single die, at least one six will appear. He'd made money on it for years. The math backs him up - the chance of at least one six in four rolls is 1 − (5/6)⁴ ≈ 0.518, just over even, so betting on it at even odds wins in the long run.

Emboldened, he "scaled up" the bet in a way that felt obviously equivalent: with two dice instead of one, he'd wager on at least one double-six in 24 rolls. His reasoning was a proportion. A double-six is six times rarer than a six (1 chance in 36 versus 1 in 6), so surely you need six times as many rolls: 4 × 6 = 24. It should be the same bet. But it wasn't - he kept losing. And the math shows why: the chance of at least one double-six in 24 rolls is 1 − (35/36)²⁴ ≈ 0.491, just under even. His intuitive proportion was wrong, and the gap between 0.518 and 0.491 was quietly eating his money. He could feel the loss but couldn't explain it, so he took it to Pascal.

You can watch his mistake happen. Below are the two bets he thought were equivalent: at least one six in k rolls of one die, and at least one double-six in k rolls of two dice. Slide k and watch the winning bet cross below the even-money line right where his "multiply by six" intuition (4 rolls becomes 24) said it should still be winning.

rolls (k)
4
Bet A · one six
0.518
▲ winning bet
Bet B · double-six
0.107
▼ losing bet
P(at least one hit) vs number of rolls0.5 = break-even
0.000.250.500.751.00141020243040number of rolls kk=4 · 0.518 ▲ winsk=24 · 0.491 ▼ loses
- Bet A (one six)- Bet B (double-six)
4
roll it: 20,000 seeded trials of each bet at k=4

De Mere reasoned by proportion: a double-six is 6x rarer than a six, so surely 6x the rolls - 4 becomes 24 - should hold the odds steady. But the arithmetic betrays him. His winning bet, 1 − (5/6)^4 = 0.518, sits just above even; the "scaled" bet, 1 − (35/36)^24 = 0.491, slips just below it - and he kept losing. Baffled by a gap he could feel at the table but not explain, he wrote to Pascal, who wrote to Fermat - and probability theory was born to settle a gambling dispute.

The letters between Pascal and Fermat in 1654 didn't just solve de Méré's bet. In working out a related puzzle - the , about how to fairly divide the stakes if a game is interrupted before someone wins - they invented the core ideas of probability and expected value. It is one of the great origin stories in mathematics, and it began with a gambler who trusted a proportion that didn't hold.

A couple of pieces of trivia I can't resist, because they show how long humans circled this idea before grasping it. The first actual book on probability, the Liber de Ludo Aleae ("Book on Games of Chance"), was written around 1564 - ninety years before Pascal - by , a physician and mathematician who was also a compulsive gambler. It contains the first systematic treatment of sample spaces, alongside frank advice on how to cheat. It wasn't published until 1663, 87 years after his death, which is why Pascal and Fermat usually get the credit. And if you go back further, dice themselves descend from - the knucklebones of sheep and goats - which were thrown not for money but for divination. Before probability was a tool for winning bets, its physical ancestor was a tool for asking the gods what to do. We have been rolling these things for a very long time; we only recently learned what the rolls mean.

I'll mention, and then not belabor, that all of this got a proper foundation only in 1933, when wrote down three short axioms that pin down what a probability is: probabilities are non-negative, the probability of "something happens" is 1, and the probability of any of several mutually exclusive things is the sum of their probabilities. Everything in this article is a consequence of those three lines. Probability spent three centuries as a wildly successful collection of tricks before it finally got a constitution.

1.3 The law of large numbers, and what it does not say

Everyone has heard that "it evens out in the long run." This is true, and almost everyone misunderstands what it means, in a way that costs real money. The precise statement is the , and the gap between what it actually says and what people think it says is the single most expensive misconception in probability.

Here's what it says: as you take more and more samples, the average of your results gets closer and closer to the true expected value. Flip a fair coin enough times and the proportion of heads homes in on 0.5. That part everyone gets. Here's the part almost no one gets: the law says nothing about the raw count ever balancing out. In fact, the absolute gap between the number of heads and the number of tails typically grows without bound as you keep flipping. It wanders further and further from zero. The proportion converges not because the gap shrinks, but because the gap grows more slowly than the total number of flips. It gets diluted.

Watch both quantities at once below. On the left, the proportion of heads settling toward 0.5. On the right, the absolute gap |heads − tails| - wandering off, often larger after 100,000 flips than it was after 100. Run it a few times.

flips:
Proportion of heads→ 0.5
0.000.250.500.751.001101001k
number of flips (log scale)
Absolute gap |heads − tails|wanders
025501101001k
number of flips (log scale)

After 1,000 flips, proportion = 0.495 (only 0.005 from 0.5) and gap = 10 (10 more heads-or-tails than the other, and it never closed back to zero).

convergence by dilution, not correction

gap = 10 (large, and never closed) - but gap / 2n = 10 / 2,000 = 0.0050 (tiny) - which is exactly why the proportion is 0.495, not 0.5.

The proportion converges. The gap does not. The law of large numbers dilutes early luck; it never reverses it.

Sit with that split for a moment, because it dismantles the gambler's fallacy completely. The gambler's fallacy is the belief that after a run of reds at the roulette wheel, black is "due" - that the universe keeps a ledger and will correct an imbalance. It does not. The coin has no memory. It does not know it has landed heads eight times; it will not tilt toward tails to compensate. The proportion evens out not because past results get cancelled, but because they get drowned by the sheer volume of future results that don't care about them. Convergence by dilution, not by correction. The coin doesn't owe you anything.

The most vivid demonstration of this ever recorded happened at the on August 18, 1913. At one roulette table, the ball landed on black an extraordinary number of times in a row - the run reached twenty-six. As the streak lengthened, gamblers crowded the table betting ever-larger sums on red, certain that after so many blacks a red was overwhelmingly overdue. It wasn't; each spin was independent, still a hair under even odds. The house took millions of francs from people who believed the wheel owed them a correction. The gambler's fallacy is sometimes still called the "Monte Carlo fallacy" because of that night.

You don't have to travel to Monte Carlo to feel the pull. Watch a streak build below, bet on whichever color feels "due," and watch a fair game politely refuse to reward you for it - because the coin has no memory of the streak that just terrified everyone at the table.

The coin is fair and has no memory. After any streak, the next flip is still a 50/50 toss.
recent flips
teal has come up 5 times in a row.
It feels like amber must be due. But P(next is amber | 5 teal) = 50%. The coin owes you nothing.
Stake $10 on the next flip:
bankroll
$100
your win rate
0/0

Monte Carlo Casino, 18 August 1913: black came up on the roulette wheel 26 times in a row. Convinced red was overdue, gamblers piled money on it and lost millions - the wheel, like this coin, had no memory of the streak at all.

A small historical note that says a lot about how hard-won this idea was: the first rigorous proof of the law of large numbers is due to , in his . He proved it, and then sat on it, refining it, for twenty years. It was published in 1713, after his death. Even the man who proved that the long run behaves itself found the result subtle enough to worry over for two decades.

1.4 The birthday paradox: combinatorial explosion in a party hat

One more piece of counting before we let probability start to change its mind, because it's the cleanest demonstration that your intuition and the actual arithmetic can point in wildly different directions. How many people need to be in a room before it's more likely than not that two of them share a birthday?

Most people guess something around 180 - half of 365, which feels right. The actual answer is 23. With just 23 people, the odds are already better than even. With 70, it's a virtual certainty - 99.9%. This feels impossible the first time you hear it, so let's build the room one person at a time and watch the collisions appear.

people
23
pairs
253
P(any 2 match)
50.7%
this room
Jun 28
the roomone random sample
1 colliding pair
the theoryP vs n
0%50%100%12370n=23 · 50.7%n=70 · 99.9%
curve = the whole ensemble, not one room
23
same n, a fresh set of birthdays:
stop trusting the curve - sample it:

With 23 people there are 253 distinct pairs, and every pair is a fresh chance to collide. That's why the odds climb so fast: add one person and you add a whole new column of pairings. You track people - probability tracks pairs, and pairs grow quadratically. The very same math is why cryptographic hash collisions are easier to find than they look (the "birthday attack").

The trick to un-paradoxing it is to notice what question you're actually asking. Your intuition hears "share a birthday" and quietly rewrites it as "share my birthday" - and that version really is rare; you'd need around 253 people for a coin-flip's chance that someone matches you specifically. But the room isn't asking about you. It's asking whether any two people match, and the number of possible pairs grows much faster than the number of people. Two people make one pair. Ten people make 45 pairs. And 23 people make 23 × 22 / 2 = 253 pairs - 253 separate chances for a collision. Suddenly 50% looks obvious.

This is , and it is one of the most important intuitions in all of applied probability: pairs (and triples, and larger combinations) grow quadratically or worse while the things being paired grow only linearly. Your brain counts people. Probability counts pairs. Whenever those two counts diverge, your intuition loses.

It's also not a party trick. This exact math is why cryptographic systems worry about "": to find a collision in a hash function - any two inputs that produce the same output - you don't need to try anywhere near as many inputs as the size of the output space, only roughly its square root, because you're checking all the pairs at once. It's why a hash that looks 128 bits strong offers only about 64 bits of collision resistance. If you read the Merkle trees piece, this is the quiet threat sitting underneath every hash in it. The birthday paradox is a party game and a cryptographic constraint, and they are the same arithmetic wearing two different outfits.

Notice something about everything in Part 1: the probabilities never changed. The dice don't care what you know; a 7 has six ways to happen whether you're paying attention or not. Every number we've counted was fixed, a property of the setup itself. But most of the questions you actually care about aren't like that. What's the probability your cough is something serious? That this email is spam? That the defendant is guilty? Those aren't fixed. They change the instant you learn something new - a fever, a suspicious word, an alibi. Probability, it turns out, has an update button. Learning to press it correctly is the subject of Part 2, and it is where this whole story stops being about gambling and starts being about thinking.

Part 2 - Changing Your Mind

Everything in Part 1 was static. Now we give probability the one power that turns it from a gambler's curiosity into a way of thinking: the ability to update. This is the emotional center of the whole article. It's where probability stops being about dice and starts being about evidence - about medical tests, spam, courtrooms, and the ordinary business of being less wrong tomorrow than you were today.

2.1 Shrinking the universe

sounds technical and is actually a single physical gesture: you delete the part of the world you now know is impossible, and re-weigh what's left. Before you learn anything, the sample space is the full list of ways things could be. Then you learn a fact - "the card is a face card," "the patient has a fever" - and a whole region of that list is now ruled out. Conditional probability is just probability computed inside the surviving region, rescaled so it adds back up to one. That's all the notation P(A | B) - "the probability of A given B" - is bookkeeping for: shrink the universe to B, then ask about A.

Try the gesture on a deck of cards before we make it hard. Pick something you now "know" about a drawn card - it's a face card, say - and every card that doesn't fit dims out of existence. The probability of anything else is now computed inside what's left, rescaled so it adds back to one. That, and nothing more, is conditioning.

Conditioning: shrink the universe, then ask
surviving 13/52
CONDITION B (what you now know)
EVENT A (what you're asking about)
A
2
3
4
5
6
7
8
9
10
J
Q
K
A
2
3
4
5
6
7
8
9
10
J
Q
K
A
2
3
4
5
6
7
8
9
10
J
Q
K
A
2
3
4
5
6
7
8
9
10
J
Q
K
survives Balso satisfies Aimpossible under B
Unconditional
P(A) = 4 / 52 = 7.7%
over the whole deck
Conditional on B
P(A | B) = 1 / 13 = 7.7%
denominator shrank 52 13

P(A | B) is just probability computed inside the surviving region. You delete every card that B rules out - they are now impossible - then keep only the A-cards among what remains and rescale so the survivors sum to 1 again. That is the whole move: shrink the universe, then ask. Every Bayes update that follows is a version of this one gesture.

This sounds harmless. It is not. Get the shrinking wrong - condition on the wrong thing, forget that someone's choice leaked information - and you will confidently reach exactly the wrong answer. The most famous demonstration of this in all of mathematics is a . Play it before you read another word of explanation.

Three doors. A car behind one, goats behind the other two. You pick a door. The host - who knows where the car is - opens one of the other two doors, always revealing a goat, and offers you the chance to switch to the remaining closed door. Should you stay, or switch? Play enough rounds by hand to form an opinion, then hit auto-play and watch a thousand rounds settle the argument.

Pick a door. The host opens a goat. Do you stay or switch?
Click a door to begin.
When you stayed
0/0 = -
When you switched
0/0 = -

Switching wins two-thirds of the time. Staying wins one-third. If you're feeling the same indignation almost everyone feels - surely it's 50/50 once there are two doors left - hold that feeling, because you are in extraordinary company, and then let me shrink the universe correctly for you.

The key is that the host's reveal is not random. When you first pick, you have a 1/3 chance of having found the car and a 2/3 chance of having pointed at a goat. That 2/3 doesn't evaporate when a door opens. The host is constrained: he must open a goat door, and he must avoid your door. When your original pick is wrong - which is 2/3 of the time - the host has only one legal door to open, and by opening it he is practically pointing at the car with the door he leaves closed. His knowledge leaks through the choice he's forced to make. Switching converts your original 2/3 chance of being wrong into a 2/3 chance of being right. You aren't choosing between two doors; you're choosing between your first guess and everything else, and the host has helpfully cleared the junk out of "everything else."

If it still feels wrong, crank the door count up in the demo. Imagine a hundred doors. You pick one - a 1% shot. The host, who knows, then opens ninety-eight other doors, every one a goat, leaving your door and one other. Now the question answers itself: your door is the 1% you guessed blind; the other door is the survivor of a 99%-of-the-probability gauntlet the host ran on your behalf. Of course you switch. Three doors is the same situation with the drama turned down.

The reason this problem is legendary isn't the math - it's the reaction to the math. When published the correct answer in her Parade column in 1990, she received something like ten thousand letters telling her she was wrong, roughly a thousand of them from people with PhDs. Mathematics professors wrote in to lecture her. , one of the most prolific mathematicians who ever lived, reportedly refused to accept it until a colleague showed him a computer simulation running the rounds. Sit with that: some of the finest mathematical minds on the planet could not reason their way to the answer, and were only convinced by watching the trials pile up - which is exactly what you just did. That's the entire thesis of this article, delivered by history: your intuition is not enough, and the cure is to run the experiment.

2.2 The test came back positive. Should you panic?

Here is the single most consequential place where bad probability intuition does real damage, and it happens in doctors' offices every day. Suppose there's a disease that affects 1 in 100 people. There's a test for it that's 90% (it catches 90% of real cases) and about 91% (it correctly clears 91% of healthy people). You take the test. It comes back positive. What's the chance you actually have the disease?

Most people - and, famously, most doctors - answer something like "around 90%." The real answer is about 9%. Not 90. Nine. Play with the population below and watch why: color in ten thousand people, mark the sick ones and the ones who test positive, and count.

sick + positive 90healthy + positive 891sick, missed 10healthy + negative 9009
outline = everyone who tests positive (accent + teal)
P(sick | positive)
9.2%

Of the 981 people who test positive, only 90 are actually sick - the other 891 are false alarms.

true positives
90
false positives
891
sick, total
100
healthy, total
9,900
1.0%
90.0%
91.0%
Try a scenario:

This is base-rate neglect: we anchor on the test's accuracy and forget how rare the disease is. When Gigerenzer posed this exact problem to practicing physicians, most estimated the chance of illness at 80-90% - off by nearly an order of magnitude. Counting whole people ("9 of 109") instead of juggling percentages makes the right answer almost obvious.

The reason is the base rate. Out of 10,000 people, only 100 have the disease (that's the 1%). The test finds 90 of them - the true positives. But look at the other 9,900 healthy people: a test that's 91% specific still wrongly flags 9% of them, and 9% of 9,900 is about 891 false positives. So a positive result puts you in a pool of roughly 90 + 891 ≈ 981 people, and only 90 of them are sick. 90 out of 981 is about 9%. The test isn't bad. It's just that when the disease is rare, the enormous healthy majority generates a flood of false alarms that drowns the true cases. Ignoring the base rate - the 1% - is called base-rate neglect, and it is astonishingly common.

The psychologist has spent a career documenting how badly trained physicians handle exactly this calculation, and - more usefully - how to fix it. His finding is wonderful: the fix isn't more statistical training, it's changing the units. Tell a doctor "90% sensitivity, 9% false positive rate, 1% prevalence" and they flounder. Tell them "90 out of every 100 sick people test positive, and 891 out of the healthy ones also test positive, so out of about 981 positive tests only 90 are sick" and they get it instantly. Our brains did not evolve to juggle percentages and conditional probabilities. They evolved to count things. Natural frequencies - "9 out of 109" instead of "8.3%" - turn an impossible problem into an easy one, because they quietly carry the base rate along for free.

Here is that representation as a picture: split a thousand people by whether they're sick, then split each group by how the test treats them. Everything stays whole people, and the answer - of everyone who tests positive, how many are actually sick - is just counting the highlighted leaves.

1%99%90%10%9%91%people1,000sick10healthy990test + (sick)9test - (missed)1test + (false)89test - (clear)901
true positives 9false positives 89
Of everyone who tests positive, how many are actually sick?

Of the 98 people who test positive, only 9 are actually sick - the other 89 are false alarms.

9.2%= 9 / 98 actually sick
Population (N)
1.0%
90.0%
91.0%

Our brains evolved to count things, not to juggle conditional percentages. "9 out of 98" is easy where "9.2%" is nearly impossible to feel. This is the representation Gigerenzer's research recommends - and it is base-rate neglect's cure: keep the whole population in view and the rare disease can never hide behind the test's accuracy.

Now, and only now that the demo has already shown you the answer, here is the equation that names what you just did. It's called , and every panic-inducing positive test result is one application of it:

P(sick | positive) = P(positive | sick) · P(sick) / P(positive)

Read it as bookkeeping: the chance you're sick given a positive test equals how often sick people test positive, scaled by how common the disease is to begin with, divided by how often anyone tests positive at all. That last term in the denominator is the whole story - it includes all those false positives. Drop the base rate P(sick) and you get 90%; keep it and you get 9%. The base rate is not a detail. It is frequently the entire answer.

There's an even more intuitive way to write Bayes, and it's the one I want you to actually keep, because it turns updating into multiplication. Work in instead of probabilities:

posterior odds = prior odds × likelihood ratio

Your odds of being sick were 1 to 99. The test has a "strength" - a - of how much more often it fires for the sick than the healthy: 90% versus 9%, a ratio of 10. Multiply: 1-to-99 becomes 10-to-99, which is about 9%. That's the whole update in one multiplication. Evidence has a strength, and you multiply it in. Hold on to that phrasing, because in the next section a codebreaker is going to build a war-winning machine out of nothing but adding up the logarithms of those strengths.

If the equations still feel like notation, here they are as an area. The width of the box is the prior - how common the disease is; each column is split by how the test behaves; and the is simply the accent slice as a fraction of the whole highlighted, test-positive region. Drag the prior narrow and watch the answer collapse - the base rate isn't a detail, it's the width of the box.

FPTN
← P(sick) = 1.0%P(healthy) = 99.0%
true positivefalse positivetests negative
P(sick | test +)
9.2%
posterior =0.00900.0090 + 0.0891

accent area (true positives) divided by every highlighted region (all positive tests).

TP area
0.0090
FP area
0.0891
sensitivity
90.0%
specificity
91.0%
1.0%
90.0%
91.0%
Try a scenario:

Drag prevalence toward zero and watch the accent sliver shrink: the true-positive area collapses even though the test never got less accurate. The base rate is the width of the left column - and frequently it IS the whole answer.

2.3 The reverend, the marquis, and the codebreaker

The theorem is named for the , a Presbyterian minister and amateur mathematician who, fittingly for a man who taught the world how to update on evidence, never got around to publishing his idea while alive. He worked it out sometime in the 1740s as a solution to a philosophical puzzle - if you've seen the sun rise every day of your life, how confident should you be it rises tomorrow? - and then left it in a drawer. After he died in 1761, his friend found the essay among his papers, recognized what it was, and read it to the Royal Society in 1763. Price did enough work preparing and extending it that he arguably deserves co-credit; he almost never gets it. Bayes' theorem is, in a small way, itself a lesson in how evidence gets lost and recovered.

The person who actually turned it into a working science was , the "marquis" of this section's title, working independently across the Channel a few decades later. Where Bayes had a fragile special case, Laplace built the general engine and immediately pointed it at the sky. He used it to estimate the masses of Saturn and Jupiter from noisy astronomical data, and - this is the part I love - he didn't just give an answer, he gave a bet. Laplace declared it was "a bet of 11,000 to 1" that his estimate of Saturn's mass was within 1% of the truth. Two centuries of better measurements have proven him right. He was quantifying his own uncertainty and staking odds on it, which is the most Bayesian thing a person can do.

Then the theorem went to war. At during the Second World War, Alan Turing needed to break the German naval Enigma, and the search space was astronomically large. His method, which he called , was Bayes in disguise. Each tiny scrap of evidence about the Enigma's settings - a guessed letter, a repeated pattern - was worth a certain weight, and Turing measured that weight in a unit he invented called the ban (named after Banbury, the town where the paper sheets were printed), with tenths of a ban called decibans. The trick: because Bayesian updates multiply, taking logarithms turns them into something you can add. Codebreakers could literally accumulate evidence by adding up decibans on strips of paper until the total crossed a threshold and a hypothesis became near-certain. That's the odds form of Bayes from the last section - evidence as a strength you multiply in - converted into decibels so a room full of people could do it by hand, at speed, under wartime pressure. It is one of the most beautiful applications of probability I know, and it helped shorten the war.

Bayes also finds lost things. works by spreading a probability distribution over a map - where might the object be? - and then updating it after every search that comes up empty, because a failed search is itself evidence: it lowers the probability where you looked and raises it everywhere else. In 1968 the US submarine Scorpion was lost in the Atlantic; a team led by John Craven built a probability map from expert guesses about its final maneuvers and directed the search to the highest-probability cells, finding the wreck within a couple hundred meters of the peak. The same method found the flight recorders of in 2011, two years after the crash, after conventional search had failed - a fresh Bayesian analysis pointed at a patch of seafloor everyone had previously written off, and the wreckage was there. A search that finds nothing is not a wasted search. It is an update.

I should be honest that Bayes was not always respected. For much of the twentieth century there was a real and often bitter feud between Bayesians, who treat probability as a degree of belief you update, and frequentists, who insist probability is only the long-run frequency of repeatable events and that putting a "prior" on a hypothesis is unscientific hand-waving. The great statistician was openly contemptuous of Bayesian reasoning, and his influence pushed it to the margins of respectable statistics for decades. What rescued it was, of all things, computers: many Bayesian calculations are intractable by hand but easy to approximate by simulation, and once machines could grind through them, the approach came roaring back. Today it quietly underwrites huge swaths of machine learning. The reverend's drawer-bound idea won.

2.4 Build a spam filter in your head

Let's make all of this concrete with the most successful consumer application Bayes ever had: the thing that saved your inbox. Early spam filters worked by accumulating exactly the kind of evidence Turing did. Each word in an email is a scrap of evidence - "viagra" pulls hard toward spam, "meeting" pulls toward legitimate mail - and each has a likelihood ratio, a strength. The filter starts with a prior and multiplies in every word's strength, or equivalently, adds up every word's decibans, until the total tips one way. Type a message below and watch the tug-of-war, word by word.

A naive-Bayes spam filter, thinking out loud.
SPAM · 10
  • congratulations you are a winner claim your free prize now
  • click here to get cheap viagra pills online
  • urgent your account needs verification click this link
  • you have won free cash click to claim the prize
  • limited offer buy now and get free money fast
  • act now to receive your free gift card winner
  • cheap loans available click here for instant cash
  • hot singles waiting click this link right now
  • final notice claim your unclaimed prize money today
  • free trial no credit card click to win big
HAM · 10
  • can we move our meeting to three tomorrow afternoon
  • thanks for sending the report i will review it tonight
  • are you free for lunch on friday near the office
  • the build passed but one test is still flaky
  • mom called she wants to know about the weekend plans
  • please find the updated slides attached for review
  • let me know if the deployment finished successfully
  • i left the keys with the neighbor as we discussed
  • great work on the presentation everyone was impressed
  • reminder the invoice is due at the end of the month
← hameach word pullsspam →
congratulations
+0.67
winner
+1.08
click
+1.92
here
+1.08
claim
+1.37
your
+1.59
free
+1.08
cash
+1.08
prize
+1.37
now
+1.59
prior log-odds 0.00 (10:10 base rate)
running log-odds +12.81
SPAM
P(spam) = 100.0%
Teach it a new example, then watch a word flip:

Each bar is one word's log P(word|spam) − log P(word|ham) - a signed weight for the evidence it carries. Turing called these units decibans: measure belief in logs and evidence simply adds up. "Naive" Bayes assumes the words are independent - plainly false, since real language clumps - yet summing the weights still sorts the mail remarkably well.

That's it. That's a working spam filter, and it's just the odds form of Bayes applied one word at a time. It was popularized by Paul Graham's 2002 essay "A Plan for Spam," and for a few years these filters worked so well that they nearly ended the spam problem, until spammers adapted. But notice the assumption hiding inside it, the one that makes the arithmetic tractable: the filter treats every word as independent evidence, as if seeing "free" told you nothing about whether "money" is coming next. That is obviously false - language is dripping with correlations. This is why the technique is officially called : the "naive" is an admission that the independence assumption is a lie.

And here is the first genuinely important lesson of applied probability, the one you'll meet again and again all the way to the end of this article: the model is wrong and it works anyway. The words aren't independent, the assumption is false, and the filter is still good enough to clean your inbox. The statistician George Box put it best - "all models are wrong, but some are useful." A model doesn't have to be true. It has to be useful. Keep that in your pocket; it's going to matter enormously when we get to machines that model all of human language with assumptions that are, in their own way, just as brazen.

One last demo for this part, and it's a quiet bridge to the next. So far we've treated a belief as a single number - "9% chance you're sick." But a good Bayesian doesn't hold a number; they hold a whole shape. Here's a coin of unknown, possibly rigged, bias. You don't know its true weighting. Start flipping, and watch your belief about the bias update - not as a moving number, but as a curve that starts flat (you know nothing) and, flip by flip, gathers itself into a sharp spike over the true value.

Your belief about the coin, as a shape
0 flips
00.51the coin's bias = P(heads)
meantrue bias
heads
0
tails
0
mean
0.500
95% interval
0.02-0.97
0.70

Belief is a distribution - it gets narrower and taller as evidence arrives, homing in on the coin's true bias.

Every flip reshapes the curve. Early on it's a broad, humble mound: the coin could be almost anything. As evidence piles up, the curve narrows and grows tall, concentrating over the truth, encoding not just your best guess but how sure you are. This is Bayesian updating in its most honest form, and the width of that curve is your uncertainty made visible.

But look at what just happened on that screen. To describe a belief, we stopped using a number and started using a shape - a distribution. And that turns out to be the secret the rest of probability has been keeping. Chance doesn't just produce single outcomes; it produces shapes, and startlingly few of them. The same handful of curves show up everywhere - in heights and errors and dice sums and radioactive decay - as if the universe had only a few favorite doodles it draws over and over. Part 3 is about those shapes: where they come from, why they're so few, and why one of them is so common it got named "normal."

Part 3 - The Shapes of Chance

This is the part of every probability book where it turns into a catalogue - a grim march through named distributions, each with its formula and its moments, memorized and forgotten. We're not doing that. There are only four shapes in this whole section, and every one of them arrives through a story or a paradox, not a definition. The goal isn't to make you recognize distributions. It's to make you feel why chance keeps drawing the same few of them, as though the universe were working from a very short sketchbook.

3.1 What's it worth? Expectation as the fair price

Before shapes, we need one number that summarizes a gamble: its . Informally it's the average outcome if you played forever - multiply each payoff by its probability and add them up. But I want you to notice that expectation wasn't invented as an average. It was invented as a notion of fairness. Remember the Problem of Points that Pascal and Fermat solved back in the intro - how to split the pot of a game abandoned midway? Their answer was: give each player the share equal to their expected winnings if play had continued. Expected value entered the world as the fair division of a stake, and only later became "the mean." Fairness first, arithmetic second.

Here's where it gets practical, and a little cruel. Below are three casino tables. Each has some payout structure, and their expected values are hidden. You have a bankroll. Play the tables, form a hunch about which one loves you, and only then reveal the math.

Your bankroll
1000credits
bet10
Even CoinEV ?

Coin flip. win: +0.95× your stake · lose: −1× your stake.

swing±0.97× stake · low
0 · 0 rounds
JackpotEV ?

3% shot at +30× your stake · otherwise −1× your stake.

swing±5.29× stake · high
0 · 0 rounds
The Quiet TableEV ?

Coin flip. win: +1.10× your stake · lose: −1× your stake.

swing±1.05× stake · low
0 · 0 rounds
0 rounds played · net 0

The boring table is the only winner. Notice how Jackpot's rare 30× hits feel like the game is beatable - but auto-play a thousand rounds and your average drifts to its true hidden EV. Variance is what you feel round to round; EV is what the house feels over millions of rounds. Casinos aren't gambling - they're running the law of large numbers as a business model. Insurance is the exact same trick, sold to you as safety instead of a game.

The lesson is in the gap between what you felt and what the reveal showed. The flashy table - rare, thrilling jackpots - feels the most winnable and quietly has the worst expected value. The boring table, the one where nothing exciting ever happens, is the only long-term winner. Your experience at a table is dominated by , the swings; the casino's experience is dominated by expected value, the drift. And the two of you are having completely different relationships with the same game.

This is the insight into why casinos always win, and it isn't cheating. A casino is not gambling. A gambler at a table might be up or down on any given night - that's variance. But the casino plays every table, every hand, every spin, millions of times a month, and across that volume the variance washes out and only the expected value remains. The casino is not betting against you; it is running the law of large numbers as a business model. Its "edge" is a small negative expected value on each of your bets, applied so many times that the outcome is a near-deterministic river of profit. Insurance, by the way, is the exact same machine wearing a more respectable suit - a pile of small, negatively-expected bets (your premiums) that, in aggregate, reliably fund the rare large payouts and a margin besides.

3.2 When expectation breaks: the

Expected value is so useful that it's tempting to treat it as the answer to "what should I do?" But there's a famous game that breaks it in half. Here are the rules: I flip a fair coin repeatedly. The pot starts at $2 and doubles on every heads. The first time tails comes up, the game ends and you take the pot. So if tails comes up immediately you win $2; one heads then tails, $4; two heads, $8; and so on. How much should you be willing to pay for a single ticket to this game?

Compute the expected value and you get a shock. There's a 1/2 chance of winning $2, a 1/4 chance of $4, a 1/8 chance of $8 - and each of those terms contributes exactly $1 to the expectation. There are infinitely many terms. The expected payout is infinite. By the logic of expected value, you should hand over your house, your car, and your children for one play. Obviously you shouldn't. Almost nobody would pay even $20. Play it below a few thousand times and watch why.

simulate:

Pot starts at $2. Every heads doubles it; the first tails ends the game and you collect. Hit Play once to see a single game play out.

Running average payout
never settles - it climbs
Play some games to plot the running average.
games played (log scale)
games
0
running avg
-
biggest win
-
$10 / game
Play some games, then see whether this price would have paid off.
How often each payoff landed

Half of all games pay just $2, a quarter pay $4, an eighth pay $8… Small payoffs dominate. Play to see it.

The expected value is infinite - Σ 2ᵏ·(½)ᵏ = Σ 1 = ∞ - yet the running average never converges: it drifts upward, jerking each time a freak streak lands a giant pot, so "expected value" gives no sensible price. Two escapes: Bernoulli's diminishing marginal utility - we value the log of money, and the log-EV is finite; and the practical one - you can't ride out the long run if you go bankrupt first.

The running average payout never settles down. It creeps upward in lurching steps and refuses to converge, because every so often a freakishly long run of heads delivers a payout so enormous it single-handedly drags the average up - and then it drifts while the next such run builds. The expected value is "infinite" only in the sense that the rare colossal wins never stop being large enough to matter, no matter how far out you go. But you don't live in the infinite average. You live in the actual games, and half of them pay $2.

There are two resolutions, and both are important. The first came from in 1738, right there in St. Petersburg, and it's the birth of a huge idea: . A second dollar means less to a rich person than a first dollar means to a starving one - money has diminishing marginal utility. Bernoulli proposed that people don't maximize expected money, they maximize expected usefulness of money, which grows roughly like the logarithm of wealth. Under log utility, those astronomical payouts get logarithmically deflated, the sum converges, and a sane ticket price falls out. This one move - value is not linear in money - later became a cornerstone of all of economics.

The second resolution is blunter and more modern: you can't play the long run if you go bankrupt first. An infinite expected value assumes infinitely many plays and an infinitely deep pocket, and neither exists. In the real world your bankroll is finite, ruin is permanent, and a strategy's average outcome is a dangerous thing to optimize if the variance can wipe you out before the average arrives.

Which raises a genuinely practical question that the St. Petersburg game only hints at: if you do have a favorable bet, how much of your money should you put on it? Bet too little and you barely grow; bet too much and variance ruins you even though the bet is in your favor. The answer is a beautiful formula called the , and you can feel it below - slide the bet fraction and watch twenty parallel fortunes rise or self-destruct.

f* = 20% (p − q)
20 bankroll paths · 200 bets · p = 0.6median wealth
1e-21e-11101001,0001e4050100150200
bet number · bankroll on log scale (start = 1)
Long-run growth rate g(f)g(20%) = 0.0201/bet
00.020%20%40%60%80%100%f* = 20%g = 0 at 39%
bet fraction f · expected log-growth per bet (peaks at Kelly)
Median terminal bankroll
189.33×
Unlucky · ended below start
5%

Every bet here is favorable - p = 0.6 at even money. Yet betting more than f* = 20% drags the median wealth down and drives more paths to ruin; at f = 100% a single loss wipes you out. Overbetting a winning game still ruins you. Kelly bets exactly enough to maximize long-run growth - no more.

Notice the cliff. There's a fraction - for this bet, 20% - that maximizes long-run growth. Bet less and you leave money on the table; bet more and your growth rate actually drops, because the losses compound against you; bet near everything and you are almost certain to be wiped out despite having a genuine edge on every single wager. Ruin isn't caused by making bad bets. It's caused by making good bets too big. The formula was derived in 1956 by John Kelly, a physicist at Bell Labs, in the office next to Claude Shannon - hold that name, because Shannon is going to walk back into this story at the very end and change everything. then took Kelly's criterion, and a hidden wearable computer he built with Shannon, into actual casinos to beat roulette and blackjack. The math on this page has been to Vegas, and it won.

3.3 The universe's favorite doodle: from coin flips to the bell curve

Now, finally, the shapes. Start with the simplest interesting one. Flip a coin a fixed number of times and count the heads - that count is a random variable. Zero heads is possible but needs every flip to cooperate, so it's rare; the same for all-heads; and the middle counts are common because there are so many different ways to arrange them (this is the dice-sum counting from Part 1, grown up). Plot how often each count occurs and you get a humped, symmetric shape. Now here's the machine that makes it physical: drop balls through a lattice of pegs, each peg a 50/50 coin flip left or right, and let them pile up.

0 balls
12 rows · 13 bins

Each ball bounces left or right with equal odds at every peg, so its final bin is simply the number of right-bounces - a Binomial(12, ½) draw. No single ball is predictable, yet pile up enough and the bins settle into the same smooth bell curve every time: N(12/2, √12/2). Galton called it "the supreme law of Unreason" - order emerging, reliably, out of pure chance.

Every ball's final bin is just its number of right-bounces - a binomial count - and as the balls accumulate, that humped silhouette emerges out of pure chance, the same bell every time. This is the Galton board, built by Francis Galton in the 1870s, who was so moved by it he wrote one of the great purple passages in statistics:

"The supreme law of Unreason. Whenever a large sample of chaotic elements are taken in hand... an unsuspected and most beautiful form of regularity proves to have been latent all along."- Francis Galton, Natural Inheritance (1889)

That regularity is the normal distribution - the bell curve - and it is the closest thing probability has to a mascot.

Before we ask why this shape is everywhere, meet the one number that describes it. A bell has a center (the mean) and a width - and that width has a name: the standard deviation, written σ. It is the natural ruler of chance. About two-thirds of everything lands within one σ of the mean, about 95% within two, and virtually all of it within three - the famous "68-95-99.7" rule. It's worth feeling σ in your hands, because every bell in the rest of this article is measured in it.

A real distribution:
68%95%99.7%55-3σ70-2σ85-1σ115+1σ130+2σ145+3σ100μ
100 points
15 points
The 68 - 95 - 99.7 rule, in points
68%fall within ±1σ of the mean =[85, 115] points15)
95%fall within ±2σ of the mean =[70, 130] points30)
99.7%fall within ±3σ of the mean =[55, 145] points45)

About 95% of people are within 30 points of average - between 70 and 130 points.

Sigma (σ) is the width of chance - the natural scale of a bell. Drag it and the curve stretches or pinches while its area stays fixed; the mean only slides it sideways. Read the shaded bands as a near-universal habit of normal data: about 2/3 of everything lands within one sigma of the mean, ~19/20 within two, and virtually all of it within three. That is the vocabulary the rest of this section speaks - Galton's board fills out this same bell, and the central limit theorem shrinks its width as σ/√n.

But why this shape, and why is it everywhere - in heights, in measurement errors, in test scores, in the noise on a wire? The answer is one of the most remarkable facts in all of mathematics, the , and I'd rather you insult it personally than have me state it. In the demo below, draw any distribution you like - make it lumpy, lopsided, spiky, two-humped, as far from a bell as you can manage. Then we'll repeatedly take samples from your monster and plot the distribution of their averages.

your distribution
μ 0.500 · σ 0.265
Drag across the canvas to paint your own shape.
distribution of the sample mean
σ/√n 0.265
sample means (n = 1)N(μ, σ/√n)
1
presets:

The means re-sample on their own when you paint or change n. Reshuffle just rolls a new random batch from the same setup - the bars wobble, the bell holds.

Set n = 1 and the right panel is just a noisy copy of whatever you drew. Push n up and - no matter how lumpy, bimodal, or spiky the parent - the averages collapse into a normal bell curve, narrowing by exactly σ/√n. That universality is why the bell curve is everywhere: heights, measurement errors, background noise - each is a sum of many small independent effects.

Fine print: the CLT needs the draws to be independent and the parent to have finite variance. Fat-tailed distributions can break it - finance learned this the hard way when "impossible" market moves kept happening.

It doesn't matter what you drew. Take samples of it, average them, and the averages pile up into a bell. The weirder your distribution, the more it feels like a personal affront - you deliberately built a two-humped camel and its sample-means are a smooth, symmetric bell anyway. That is the Central Limit Theorem: sums and averages of many independent random pieces converge to a normal distribution almost regardless of what the individual pieces look like. And now the ubiquity makes sense. A person's height is the sum of thousands of small genetic and environmental nudges; a measurement error is the sum of many tiny independent errors; the bell curve is everywhere because adding up lots of little independent things is everywhere. It's not that nature loves the normal distribution. It's that the normal distribution is what you get when many small causes add together, and that describes an enormous fraction of the world.

One honest piece of fine print, because it will matter enormously someday and people forget it: the Central Limit Theorem has conditions. The pieces must be roughly independent, and - crucially - they must have finite variance. Some distributions have tails so fat that this fails; averages of them do not settle into a bell, and rare enormous events keep dominating. Financial returns are the notorious example. A generation of risk models assumed a comfortable bell curve, and the fat tails they ignored showed up in 2008 as events their own models rated as impossible several times in a week. The bell curve is a gift, but it comes with terms and conditions.

3.4 The law of rare events

One more shape, for a different kind of situation: not "how many heads in a fixed number of flips," but "how many rare events happen in a stretch of time or space when each opportunity is tiny and there are enormous numbers of them." Typos on a page. Meteors in an hour. Customers arriving at a counter. Radioactive decays in a second. The distribution of those counts is the , and it has the nicest origin story of any of them.

In 1898 the Russian-German statistician went looking for a dataset of genuinely rare, independent events and found a magnificently grim one: the number of Prussian cavalry soldiers killed by being kicked by their own horses. The classic tabulation covers 10 army corps over 20 years - 200 corps-years, 122 deaths in all - and the deaths-per-corps-per-year followed the Poisson distribution almost perfectly, with a mean of about 0.61. Scatter rare events at random over many opportunities and this is the exact shape you get. Watch it assemble below, then flip on the horse-kick data and see von Bortkiewicz's numbers fall onto the curve.

λ (mean/cell)
1.00
raindrops
144
cells
144
busiest cell
4 hits
the fieldone scatter
darker = more hits · empty = a lucky cell
hits per cellvs Poisson(1.00)
01020304050600123456
observed (bars)Poisson pmf (curve)
1.0
144 drops · λ = 1.0

Rare, independent events scattered over many opportunities pile up as Poisson(λ). Typos per page, meteor strikes, goals per match - and V-2 rockets on London: Clarke's 1946 study showed the bombs weren't targeting neighborhoods at all; randomness just clusters. Some cells get hit two or three times while others stay empty - that isn't a pattern, it's what pure chance looks like. Clustering is expected, not sinister.

The deep lesson of the Poisson distribution is emotional as much as mathematical: randomness clusters, and the clustering is not a signal. When rare events scatter at random, they don't spread out evenly - they bunch, leaving some cells empty and some with several. During the Blitz, Londoners were convinced the V-2 rockets were targeting particular neighborhoods, because the hits came in clusters. In 1946 R. D. Clarke took the map of where the rockets fell, divided South London into a grid, and found the hits-per-square followed Poisson almost exactly - the pattern of pure randomness. The bombs weren't aiming at anyone's street. Chance simply clusters, and our pattern-matcher - the same one from Part 1, still refusing to switch off - reads intent into the clusters. The Poisson distribution is, among other things, a formal statement of why you should be slow to see a conspiracy in a coincidence.

Step back and notice a quiet assumption running underneath all four of these shapes. Every coin flip, every peg, every raindrop, every horse kick has been independent - each one forgets the one before it. That independence is exactly what let us count and add and watch bells emerge. But almost nothing you truly care about is independent. Today's weather remembers yesterday's. Tomorrow's stock price remembers today's. The next word in this sentence remembers the previous one. The moment we let each event remember the last, a new and stranger mathematics appears - one that will end up training a text generator on this very page, and setting up the final reveal of the whole article. What happens when chance grows a memory?

Part 4 - Chance with a Memory

Until now, every source of randomness we've studied has been amnesiac. The coin doesn't remember its last flip; the die doesn't recall the last roll; each raindrop lands ignorant of the others. That independence is what let us count and add so freely. But it also makes these models poor descriptions of almost anything real, because real processes remember. Weather, language, markets, your own behavior - the next step depends on the current one. This part is about what happens when we let chance keep exactly one step of memory, and it ends with you training a text generator by hand - which is the last thing we need before the finale.

4.1 An argument about free will invents a new mathematics

This branch of probability was born, gloriously, out of spite. At the start of the twentieth century a Russian mathematician named - who was also a theologian - made an argument that sounds absurd now but was taken seriously then. He knew that the law of large numbers, as it was usually proved, assumed independence: independent events, averaged, converge. He also observed that social statistics - crime rates, marriage rates - obey the law of large numbers, settling to stable averages year after year. Therefore, he reasoned, the underlying human acts must be independent; and independent acts, he claimed, are freely willed. He had, to his own satisfaction, proven free will with a theorem. The regularity of statistics was, for Nekrasov, mathematical proof of the human soul.

Andrey Markov thought this was nonsense, and he disliked Nekrasov intensely - the two were on opposite sides of Russian politics and academic life, and Markov's letters about him drip with contempt. So Markov set out to demolish the argument in the most devastating way a mathematician can: by construction. He built a model of events that were emphatically not independent - where each outcome depended directly on the one before it - and then proved that these dependent chains obey the law of large numbers anyway. Independence was never required. Nekrasov's entire inference collapsed. And in the act of refuting a theological argument out of pure animus, Markov invented what we now call the , in 1906. An enormous branch of modern mathematics exists because one Russian mathematician wanted to prove another one wrong.

Then Markov did something visionary to show his chains described the real world. In 1913 he took the text of Pushkin's novel-in-verse , went through the first 20,000 letters by hand, and classified each as a vowel or a consonant, tallying how often a vowel followed a vowel, a consonant followed a vowel, and so on. He was measuring the dependency between successive letters - building, letter by letter and stroke by stroke, the first statistical model of language in history. A century before autocomplete, a man with a pen and a novel built a machine that knew Russian spelling was not a sequence of independent coin flips. Hold that image; we're going to rebuild his experiment, automated, at the end of this part.

Let's state the idea honestly, because it's simpler than its reputation. A process has the Markov property if the future depends on the past only through the present. Not that the past doesn't matter - it matters enormously - but that everything the past has to say about the future is already summarized in the current state. Once you know where you are now, the road that brought you here tells you nothing extra. That's memory, but exactly one step of it. (You can build in more memory by folding the last few states into "the present" - an order-2 or order-3 chain - but that's a footnote, and we'll see it pay off literally in the text generator.)

4.2 Walking the chain

The cleanest way to feel a Markov chain is to build a tiny one and walk it. Here's a weather model with three states - sunny, cloudy, rainy - and a table of transition probabilities: given today is sunny, how likely is tomorrow to be sunny, cloudy, or rainy? Edit the transitions, pick a starting day, and step it forward. Keep a tally of how many days you spend in each state.

The weather machine - a Markov chain over three skies
day 0 · 1 sampled
today
Sunny
started from
Sunny
days elapsed
0
the chainarrow width ∝ probability
SunnyCloudyRainy
highlighted arrows = where tomorrow could go
transition matrix Peach row sums to 1
Sun
Clo
Rai
Sun
0.70
0.20
0.10
Clo
0.30
0.40
0.30
Rai
0.20
0.30
0.50

Drag any cell - the other two in its row re-balance so P stays a valid set of probabilities.

fraction of days in each statebars = visits · ticks = stationary π
π100%Sunnyπ=46%π0%Cloudyπ=28%π0%Rainyπ=26%
start from
launches all three starts at once and animates the fill - watch three different origins pile onto the same π ticks.

Try this: run a thousand days, note where the bars land, then pick a different starting state and run again. The long-run histogram lands in the same place no matter where you begin. That start-independent resting point is the stationary distribution - the chain forgets where it started. Or skip the memorizing: hit run 3 starts to race all three origins side by side and watch their faint bars converge onto the same ticks at once. Notice the π ticks didn't move when you changed where you started - that invariance is the stationary distribution.

This is a Markov chain: the future depends on the past only through the present. Tomorrow's weather is drawn from today's row of P and nothing else - not last week, not the season, just today. That's “one step of memory.” The empirical bars are one wandering path; the ticks are the ensemble it's drawn from, and given enough days the path visits each state in exactly those proportions. (Chains that remember more than the present - order-2 and up - exist, but they're just a bigger state space wearing the same clothes.)

Run it long enough and the histogram of days-per-state stops moving. It settles into a fixed set of proportions - say 50% sunny, 30% cloudy, 20% rainy - and stays there. That settled distribution is called the , and here is the property that makes it magical: it doesn't depend on where you started. Begin in the sunniest state or the rainiest one, run the chain long enough, and you land in the same long-run proportions either way. The chain forgets its origin. Whatever information was in the starting state gets washed out, one memoryless step at a time, until only the structure of the transitions remains. That forgetting is the stationary distribution, and it's the beating heart of everything else in this part.

Now the simplest chain of all: a walker on a line who steps left or right at random. It's a Markov chain whose state is just a position. Watch a few of them wander.

Random walk · one dimension
walker 1 (tracked)other walkersreturns to origin
steps
0 / 400
distance (walker 1)
0.00
returns to origin
0
RMS dist · √steps
0.00 · 0.00
RMS distance from origin vs steps
measured√steps

Typical distance tracks √steps, not steps: to wander twice as far, a walker needs four times as long.

Return-rate race · 400 walkers each, ever reached the origin
race step 0 / 2400
1D · line
0.0%
2D · plane
0.0%
3D · space
0.0%
1D2D3D (dashed = Pólya's ~34%)

Watch recurrence and transience split into a number: the 1D and 2D curves keep climbing toward 100% - everyone eventually comes home (2D only crawls there) - while 3D stalls against Pólya's ~34%. The other two-thirds of the 3D flock wander off and never return.

6

Pólya's theorem (1921). The simple random walk is recurrent in 1 and 2 dimensions - with probability 1 the walker returns to its starting point (infinitely often, in fact). In 3 dimensions the walk turns transient: the return probability drops to about 0.34, so a 3D walker has a real chance of never coming home. Shizuo Kakutani put it best: "A drunk man will find his way home, but a drunk bird may get lost forever."

Two things are worth noticing. First, the typical distance from home grows like the square root of the number of steps, not linearly - a random walker of a thousand steps is only about thirty steps from where it began, on average. (This √n growth is the same fact that made the gap in the law of large numbers wander in Part 1, and it's the mathematics behind why diffusion is slow.) Second, there's a gorgeous and genuinely surprising theorem hiding here, due to George Pólya in 1921. A random walker in one dimension returns to its starting point with certainty - given infinite time, it always comes home. Same in two dimensions: certain return. But in three dimensions, the walker has only about a 34% chance of ever returning; most three-dimensional walks wander off and never come back. The mathematician Shizuo Kakutani summarized it perfectly:

"A drunk man will find his way home, but a drunk bird may get lost forever."- Shizuo Kakutani

4.3 The hundred-billion-dollar eigenvector

That abstract idea - a chain settling into a stationary distribution that ignores where it started - turns out to be worth an almost unimaginable amount of money, because it is the original insight behind Google. In the late 1990s the web was a chaos of pages linking to pages, and the hard problem was ranking them: of the thousands of pages containing your search words, which are important? Larry Page and Sergey Brin's answer, , was to model the entire web as a Markov chain. Imagine a "random surfer" who starts on some page and clicks links forever, hopping from page to page. A page's importance is simply how often the surfer ends up on it - the stationary distribution of the web-sized chain. Important pages are the ones that a random walk through the link graph keeps returning to.

And here's the bridge back to the weather machine, because it is the same object in disguise: a page hands its probability out equally to the pages it links to, so a page's row of outbound links is a row of a - exactly the table you edited by hand a moment ago, only now it is the size of the entire web. PageRank is just the stationary distribution of that unimaginably large matrix.

Build your own little web below. Wire up the links, release the surfer, and watch the pages swell to sizes proportional to how often the surfer visits them.

damping d
0.85
links
12
top page
C
surfer hops
0
the mini-webclick a node, then another, to toggle a link
A18%B10%C38%D19%E11%F2%G2%
node size = PageRank
rank vs surfer stationary distribution
A
18.1
B
9.8
C
37.6
D
19.0
E
11.1
F
2.1
G
2.1
press play: the surfer's visit ticks drift toward the rank bars
links as probabilitieseach row IS a row of the transition matrix
A->B, C (1/2, 1/2)
B->C (1/1)
C->A, D (1/2, 1/2)
D->C, E (1/2, 1/2)
E->C (1/1)
F->C, E (1/2, 1/2)
G->C, D (1/2, 1/2)
A page splitting its probability equally among its outbound links is one row of the Google matrix - the web graph is the weather chain, grown large.
0.85

A page's PageRank is just the fraction of time a bored, link-clicking surfer spends there - the stationary distribution of a Markov chain, the same idea as the long-run weather. Point many nodes at one target and watch its rank balloon: that's the original link-spam exploit. The 15% teleport (from d = 0.85) is what keeps the chain ergodic, guaranteeing one unique stationary distribution no matter how you rewire the web.

There's one wrinkle Page and Brin had to fix, and it's the same well-behavedness the weather chain needed. A raw web has traps: pages with no outbound links, or clusters that link only among themselves, where the surfer gets stuck and the "forgets where it started" guarantee breaks. Their fix is the : about 15% of the time, the surfer ignores the links entirely and teleports to a random page. That small dose of teleportation reconnects everything, guaranteeing the chain has a single, well-defined stationary distribution no matter how tangled the link structure is. (Mathematicians call such a chain ; the teleport is what buys ergodicity.) Google's original empire rested on a Markov chain and a clever hack to make it behave. Try pointing many of your nodes at a single page and watch its rank balloon - you've just reinvented link-farm spam, which is exactly the exploit Google then spent two decades fighting.

Two more places this same machinery quietly runs, mentioned in one breath because each could be its own article. When modern Bayesians need to compute the impossible integrals from Part 2, they often use - they design a Markov chain whose stationary distribution is the posterior they want, then walk it and collect samples. The chain's forgetfulness becomes a computational tool: run it long enough and its wanderings trace out the exact distribution you couldn't calculate directly. That closes a loop with Part 2 rather neatly. And the humble autocorrect and predictive-text keyboard on your phone is, at its simplest, a Markov model over words - which brings us to the machine I promised.

4.4 The machine that writes

Here is the flagship, and Markov's Onegin experiment reborn as something you can run in a browser. Pick a body of text - Alice in Wonderland, Shakespeare's sonnets, Pushkin's Onegin in Markov's honor, or paste your own. Choose whether to work in letters or whole words, and choose an order: how many preceding the model gets to look at. Then generate.

A Markov chain that learned to write by counting.
Training corpus
Lewis Carroll, 1865
Token type
Order (context length)k = 2
almost-English with ghost words that never existed
How it picks the next tokenthe same knob a language model turns: sampling ("temperature") vs argmax
Draw the next token in proportion to its count - the variety comes from the dice. This is an LLM decoding with temperature above zero.
11,241
corpus (characters)
582
distinct contexts
3.8
avg branching
Avg branching is how many distinct tokens a context can lead to. As order rises it collapses toward 1.0 - and branching near 1 means the chain has stopped choosing and is reciting the source verbatim: memorising, not generalising. The same overfitting a language model must avoid.
Generated passage - click any character to inspect the context that produced it
Ma'amp! thund begaink and fore re papponce but wastas shey, hose any rin yought wer sagainagards ing was thes: of eves th ming upongs and nowelf, yought, fif th to las dain truld pas the get and lostseverst andid of might ithiced: prat ther. The a for, thered go Aling tabbit hure his boor; acks ve a fire, ling darkabout ing foreathing play, sorse, was ne fall throme coat whad she wassay to id the whe was pright cou ith was got wered; holich Do had so hatcolefor it wever to down and tuddento shen ache curt, but very
Given this context, here's what comes next - with probabilities:
er?
41.0% ×75
e
16.4% ×30
y
13.7% ×25
s
10.9% ×20
,
6.0% ×11
a
2.2% ×4
i
1.6% ×3
.
1.6% ×3
h
1.1% ×2
t
1.1% ×2
w
0.5% ×1
n
0.5% ×1
_
0.5% ×1
)
0.5% ×1
+ 4 more possible characters
Here the chain sampled y (p = 13.7%) - one draw from 18 options. Slide the window one step and repeat.
Same seed, every order - watch the one passage sharpen, then tip into memorising the source (click a rung to inspect it above)
One seed, held fixed - only the context length changes. to re-run the whole ladder on a fresh sample.

That is the entire machine: take the current context, look up the tokens that followed it in the corpus, and sample from those counts. Claude Shannon did exactly this by hand in 1948 - book in lap, find the current few letters, flip to a random page, copy the next letter that follows them, repeat - in the founding paper of information theory. In the 1980s the Usenet bot Mark V. Shaney ran a word-level chain over a newsgroup and its posts fooled readers into arguing with it. Turn the order up and the babble sharpens toward memorised English; the only thing that ever changed was the length of the context. Predicting the next token from a probability distribution over what could come next is what a language model does - just with a vastly richer sense of "context."

Slide the order up from zero and watch language assemble itself out of counting. At order 0, with no memory at all, you get alphabet soup - letters in roughly the right proportions but no structure. At order 1, each letter is chosen from what typically follows the single previous letter, and you get pronounceable nonsense, little burps of almost-words. By order 2 or 3, the output is eerily close to English: real words appear, along with plausible ghost words that were never in the text but obey its spelling. Switch to word-level and low orders already produce sentences that nearly mean something. The model is doing nothing clever. It is counting what followed what, and sampling from those counts.

And that's why I built the lookup panel: so you can see there's no magic under the hood. Pick a context - the last few letters or words - and the demo shows you the exact frequency table the model consults: here are the tokens that followed this context in the training text, here are their counts, here are the probabilities, and generation is nothing but land on a context, look up this table, roll the dice, move on. That is the whole machine. A frequency table and a random number generator.

Two pieces of history to sit with before the finale. First: in 1948, Claude Shannon - the Bell Labs man from the Kelly section - did exactly this by hand in the paper that founded . He'd open a book, pick a pair of letters, find a random later occurrence of that pair, note the letter that followed, and repeat, generating text one weighted coin-flip at a time. His hand-computed Markov gibberish appears in the single most important paper of the twentieth century. Second, and more comic: in the 1980s a Markov-chain bot called "" was loosed on Usenet, generating posts by exactly this method, and readers spent real energy arguing with what they took to be a confused but sincere human being. A frequency table fooled people forty years ago.

Look hard at what your text lab actually does, because the whole article has been walking toward this sentence. Given a context, it produces a probability distribution over what comes next, and samples from it. That's it. That's the entire operation. Now here is the strange and beautiful fact that turns this from a toy into the story of our moment: in that same 1948 paper, Shannon proved that predicting what comes next and compressing information are not two problems but one - that a good enough model of "what comes next" is a good enough compressor, and vice versa. And seventy-five years later, that single identity is the reason a machine that does nothing but predict the next token can appear to think. The last part is short, and it is a door, not a room.

Part 5 - Prediction Is Compression

This last part is short on purpose. It's not a destination; it's a door. Everything so far has been well-charted territory - three centuries of settled mathematics. What's on the other side of this door is the live wire of our moment, and it deserves its own articles, which I'm going to write. But I want to walk you up to the threshold, because the view from your text lab is better than you might think, and it turns out to look directly at the machines everyone is arguing about.

5.1 Surprise, measured in coin flips

Start with a deceptively simple question: how much information is in a message? Claude Shannon's answer, in that same world-changing 1948 paper, was to tie information to surprise. A message that tells you something you already expected carries almost no information; a message that tells you something shocking carries a lot. "The sun rose this morning" is nearly informationless. "The sun did not rise this morning" would be the most information-dense sentence in history. Information is surprise, and surprise is just improbability: the rarer the event, the more it tells you when it happens. "Dog bites man" is common and dull; "man bites dog" is rare and newsworthy. Shannon made this exact intuition quantitative.

He measured it in bits - the same bits your computer uses - where one bit is the information in a single fair coin flip, the answer to one perfectly balanced yes/no question. The average surprise of a source, the average number of yes/no questions you'd need to pin down its next output, is its . A predictable source has low entropy (few questions needed); an unpredictable one has high entropy. And here's the delightful part: you can measure the entropy of English by playing a game. Shannon did exactly this in 1951, with his wife as a test subject and a book. We can run his experiment on you right now.

Below is a hidden sentence. Guess it one letter at a time; the demo counts how many guesses each letter takes. That guess count is, quite literally, a measurement of how predictable English is - of its entropy.

Guess the next letter - and estimate the entropy of English.
___________________________________________________________
guess the highlighted position - spaces count too (click here first to type with your keyboard)
0
letters solved
0
total guesses
-
avg guesses / letter
-
entropy estimate (upper bound)
bits per character - your model vs. blind guessing
you
-
uniform 27
4.75
estimated redundancy of this passage: - (rough upper bound from a short sample, not a measurement of all English)
how many tries each letter took
1st
2nd
3rd
4th+
For real English most letters fall on the 1st or 2nd try - that low surprise is the redundancy.

This is Shannon's 1951 experiment. Your guess count is a rough estimate of the entropy of English - the average surprise per character, which he pegged near 1 bit against the 4.76 bits of blind choice. You could only guess well because you carry a probability model of English in your head: good guessing is a good model. (The numbers here are a small-sample approximation of Shannon's method, not an exact measurement.) The same next-symbol game - measured in bits, powered by a learned model - is the bridge from probability to compression and language models.

Notice how often you nailed the next letter on the first or second try. After "th" you knew an "e" was likely; after "probab" the rest wrote itself. If letters were random - 27 equally-likely symbols - you'd need about 4.76 bits each, roughly 14 guesses on average. But you needed far fewer, because English is drenched in : th_ r__d_r c_n pr_b_bly r__d th_s just fine. Shannon's estimate came out to roughly 1 bit per character - meaning English is something like 75 to 80 percent redundant. You could only guess that well because you are carrying around an extraordinarily detailed probability model of English in your head, built from a lifetime of reading. Good guessing is good modeling. Hold onto that sentence; it's the hinge of the whole finale.

Want to feel the redundancy directly? Erase letters from a passage and see how many you can lose before it stops being readable. Most people sail past 40 percent gone - which means those letters were barely carrying any information, and a compressor could have dropped them too.

Erase the letters - and watch English stay readable.
Te ae c prbaby rea his ence ev ft ay its lt ave e quitly moe. he se of the wrd, h spc e thm, n th rdiry hai f Englh o s of he k, s yur ey il in te gps lm tut ffort.
45%
0%intactreadable?70%
94
letters removed
114
letters kept
45%
% of letters removed
≈ 536 / 978 bits
information kept (rough)
45% of letters removed - still readable for most people.

You just reconstructed the message from a fraction of its letters - the missing ones were redundant, carrying little information because context could supply them. That redundancy is exactly what a compressor removes, which is why text files shrink. It is also why the guessing game let you predict the next letter so well: English is roughly 75% redundant, and you can feel it.

5.2 Why prediction and compression are the same thing

Now the identity that this entire article has been walking toward. Shannon proved that the entropy of a source is exactly the limit of how much you can compress it - you cannot losslessly squeeze a message below its entropy, and you can always squeeze it down to nearly that. Redundancy is precisely the stuff a compressor removes. English is 75% redundant, so a good compressor can shrink English text to roughly a quarter of its size, and not much further. Entropy is the floor.

And the way you hit that floor is beautiful, and it closes the loop with everything you've built. To compress well, you give short codes to likely things and long codes to rare things. Samuel Morse knew this in the 1830s without any theory: in , the most common English letter, E, is a single dot - the shortest possible symbol - while rare Q and Z get long dot-dash strings. He assigned code lengths by walking into a print shop and counting the letters in the type-cases. That's it. That's compression: a probability model (which letters are common) plus the rule "spend fewer bits on the probable." But look at what that requires - you can only assign the short codes if you know the probabilities. A better probability model produces better predictions produces shorter codes. So a compressor is a probability model wearing a filing system, and a good predictor and a good compressor are not two things. They are one thing viewed from two sides. Your phone's autocomplete and the zip file on your desktop are the same mathematics in different costumes.

Here is that trade actually happening. Below, the same message encoded two ways: every letter the same width (blind), or short codes for the common letters and long codes for the rare ones. Turn it on and watch the message physically shrink toward a floor it cannot cross - the entropy. Spend fewer bits on the probable; that is the whole of compression.

Give short codes to likely letters and watch the message shrink.
each block's width = its code length (Huffman)frequent = narrow
t
h
e
m
o
r
e
l
i
k
e
l
y
a
l
e
t
t
e
r
i
s
t
h
e
s
h
o
r
t
e
r
t
h
e
c
o
d
e
i
t
s
h
o
u
l
d
g
e
t
s
o
c
o
m
m
o
n
o
n
e
s
l
i
k
e
e
t
a
n
d
t
h
e
s
p
a
c
e
c
o
s
t
l
i
t
t
l
e
w
h
i
l
e
r
a
r
e
l
e
t
t
e
r
s
l
i
k
e
q
a
n
d
z
m
u
s
t
p
a
y
m
u
c
h
m
o
r
e
634
total bits (this code)
3.89
bits / character
3.85
entropy floor H
22%
saved vs. blind
bits per character - and the floor it cannot cross
0H 3.85blind 5.00
blind 5.00
Huffman 3.89
floor H 3.85
the filing system - 22 symbols, short codes to the common ones
20.9%
2 bits
e
13.5%
3 bits
t
9.8%
4 bits
o
6.1%
4 bits
l
6.1%
4 bits
s
5.5%
4 bits
r
4.9%
4 bits
h
4.9%
5 bits
i
4.3%
5 bits
m
3.7%
5 bits
a
3.7%
5 bits
c
3.1%
5 bits
d
2.5%
5 bits
n
2.5%
5 bits
k
1.8%
6 bits
u
1.8%
6 bits
y
1.2%
6 bits
p
1.2%
6 bits
g
0.6%
7 bits
w
0.6%
7 bits
q
0.6%
7 bits
z
0.6%
7 bits

This is order-0 coding: it only knows how often each letter appears, not what tends to follow what. That is why it stalls near 3.85 bits/char and can never reach the ~1 bit the guessing game found. To go lower you need context - a model that knows q is almost always followed by u, that a space is likely after the. A better probability model makes better predictions, and better predictions buy shorter codes. A compressor is a probability model with a filing system.

This deserves its own article, and it's the next one on my list: information theory - entropy, codes, channels, the whole gorgeous edifice Shannon built in a single 1948 paper. For now, just hold the identity: to predict well is to compress well is to understand.

5.3 The trillion-dollar autocomplete

Here, at last, is the door. Go back to your Markov Text Lab from Part 4 and remember exactly what it did: given a context - the last few tokens - it produced a probability distribution over what comes next, and sampled from it. That is also exactly what a does. When ChatGPT or any of its cousins writes, it is doing precisely one thing, over and over: given everything so far, it outputs a probability distribution over the next token, and samples one. Same operation as your text lab. Same operation Shannon did by hand in 1948. Same operation you just did guessing letters.

You can watch that exact operation below: type a few letters and see the live distribution over what comes next, then sample from it one character at a time. It's the Markov Text Lab's lookup table again, reframed as the single thing a language model does - except a real model learns its distribution from the whole context instead of counting the last few letters.

A language model in miniature: type a prefix and watch the distribution over the next character update - then sample from it.
Training corpus
Lewis Carroll, 1865
Context lengthk = 3
The model looks at the last 3 characters to predict the next one.
context:_ca?
P(next character | context) - top 10 candidates, sorted by probability:
t
33.3% ×6
n
27.8% ×5
m
16.7% ×3
k
16.7% ×3
r
5.6% ×1

That is the entire operation of a language model: given the text so far, produce a probability distribution over the next token and sample one. The only differences are scale and sophistication - a neural network with a learned, compressed representation of a vast context stands in for this lookup table over the last few characters, and its "tokens" are word pieces rather than single letters. But the shape of the thing is exactly what you built in the Markov Text Lab: count what follows, turn the counts into probabilities, and roll the dice.

So what's the difference? Only this - and it is a vast "only." Your text lab remembers a fixed, tiny window: the last three or four characters, looked up in a literal frequency table you could print out. A language model throws away both limits. Instead of a lookup table keyed on the last few tokens, it uses a neural network with hundreds of billions of parameters to build a learned, compressed representation of the entire context - thousands of tokens, and the patterns, syntax, facts, and styles distilled from much of the written internet. It is a Markov text generator with the memory restriction removed and the frequency table replaced by something that had to compress the regularities of language to fit. And by the argument of the last section, compressing the regularities of language that well is indistinguishable, from the outside, from understanding it.

Everything you built in this article is inside that machine. The counting of possibilities from Part 1. The updating on evidence from Part 2 - every predicted token is a posterior over what fits. The distributions over outcomes from Part 3. The next-step, context-conditioned prediction from Part 4. And the prediction-is-compression-is-understanding identity from this part, which is the reason a next-token predictor can write a poem, debug your code, or explain probability back to you. It is guessing the next letter. It is very, very good at carrying a probability model of the world in its head - because a lifetime of reading is exactly what it was trained on, only the lifetime is all of ours at once.

I'm going to stop right at the threshold, because what's past it - how you get from a frequency table to something that appears to reason; what a neural network actually is; what a transformer does; why scale changed everything - is the subject of the articles that come after this one. Information theory first, then neural networks, then the machines themselves. The path is longer than the one we just walked. But notice where it begins: it begins exactly where you are standing right now, with a probability distribution over what comes next.

Epilogue

In 1654 a gambler noticed his dice bets had stopped paying and, unable to explain it, wrote to a friend. Three hundred and seventy years later, machines finish our sentences. Between those two points runs a single unbroken thread, and it is remarkable how few moves it really contains. Count the ways things can happen. Update when the evidence arrives. Respect the long run without expecting it to rescue you from the short one. Notice that chance draws only a few shapes. Let the present carry the memory of the past. And, at the end, see that predicting what comes next and compressing what came before are the same act.

That's the whole toolkit, and I hope the thing you take from all this playing is not a set of formulas but a slight, permanent change in how the world looks: streaks stop feeling meaningful, positive tests stop being verdicts, coincidences stop being conspiracies, and the machine on your phone stops being magic and starts being counting - extraordinary, world-altering counting, but counting all the same. De Méré never did understand why his bet failed. You do. That's three and a half centuries of very hard thinking, compressed into an afternoon of pressing buttons, and it's yours now.


Get in touch

Have a thought, a question, or something you'd like me to write about?

Email me →