◈ probability mapProb · Ch 04/16
Probability from the coin flip up · chapter 04

04When "At Least One" Explodes

A room needs only 23 people before two of them very probably share a birthday. That is the most famous shock in the subject, and one subtraction is all it takes to crack it. Here is the subtraction. Last chapter ended with a small tool we almost threw away as bookkeeping: the complement rule, P(Aᶜ) = 1 − P(A). It fell straight out of the three axioms in a single line, and it looked like nothing. This chapter is where that one line does something close to magic. The setup is a trap you have fallen into before. The moment a question starts with the words “at least one,” a beginner tries to add up cases — at least one this, or at least one that — and immediately drowns. The cases overlap, the overlaps have their own overlaps, and the whole thing becomes a sum with 2ⁿ−1 tangled terms. But “at least one” has an opposite that is almost always a single, clean, multiply-it-out thing: “none.” So leave the tangle alone. Compute the easy opposite instead, then subtract it from 1. That is the whole move: P(at least one) = 1 − P(none). Aimed at a room of people it returns 23, which feels impossible and is not. By the end you will see the exact reason 23 fools everyone: your gut counts people when the maths counts pairs, and pairs grow quadratically. No magic — just one subtraction, aimed well.

01The line that does all the work

Let's stand exactly where we left off. Every event phrased “at least one” has a complement that is always the same tidy phrase: “none.” That is the hinge of the whole chapter, and it comes from one line of Chapter 3. There we watched P(Aᶜ) = 1 − P(A) fall out of the axioms. An event and its complement are disjoint, and together they fill Ω, so their two probabilities add to 1. Rearrange that and you have the rule. We filed it away as obvious. Now look at the kind of problem where it stops being obvious and turns powerful: at least one head, at least one six, at least one shared birthday. Split the sample space into those two territories below and read the identity straight off. Whatever weight is not in “none” must be in “at least one,” so the two always sum to 1.

