The Geometric Distribution

Keep rolling a die until you get your first six. Keep buying tickets until you finally win. Pull items off a production line until the first defective one turns up. Every one of these is the same question wearing a different costume: how many tries until it finally works? The number of attempts you make — counting the winning attempt itself — is governed by the geometric distribution.

Each attempt is an independent Bernoulli trial: it either succeeds (probability p) or fails (probability 1-p), with the same p every time. The geometric distribution counts how many of those identical trials you run before — and including — the first success. We write

X \sim \mathrm{Geo}(p),

where X is the trial number on which the first success lands, so X = 1, 2, 3, \ldots — it can be any whole number, because in principle you might be unlucky for a very long time.

Here's the surprising part, which we'll build up to below. Suppose you've already rolled the die twenty times without a single six. How many more rolls should you expect until your first six? Exactly the same as when you started — the die has no memory of your bad luck. The geometric distribution is the mathematics of "starting fresh every time", and it is the only distribution on the counting numbers with that property.

Building the formula

For the first success to land on trial k, exactly one story must happen: the first k-1 trials all fail, and then trial k succeeds. Because the trials are independent, we multiply their probabilities:

P(X = k) = \underbrace{(1-p)(1-p)\cdots(1-p)}_{k-1 \text{ failures}} \cdot\, p = (1-p)^{\,k-1}\, p, \qquad k = 1, 2, 3, \ldots

Read it as: fail k-1 times, each with probability 1-p, then succeed once with probability p. The bigger k is, the more failures you have to string together first, so the probabilities shrink geometrically — each is (1-p) times the one before. That steady shrinking is exactly where the name comes from: the numbers p,\ (1-p)p,\ (1-p)^2 p, \ldots form a geometric sequence.

A quick sanity check: those probabilities should add up to 1, because the first success has to happen eventually. Summing the geometric series,

\sum_{k=1}^{\infty} (1-p)^{\,k-1} p = p \cdot \frac{1}{1-(1-p)} = p \cdot \frac{1}{p} = 1. \;\checkmark

The mean and the variance

If a success happens on a fraction p of trials, then on average you wait 1/p trials for one — a rare event (small p) keeps you waiting a long time. That intuition is exactly right:

E[X] = \frac{1}{p}, \qquad \operatorname{Var}(X) = \frac{1-p}{p^{2}}.

So a fair coin (p = \tfrac12) gives its first head after 2 flips on average; a die's first six (p = \tfrac16) takes 6 rolls on average; and a one-in-a-hundred jackpot needs about 100 tickets. The variance is large when p is small — long waits are not just long, they're also wildly unpredictable.

For independent trials each succeeding with probability p, let X be the trial of the first success. Then:

Worked example 1 — rolling a die for a six

A fair die is rolled until the first six appears, so p = \tfrac16 and 1 - p = \tfrac56. What is the probability the first six comes on the third roll?

P(X = 3) = \left(\frac{5}{6}\right)^{2}\cdot\frac{1}{6} = \frac{25}{216} \approx 0.116.

And how many rolls should you expect to wait for that first six? Straight from the mean, E[X] = 1/p = 6 rolls. Notice the first-six-on-roll-3 probability (0.116) is smaller than first-six-on-roll-1 (\approx 0.167): the single most likely place for the first success is always the very first trial, even though the average wait is much longer.

Worked example 2 — the die has no memory

Let's make the memoryless property concrete. Keep rolling the die (p = \tfrac16). The probability of getting no six in the first n rolls is

P(X > n) = \left(\frac{5}{6}\right)^{n},

because it means n failures in a row. Now suppose you've already rolled 3 times with no six, and you ask: what's the chance you'll need more than 2 further rolls (that is, more than 5 in total)? Using conditional probability,

P(X > 5 \mid X > 3) = \frac{P(X > 5)}{P(X > 3)} = \frac{(5/6)^{5}}{(5/6)^{3}} = \left(\frac{5}{6}\right)^{2} = P(X > 2).

The three wasted rolls have completely vanished from the calculation: your chance of waiting "more than 2 more" is identical to a fresh start's chance of waiting "more than 2". This is the memoryless property, and the geometric distribution is the only distribution on the counting numbers that has it. The die is not "due" for a six — it never was.

See it: the shape of the distribution

The distribution always decays from left to right — every bar is (1-p) times the one before it, so the tallest value is always at k = 1. Drag the p slider and watch the trade-off: a large p gives a tall first bar and a quick collapse (success comes fast), while a small p gives a low, slowly-fading tail (you're in for a long wait).

The curve traces the heights P(X = k) at k = 1, 2, 3, \ldots. However far right you look, the height is never quite zero — there is always some tiny chance of an extraordinarily long run of failures.

Where it shows up

The geometric distribution is the natural model for any "keep going until…" count:

Contrast it with its cousin the binomial distribution: the binomial fixes the number of trials in advance and counts the successes; the geometric fixes the number of successes at one and counts the trials. "Ten flips, how many heads?" is binomial; "flip until the first head, how many flips?" is geometric.