recall (Ch 3): P(A) + P(Aᶜ) = 1 Ω none 0.000 at least one 1.000 peel P(at least one) = 1 − P(none) (Ch 3's rule, relabeled)
0.657 + 0.343 = 1.000
The peel changes nothing about Ω — same rule as Ch 3, P(A)+P(Aᶜ)=1, just wearing a costume.
Fig. 1. The whole square is Ω — every outcome there is. Split it at one line and you get exactly two territories: the at least one tangle on top (all the messy ways the event fires) and the clean none strip below (the one tidy way it doesn't). Drag the gold handle — or press peel it off — and the blue tangle lifts clear of Ω, leaving a dashed ghost of the slot it came from: same territory, just moved. That's the whole trick. This is Ch 3's complement rule, P(A)+P(Aᶜ)=1, wearing a costume — so P(at least one) = 1 − P(none) isn't a new law to memorize, it's one line of bookkeeping you already own, aimed at a harder-looking question. Slide n and p and watch the seam redraw itself; the two numbers in the readout never stop summing to 1.000.

Figure 1 split Ω into two territories, but only in the abstract. Make the messy side something you can count on your fingers. Flip a coin three times and there are eight outcomes. Exactly one of them, TTT, has no heads. The other seven all count as at least one head, and those seven scatter across exactly-one, exactly-two, and exactly-three. That scatter is what the complement lets you skip. Subtract the single none from 1 and you are done.

Guess P(at least one head) — then count all 8 outcomes by hand
3 flips → 8 equally likely outcomes ? HHH 3H ? HHT 2H ? HTH 2H ? HTT 1H ? THH 2H ? THT 1H ? TTH 1H ? TTT 0H ? ?
Guess: P(at least one head in 3 flips)?
Then filter the grid:
lock in a guess to begin
Lock a guess — then two ledgers agree
?
+
?
+
?
= ? of 8 — three separate piles, summed
1 −
?
= ? — one cell, one subtraction, same answer
Fig. 2. Guess P(at least one head) among 1⁄2, 3⁄4, 7⁄8, or not sure — then all 8 three-flip outcomes reveal, each cell coloured by head count. Filter none and only TTT lights up (1 of 8); filter =1, =2, =3 and you get 3, 3, 1 — three separate piles. Filter ≥1 and all three piles light together: 3+3+1 = 7 of 8. The bar below regroups the same 8 cells and makes the shortcut visible: summing three piles (top brace, 7) costs three additions, while the bottom brace is a single cell you subtract once — 1 − 1⁄8 = 7⁄8. Same number, one step instead of three. It's also why ≥1 is not =1: exactly-one is only 3 of those 7.

The identity is just the complement rule wearing a costume: P(at least one) = 1 − P(none). Nothing new arrived — it is the same one line from last chapter. What matters is not the algebra. It is which side of the equals sign is easy to compute, and the two sides are nowhere near equal in effort. To feel that difference, try computing the hard side head-on for a moment and watch it explode.

Eight servers that might each time out force the direct road into 255 separate terms. The complement needs one. Here is where that gap comes from. Say you have n separate things that could each “happen” — n servers that could each time out, n dice that could each show a six — and you want the chance that at least one does. The direct way forces you into inclusion–exclusion. Add the chance each one happens. Subtract every pair you double-counted. Add back every triple, and so on. Crank n below and watch the number of terms in that alternating sum blow up as 2ⁿ−1, hitting that count at n=8. Next to it sits the complement, which stays a single term the whole time.

n = 5 events + + + + + 1 2 3 4 5 6 7 8 9 10 k events overlapped at once (C(n,k) terms each) direct: P(at least one) 31 bookkeeping terms = 2ⁿ − 1 complement: 1 − P(none) 1 term, no matter how big n gets
n=5 → 31 direct terms vs 1 complement
That's why you flip the question: the direct road's bookkeeping grows exponentially (2ⁿ−1 terms) while the complement road never leaves 1 term.
Fig. 3. Crank n and watch the direct road pay for it: one bar per inclusion–exclusion term, alternating add (green, odd k) and subtract (orange, even k), and the counter races to 2ⁿ−1 — 255 terms by n=8. The complement chip on the right never moves: it is always exactly 1 term, 1 − P(none), no matter how large n gets. That gap in bookkeeping is why you flip the question.

The skill here is not memorizing a formula. It is the reflex to flip the question the instant you see “at least one,” and reach for “none.” The figure makes the reason plain. The direct road grows exponentially in bookkeeping. The complement road stays a one-liner, however large n gets. So let's earn that reflex on the simplest possible case before we aim it at anything hard.

Roll a fair die k times. What is the chance of at least one six? Head-on that is “a six on roll 1, or roll 2, or…” — the overlapping tangle again. Flipped, it is clean. “none” means every single roll misses, and each single roll misses with probability 5/6. Drag k and watch (5/6)ᵏ, the chance of a clean miss every time, shrink while 1 − (5/6)ᵏ climbs. Guess first: how many rolls before you are past 50%?

50% 100% 0% 1 4 8 12 k — number of dice rolls your guess miss ≥1 six k = 1 (5/6)^k → miss chance 83% 1 − (5/6)^k → ≥1 six 17%
guess: at which k does a six first beat 50/50?
pick a guess, then reveal
aha: "no six" is a product of independent misses, (5/6)×(5/6)×… — products fall fast, so the six wins by k=4.
Fig. 4. Lock in a guess for the k where a six first beats 50/50, then hit reveal — a gold band lights up the true crossing. Now drag rolls k yourself: the blue "miss" curve (5/6)^k falls while the green "≥1 six" curve climbs, and the crossover sits at exactly k=4. Each extra roll multiplies the miss chance by another 5/6, and that repeated multiplication is why "none" collapses so much faster than intuition expects.

The real test is whether your own hand reaches for the flip unprompted. You have watched it happen three times now, always done for you. Here are fresh at least one problems with no worked answer attached. For each one, build the “none” side yourself, then read off 1 − P(none). Guess wrong and the widget shows you exactly which factor you missed.

the reflex, on new ground P(at least one) = 1 − P(none) build P(none) below, then press check — no enumerating cases needed. 3 cards 1 flips 2 dice 3 parts
At least one head in 10 flips of a fair coin?
P(none) = ^
submit to check
1 − P(none) = —
At least one six across 4 dice rolls?
P(none) = ^
submit to check
1 − P(none) = —
At least one defective in 5 parts, 2% each?
P(none) = ^
submit to check
1 − P(none) = —
score: 0 / 3 solved
The reflex: read "at least one" → hand writes 1 − (the clean none product) → only then plug numbers in.
Fig. 5. Three fresh "at least one" problems — no coins-and-birthdays crutch. For each card, build P(none) from its two dropdowns (the per-trial miss chance, then the count) and press check. Get it wrong and the verdict names exactly which dropdown is off — the miss chance or the count — instead of just saying no. Get it right and the card reveals 1 − P(none): 0.999 for at least one head in 10 flips, 0.518 for at least one six in 4 dice, 0.096 for at least one defective in 5 parts at 2% each. Clear all three and the score reads 3 / 3 solved — proof the reflex is now yours: "at least one" makes your hand reach for 1 − (the clean none product) before you'd ever think to enumerate cases.

Four rolls of the die already make you a favourite to have seen a six: 1 − (5/6)⁴ ≈ 0.52. That surprises almost everyone, because most people guess six rolls or ten. Notice what made the calculation easy. “None” was a product of identical, independent misses, one factor per roll. That product is the real engine of the chapter. So let's understand exactly why “none” always multiplies into one clean term.

02Why "none" is one clean product

Here is the mechanism, from the ground up. “None” is a chain of “ands”: no six on roll 1, and none on roll 2, and none on roll 3… When the trials do not influence each other — when they are independent — the probability of that chain of ands is simply the product of the pieces. Each new trial that still fails tacks one more factor onto the running product. There is nothing to add, nothing to subtract, and no overlaps to police. Step through the build below and watch “none” grow one clean factor at a time.

one die roll: p = 1/6 chance of a six · 1−p = 5/6 chance of no six P(none) = (5/6)⁰ = 1.0000 each new trial → one more ×(5/6), nothing added or removed none — no six yet at least one six P(none) = 1.0000 P(at least one) = 0.0000 one clean flip: P(at least one) = 1 − P(none)
n = 0 trials rolled
n=0 → empty product → P(none)=1.0000
That's why the complement side never tangles — ands under independence multiply, they don't overlap.
Fig. 6. Hit add trial: one more die roll joins the chain, one more ×(5/6) tile lights up gold, and the running product — P(none), the chance not one of the rolls so far shows a six — just gets multiplied by another 5/6. No term is ever added, none is ever subtracted; each trial is independent, so "none in trial 1" and "none in trial 2" and … is a plain product. Watch the bar below: the blue P(none) slice shrinks by that same factor each click while the green P(at least one) slice — its complement — grows to fill exactly what's left, no overlap to reconcile. That's the whole trick: the "and" chain on the complement side never tangles, because independent ands just multiply.

One factor per trial — that is exactly why the complement side never tangles. But the die example had independent rolls with a fixed 5/6 miss chance every time. The birthday problem is subtler, and it is subtle in a way you have already met. In the birthday problem the “misses” get harder as you go. That is the tell for a mechanism we built two chapters ago.

Line up n people and ask for the chance their birthdays are all distinct — the “none share” case. Person 1 can have any of 365 days, so person 1 gets a free pass at 365/365. Person 2 must dodge the one day already taken, leaving 364/365. Person 3 must dodge two taken days, leaving 363/365. So the pool of safe days depletes by one with every person who walks in. That is exactly sampling without replacement from Chapter 2, the depleting deck of cards walking back on stage. Step a person in at a time and watch the product assemble.

the 365-day pool 364 days free for the next arrival each square = one person (365 days total) person 1 just stepped in the running product 365⁄365 364⁄365 363⁄365 362⁄365 361⁄365 360⁄365 359⁄365 358⁄365 357⁄365 356⁄365 355⁄365 354⁄365 ↓ multiply every lit chip 1.0000 P(all n so far distinct) ↳ that's why the factors shrink: every new person must dodge more taken days — same depleting deck, 365 slots wide.
recall (Ch 2): picking one item without replacement shrinks the pool by one — this is that, 365 days wide.
person 1 found 365/365 days open
watch the tile flip, the chip light up, and the product tick down — together.
Fig. 7. Recall (Ch 2): drawing one item without replacement shrinks the pool by one. Click step next person — a tile flips from safe to taken, the matching fraction lights up in the product, and P(all distinct) ticks down. That's why the factors shrink: every new person must dodge more taken days — it's the same depleting deck, 365 slots wide.

So “all distinct” is the product (365/365)·(364/365)·(363/365)·…, one shrinking factor per person. It is the same depleting-pool count we already trust, run with 365 calendar slots instead of 52 cards. And the event we actually want is its complement: P(at least two share) = 1 − P(all distinct). That is the complete recipe. Now let's turn the crank and meet the shock everyone warns you about.

03The birthday problem

Before you touch the figure, commit to a number out loud if you can. Being wrong is what rewires the intuition. A room fills with people. How many do you need before it is more likely than not that some two of them share a birthday? Most people answer with a big fraction of 365 — 180, maybe, half the calendar. Hold your guess. Now drag n from 1 to 60 and watch the two curves. P(all distinct) slides down, and P(at least two share) climbs up. Find where they cross the 50% line.

100% 50% 0% 1 23 40 60 people in the room (n) → 50-50 line — even odds lock in a guess → the curves appear P(a match) P(all distinct) n=23 23 people match 50.7% distinct 49.3% 253 pairs drag n below →
Predict: how many people until a shared birthday is more likely than not?
Gut check: 365 days, so surely it takes ~183 (half a year) for a coin-flip? Lock in a guess.
lock in a guess to begin
Fig. 8. First predict the tipping point, then drag n and watch the two curves cross. The green curve — everyone's birthday distinct — slides down; the coral curve — at least one shared birthday — climbs to meet it, and they cut the 50-50 line at just n=23 (50.7%), reaching 99% by 57. Why so soon? 23 people don't make 23 comparisons — they make 253 pairs (23×22/2), and the coral curve rises with the pairs, far faster than a linear gut expects.

Twenty-three. Not 180 — 23. At 23 people the chance that some two of them share a birthday is already ≈ 0.507, a hair over half. By 57 people that same chance is above 99%, near-certain in a crowd that would not fill a bus. This is genuinely one of the great counter-intuitive results in the subject, and your disbelief right now is the healthy reaction. So let's make the result concrete before we explain it. Drop 23 actual people onto a calendar and see the collision happen with your own eyes.

365 days — one box per day empty day 1 birthday 2+ = collision click reshuffle to fill the room running tally shuffles: 0 collisions: 0 (—) real odds: 50.7%
click reshuffle to fill the room
23 people make 253 possible pairs (23×22÷2) — each pair gets its own 1-in-365 shot at matching. 253 independent shots is why a shared birthday keeps landing.
Fig. 9. Each of the 365 boxes is one calendar day. Hit reshuffle and 23 people drop onto the grid at random — most days stay empty, some get exactly one dot, and every so often two land on the same box and it flares gold. Keep clicking and watch the tally: collisions land right around the computed 50.7%, roughly every other room. With only 23 people you'd guess the 365 empty boxes make a match unlikely — but 23 people form 253 pairs, and it only takes one of those 253 shots to land for the room to flare.

Watching a single room is persuasive but anecdotal, because one collision could be a fluke. The honest way to trust a probability is to run it many times and let the empirical fraction settle. That is exactly what a computer is for. Below we fill a room with 23 random birthdays, check for a shared one, and repeat that whole experiment 100,000 times. Predict where the running fraction lands, then run it.

birthday_sim.py for trial in 1..100000: room = 23 random birthdays if collision: hits += 1 1 .5 0 0 50k 100k trials simulated→ 0.507 — the formula 0.0000 running fraction trials 0 hits 0 guess — → no formula ran in that loop — pure counting landed on ~0.507 too
predict: where does it settle?
pick a guess, then run 100,000 trials
no formula runs inside that loop — it only counts collisions, 100,000 times over.
Fig. 10. Pick a guess, then hit run: 100,000 independent rooms of 23 birthdays get filled, checked for a collision, and counted — no formula anywhere in that loop. Watch the blue running fraction chase the gold line down and settle within a whisker of 0.507 (100,000 trials pins it to about ±0.003), the number the "1 − none" formula predicted. Two completely different roads — pure counting here, algebra earlier — landing that close is why you trust the maths.

The simulated fraction homes in on 0.507 — the same value the formula gave. That agreement is the whole point of checking analytic maths against a Monte-Carlo. Two roads, one number, and now you believe it. But believing is not understanding. Why does 23 do it? The answer is the best idea in the chapter, and once you see it you can never un-see it.

04Pairs, not people

Here is the trap, named plainly. When you imagine “someone sharing my birthday,” you picture yourself checking against everyone else — 22 comparisons for you in a room of 23. That count is linear: add a person, add one comparison. If linear were the real count, your intuition would be right and you would need a crowd. But the event is not “someone shares mine.” It is “any two people at all share.” So what actually matters is the number of pairs. Pairs are a choose-two count, C(n,2) = n(n−1)/2, and that grows like n²/2quadratically. Slide n and watch every pair drawn as a chord. Count how fast the chords pile up.

6 people 15 pairs — one chord each 6 people you actually see C(6,2) = 6×5/2 = 15 the newest person adds 5 pairs
6 people → 15 pairs
You count heads (that's n). The maths counts handshakes — and each new head shakes every earlier hand, so pairs climb like n²/2. 23 heads hide 253 pairs.
Fig. 11. Pairs grow like n²/2. The birthday event isn’t about any one person — it’s about any two sharing, so the thing that counts is pairs. Add a person to the ring and they shake hands with everyone already there, so the chords don’t add up — they pile up: C(n,2) = n(n−1)/2. Slide to the classroom number and the trick is exposed: you see 23 people, the maths sees 253 pairs. That gap is why “at least one shared birthday” sneaks past your intuition.

Each newcomer brings more new pairs than the last one did, and a count whose steps keep growing is exactly what quadratic means. Watch why. A single person walks into the room and shakes hands with everyone already there, so the new pairs they add equals the size of the crowd they joined. The tenth person to arrive adds nine pairs. The twenty-third adds twenty-two. That is the chords piling up faster than the people did.

new pairs added, one person at a time 22 11 0 flat: always +1 1 5 10 15 20 23 0 pairs so far — C(n,2) 0 flat count if +1 each
Person #2 joins — how many NEW pairs do they add?
guess, then click to reveal
Aha — the increment itself climbs by exactly one every step (0,1,2,3,…). That steady climb — the constant second difference — is why the running total is quadratic, not a straight line.
Fig. 12. The increment itself is climbing. Guess, then click a number — the bar proves it: person 2 adds +1, person 3 adds +2, all the way to person 23 adding +22 — a staircase, never a flat row. That increment grows by exactly one every step (a constant second difference), which is exactly why the running total isn't linear: it's C(n,2), landing at 253 pairs from just 23 people. Flip on the flat +1 line to see the gut's picture instead — "me vs. everyone" only ever reaches 22 at n = 23, over ten times short of the real count.

At 23 people there are C(23,2) = 253 pairs. That is 253 separate little chances for a collision, hiding in a room your gut insists is tiny. That is the whole illusion. You counted people (23) and the maths counted pairs (253). Let's put the two counts side by side so the gap is unmissable: the linear “me vs everyone” fan against the full “everyone vs everyone” web.

me vs. everyone everyone vs. everyone me 6 n−1 = 6 21 C(n,2) = 21
linear 6 · quadratic 21
Same n, one slider — but "any two share" counts a whole web, not one fan.
Fig. 13. One slider, two questions. The left fan draws a line from me to everyone else — n−1 lines, adding exactly one per person. The right web draws a line between every pairC(n,2) = n(n−1)/2 lines, adding more per person than the last. Slide past 10 people and the fan is still barely a dozen lines while the web is already a tangle past fifty. That gap is why "surely that's rare" feels true — it's silently answering the linear question, does anyone share mine?, when the real question is the quadratic one, does any two share at all?

The web dwarfs the fan the moment n gets past a handful, because n²/2 outruns n and never looks back. Now we can close the loop with a lovely piece of arithmetic. Each of the 253 pairs shares a birthday with probability 1/365, so the expected number of colliding pairs in a room of 23 is 253/365 ≈ 0.69. Watch that expected-collision count climb with n. See it pass the magic value of about ln 2 ≈ 0.69 right as the share probability crosses 50%.

n = 23 E[colliding pairs] E = 0.693 5 0 ln2 C(n,2) / 365 1 − e⁻ᴱ ≈ P P(≥1 share) P = 50.7% 1 0 .5 1 − e^(−E) ≈ actual n = 23 → the exact crossing
n=23: E crosses ln2, P crosses 50%
The pair count C(n,2) is the engine: set E = ln2 and 1 − e^(−E) = ½ falls right out.
Fig. 14. Left: the expected number of colliding pairs, E = C(n,2)/365, drawn as a bar that grows with the slider — watch it climb past the gold ln 2 ≈ 0.69 line. Right: the exact share probability P(≥1 share) plotted against every headcount from 2 to 60, with a dot riding the curve at your current n — watch it cross the gold 50% line. Drag past n = 23 and both crossings light up gold at once. That's not a coincidence: since P ≈ 1 − e^(−E), setting E = ln 2 forces P = ½ by algebra alone — the pair count C(n,2) is the engine driving both panels, and 23 is just the smallest integer that pushes it past that line.

That is not a coincidence. It is the deep reason 23 is the answer. When rare events each have a tiny chance and there are many of them, their count follows a Poisson process, which we will build properly later. Poisson gives P(at least one) ≈ 1 − e^(−E), where E is the expected number of collisions. Set that probability to 1/2 and you need E = ln 2 ≈ 0.69 expected collisions. And n(n−1)/2 · (1/365) reaches 0.69 right at n = 23. The pairs were the engine all along. Now for one unglamorous but essential skill before we generalize: actually computing these products without your machine catching fire.

05Doing the arithmetic without melting

The clean way to write “all distinct” is a ratio of factorials: 365! / (365−n)! / 365ⁿ. That expression is correct, and it is a trap to compute literally. 365! is a number with 779 digits, vastly larger than any normal floating-point value can hold. Ask a computer for that factorial as a float and it does not return a wrong answer. It overflows and dies. Watch the naive factorial route detonate below, right next to the fix.

NAIVE >>> from math import factorial >>> big = factorial(365) >>> den = factorial(365-n) * 365**n >>> float(big) / den OUTPUT awaiting Run ▶ using n = 23 INCREMENTAL >>> p = 1.0 >>> for k in range(n): ... p *= (365-k)/365 >>> p OUTPUT awaiting Run ▶ using n = 23
Drag n to any crowd size — even n = 1 — then hit Run. The naive panel dies every time.
drag n, then hit Run ▶
Fig. 15. Same probability, two routes, run side by side. The naive route insists on building 365! as a plain float(big) before it divides anything: a number 779 digits long. So it detonates every time, no matter how small n is: try n = 1 and it still crashes. The incremental route never builds that giant number at all: it keeps one running probability in [0,1] the whole way down and lands safely on 0.4927 at n = 23. Never build the giant intermediate — the answer is small; only the naive path to it is huge.

Figure 15 showed the naive route crashing, but not the wall it hits. That wall has a number: a float64 can hold values up to about 1.8 × 10³⁰⁸, and no higher. Build 365! by multiplying 1 × 2 × 3 × … and watch the running value climb toward that ceiling. Predict the exact factor where it punches through and turns to infinity. The reordered route never even nears the wall, because every partial result stays the size of the answer itself.

naive: 1×2×3×…×k (building 365!) float64 max ≈ 1.8×10³⁰⁸ ← ceiling 10¹⁰⁰ 10²⁰⁰ 1 1 171 365 k — factors multiplied so far guess reordered: ∏ (365−k)/365 [0,1] — every partial stays answer-sized 1 0 1 23 365 k — people compared so far n=23 → 0.4927 never leaves the band
predict: at which factor k does building 365! first blow past the ceiling?
k=1 · running 365! = 1
predict a crossing, then reveal
aha: the answer 0.4927 is tiny — so no step ever needs a giant number. Fold (365−k)/365 instead of dividing two overflows, and there is nothing left to overflow.
Fig. 16. Drag factor k to build 365! one factor at a time and watch the blue trace climb the log-magnitude axis: at k=170 it is still a finite 7.26×10³⁰⁶, but the next factor lifts the true value to 1.24×10³⁰⁹ — past float64's 1.8×10³⁰⁸ ceiling — so the running product becomes Infinity, and the birthday ratio ∞/∞ reads NaN. Predict where that happens, then reveal (it is exactly k=171). Flip to reordered: folding (365−k)/365 keeps every partial inside [0,1] the whole way, landing on P(no shared birthday)=0.4927. The answer never needed a giant number; the naive factorization invents one and smashes a ceiling it cannot clear — reorder any computation so every partial stays about the size of its own answer.

The repair is a numerical-literacy habit worth carrying everywhere: never build the giant intermediate. Accumulate the answer one factor at a time instead. Start a running probability at 1.0 and multiply it by (365−k)/365 for each person k. Every partial result is itself a valid probability sitting politely in [0,1], so nothing ever grows large enough to overflow. Same maths, told in an order the machine can survive. Step the loop and watch the running product stay tame.

1.0 0.5 0.0 0 10 20 23 people in the room lands on 0.4927 naive: 365!/342! ≈ 10⁵⁹ ↑ P( ALL BIRTHDAYS DIFFER ) 1.0000 P(≥1 shared) = 0.0000 PERSON ADDED #1 of 23 FACTOR JUST MULTIPLIED IN 365/365 = 1.0000
1 person · p = 1.0000 · inside [0,1]
Every partial sits in [0,1]. The naive route builds 365! first — a 779-digit number no float can hold, astronomically bigger than the 0.49 answer it is heading for. Same maths, survivable order: never let a middle step outgrow the answer.
Folklore flag: the tale of a young Gauss summing 1..100 in a flash by pairing the ends is charming but likely embellished — yet it names the same habit: restructure the arithmetic so nothing balloons.
Fig. 17. The same maths, survived by reordering. To find the chance all birthdays differ, you could write the textbook formula 365! / 342! divided by 365²³ — but computed literally that means first building 365!, a 779-digit number no float can hold, and it overflows before you ever divide it back down. Restructure it instead: start at p = 1.0 and fold in one factor per person — ×364/365, ×363/365, and so on. Step it here and watch the running probability descend but never leave the range 0 to 1, landing on 0.4927 for 23 people — so the chance that at least one pair shares a birthday is 1 − 0.4927 = 0.5073, just over half. That is the transferable habit: reshape a computation so no middle step ever grows larger than its own answer.

One running number, always between 0 and 1, landing on 0.4927 at n=23 — and no 779-digit monster ever built. (While we are being honest: the old classroom legend that Gauss summed 1 to 100 in his head as a toddler is almost certainly a tall tale. The real lesson that survives is the one in this figure — restructure the computation so that it never blows up.) That is every tool the chapter needs. So let's do the two things that turn a party trick into understanding. First we try to break the result. Then we find the general shape it is a special case of.

06Break it, then generalize

Every result we have built quietly assumed birthdays are spread uniformly, with all 365 days equally likely. Real birthdays are not: there are seasonal humps, more September births, fewer on Christmas. So does clustering make a shared birthday less likely, since people bunch onto fewer days? Guess first, then toggle from uniform to clustered and watch the crossover move.

birthdays across the year (20 slices, stylized) P(≥1 shared birthday) by group size n uniform 100% 50% 0% 1 10 20 30 23 n=23
Guess: clustering moves 23 to…
commit a guess, then flip the toggle
Aha — bunching people onto popular days is exactly what forces the extra matches. Uniform wasn't typical, it was the best case.
Fig. 18. Lock in a guess, then hit flip to clustered. The strip up top is birthdays sorted into 20 slices of the year — flat means every slice gets its fair share. The curve below is P(at least one shared birthday) against group size n, for the exact same head-count either way. Spread uniformly, it crosses 50% at the textbook n = 23 (the grey mark, always there for comparison). Bunch just 20% of people onto a dozen popular days — the four tall slices mark where they fall — and the identical group now crosses 50% at n = 17: a few days are soaking up more than their fair share, so pairs collide sooner. 23 is a floor, not a ceiling — real birthdays cluster (school-year due dates, seasons), and every bit of clustering can only push that number lower, never higher.

The crossover moves the wrong way from most people's guess. Clustering makes collisions more likely, so the 50% crossing drops below 23. It makes sense once you see it: piling people onto fewer popular days is exactly what causes matches. So the plain-uniform answer of 23 is the conservative one, and the real world is even more collision-prone. Good — a result that survives having its assumptions kicked is a result you understand. Now zoom out. Strip away “birthdays” entirely and look at the template underneath.

Everything we did was one shape: a repeated trial, and the question “at least one success?” The universal answer for n independent trials, each with the same chance p, is P(at least one) = 1 − (1 − p)ⁿ. The die-six problem fits that formula exactly (p = 1/6). The birthday problem fits only approximately, because the 253 pairs are not quite independent. The formula puts the birthday crossing at 50.0%, a whisker from the exact 50.7%. Drive both knobs and watch this one formula.

p = 1/6 n = 4 51.8% P(at least one) 100% 50% 0% 1 10 100 400 n — trials (log scale) 🎲 🎂
P(at least one) ≈ 51.8%
same curve every time — only WHERE (p,n) lands on it changes. That's why die-six and birthday were never two tricks.
Fig. 19. One template: 1 − (1−p)ⁿ. Drag p and n, or snap to the die-six and birthday cases — same formula, same curve, just a different landing point.

The template 1 − (1−p)ⁿ fit the dice exactly and the birthdays only roughly. That word roughly hides the whole catch. The formula assumes every trial is independent, each carrying the same fixed p. When both of those hold, the template is exact. When the trials lean on each other it only approximates, and sometimes it lies outright. Below are three cases. Decide for each whether the shortcut is exact, close, or flat wrong before you reveal it.

1 DIE 4 rolls · at least one 6 shortcut 1−(1−p)ⁿ 1−(5/6)⁴ classify → reveal shortcut 0.518 exact 0.518 EXACT independent → exact 2 BIRTHDAY 253 pairs · p=1/365 shortcut 1−(1−p)ⁿ 1−(364/365)²⁵³ classify → reveal shortcut 0.500 exact 0.507 CLOSE weak pair link → close 3 URN 2 red 2 blue · draw 3 shortcut 1−(1−p)ⁿ 1−(1/2)³ classify → reveal shortcut 0.875 exact 1.000 WRONG pool depletes → wrong
Judge each shortcut before revealing: is 1−(1−p)ⁿ exact, close, or wrong?
1 die · independent rolls
2 birthday · 253 pairs
3 urn · 4-ball pool
classify each card, then reveal
Fig. 20. Tag each card exact, close, or wrong, then hit reveal all three to see the shortcut 1−(1−p)ⁿ beside the truth. The die (independent rolls) lands 0.518 = 0.518 — dead exact. The birthday's 253 pairs are only weakly linked, so the shortcut's 0.500 drifts a hair from the exact 0.507 — close. The tiny urn depletes hard: the shortcut says 0.875, but you cannot draw 3 blues from only 2, so the truth is 1.000 — the formula drifts all the way to a lie. Independence is the license the shortcut runs on; the more a pool depletes or trials correlate, the further it strays.

One template covers every “at least one” problem in the book. And the birthday version hides a scaling law worth seeing, because it reaches far outside probability. Replace 365 with a general number of slots d and ask where the 50% crossing lands. The answer is beautifully clean: about 1.18·√d. For d = 365 that is 1.18 × 19.1 ≈ 23 — there is our number, and now it is a formula rather than a party fact. Slide d and watch the threshold track √d.

crypto scale 0 16 32 48 64 n₅₀, in bits ↑ 0 32 64 96 128 output space size, in bits (d = 2^b) → n₅₀ ≈ 1.18·√d 🎂 365 days → 23 people 🔒 b, in bits (d = 2^b) 8.5 d — how many slots 365 n₅₀ — guesses for 50% 23
d=365 → 23 for 50%
🔓 AHA — a hash's security is HALF its bit-length: the attack forces a collision in √d, not d. A 128-bit hash (2¹²⁸ outputs) falls to just ~2⁶⁴ guesses.
Fig. 21. Drag b and one gold dot slides down a single straight law: the guesses needed for a 50% chance of a collision is always ≈1.18·√d, where d = 2^b is how many slots exist. Park it at 🎂 365 days and the dot lands on the classic answer — just 23 people are enough for a 50-50 chance that two of them share, out of 365 possible days. Now hit 🔒 128-bit hash: the exact same line, same slope, says a space of 2¹²⁸ possible outputs falls to a collision in only ~2⁶⁴ guesses. That's the whole reason a hash's quoted security is half its bit-length — the birthday attack always forces a collision in √d, never in the full d.

That √d law is not a curiosity. It is load-bearing infrastructure. In cryptography, a hash function maps data to one of d possible outputs, and a collision — two different inputs with the same hash — breaks the hash. The birthday result says an attacker does not need to try d inputs to force a collision, only about √d of them. That is why a hash advertised as “128-bit” has to output 2¹²⁸ values to stay safe against roughly 2⁶⁴ guesses: the security is the square root of the space, not the space itself. This exact party trick is why your passwords are safe or are not, and it has a name — a birthday attack. Same maths, a room of 23 people and a global security standard. Let's place it on the map.

07You are here

Step back to the family tree and see the honest size of what we did. We did not add a new axiom or a new distribution this chapter. We took the measure from Chapter 3 and learned one move on it: computing an event through its complement. We took one counting fact from Chapter 2, the depleting pool. Then we combined the move and the counting fact. Everything shocking that followed came from those two things we already owned. Find our rung, lit gold.

you are here ▾ 01sample space 02depleting pool 03measure 04at least one the trick below = tools you already own you already have depleting pool each draw shrinks it — Ch2 you already have A ¬A measure: complement P(A) + P(¬A) = 1 — Ch3 chapter 4 · the trick at least one P(≥1) = 1 − P(none) hover (or tap) the trick above ↑ = 1 − P(none) ← Ch3's complement P(none) ← Ch2's depleting pool, chained
This chapter added no new axiom and no new distribution. "At least one" is just one move on top of the two tools you already hold.
hover the gold trick above
the gold rung is always chapter 4 — hover its family tree to see the two parents it was built from.
Fig. 22. The recap strip up top is the map so far — four chapters, and chapter 4's at least one rung sits lit gold because you're standing on it right now. Hover (or tap) the tree below and watch its two parents light up: chapter 3 gave you the measure's complement rule, P(A) + P(¬A) = 1, rearranged to P(≥1) = 1 − P(none); chapter 2 gave you the depleting pool — the chain of shrinking-denominator draws that computes that P(none). Chapter 4 didn't hand you a new axiom or a new distribution. It handed you the idea of pointing those two tools at each other — that's the whole trick, and that's why it needed nothing new.

So this was a technique chapter, not a new-object chapter. It gave you the reflex to flip “at least one” into “1 − none,” and the humility to remember that your gut counts people when the maths counts pairs. That instinct — reach for the complement, or for a cleverly-chosen easier quantity — is one of the two master-moves of the whole subject. It comes back at the very summit, when we bound the tails of a distribution. But there is a question we have been carefully not asking, and it changes everything downstream.

Every probability so far has been fixed. An outcome just is, and P(A) is a single number carved in stone. But that is not how you actually reason, because you learn things. You find out the first card was red, and suddenly the chance the second one is a heart moves. So what is a probability once you have been handed a clue? And how do you update it? That is conditioning, and it is the door into the entire back half of this course. Take a first look at a probability changing the instant you learn something.

the deck: 2 red, 3 black — shuffled ↑ target: card 2 ? ? ? ? ? all 5 cards · 2 red before after the clue 40% 2 ⁄ 5 ?
40% — before any clue
by symmetry, P(card 2 = red) = red left ⁄ cards left — that's why it starts at 2⁄5.
the clue didn't just inform you — it shrank the deck you're computing inside. That's conditioning, next chapter's whole idea.
Fig. 23. Before any clue, P(card 2 = red) just sits at a fixed 40% — 2 red cards out of 5, and by symmetry that's true of any position. Click reveal and learn card 1 is red: the deck you're computing inside shrinks to 4 cards with only 1 red left, and the very same probability jumps to 25%. Nothing about card 2 changed — only what you know did. That's conditioning, and it's the whole next chapter.

Watch that number jump the moment information arrives. That jump is the whole idea waiting in the next chapter. We will shrink the universe down to what we know, re-measure inside it, and discover that the plain multiplication we leaned on all chapter is just the calm special case where the clue tells you nothing. Turn the page.

iolinked.com
Written by Ajai Raj