Flipping a Coin Until You Get Pi
Matt Parker, from the Stand-up Maths channel, recently published a video with a premise as simple to state as it is hard to believe: if you flip a coin repeatedly until heads outnumber tails, and compute the average ratio of heads to total flips... the result is .
Yes, . The number that belongs to circles. Hiding inside coin flips.
In our previous article on Pascal's triangle we saw how a triangle built from simple addition contained, within its rows, the seeds of combinatorics, algebra, and probability. Today we are going to pull on that same thread. And it will take us somewhere no one expected.
The rules of the experiment are straightforward:
- Flip a fair coin repeatedly.
- Stop the moment the number of heads exceeds the number of tails.
- Record the ratio of heads to total flips for that sequence.
The question is: if we repeat this process infinitely many times and compute the average of all those ratios... what do we get?
Before answering, let's think about what range that ratio can take. In the best case, the very first flip is heads: we stop immediately and the ratio is (100% heads). In the worst case, we need thousands of flips before heads finally edges ahead by one, and the ratio will be barely above . So the average must land somewhere between and . Let's find out exactly where.
Building the sequences, step by step
Let's construct the possible sequences starting from the shortest ones. We will use O for heads and X for tails — the same notation we use in our coin flip tool.
Length 1
The shortest possible sequence: flip once, get heads.
We stop. We have 1 heads and 0 tails. The ratio is and the probability of this happening is .
Length 3
If the first flip is tails, we cannot stop. And with just two flips, the best we can achieve is a tie (1 heads, 1 tails) — a tie is not enough, we need heads to exceed tails. So the next possible sequence has length 3:
Tails, heads, heads. The third flip gives us 2 heads versus 1 tails. Ratio: (2 heads out of 3 flips). Probability: . And it is the only possible sequence of this length.
Length 5
This is where things get interesting. We need 3 heads and 2 tails, and the fifth flip (the one that stops us) must be heads. Moreover — and this is the key constraint — at no point before the end can we have had more heads than tails, because if that had happened, we would have stopped earlier.
It is not enough for the sequence to end with more heads than tails; it must be the first time it happens.
How many sequences satisfy these conditions? Only two:
X X O O O
X O X O O
Let's check the first: XXOOO. Counting O as and X as , the running totals are:
Never exceeds zero until the fifth flip. ✅
Now the second: XOXOO.
It returns to zero at the second and fourth flip, but never exceeds it. This is the first time it reaches . ✅
What about OXXOO? Let's see: . The first flip already puts us at : we would have stopped right there. Not valid. ❌
So there are exactly 2 sequences of length 5, each with probability and ratio (3 heads out of 5 flips).
Length 7
The same reasoning applies to sequences of length 7 (4 heads, 3 tails). If you enumerate them all — and trust me, it takes a while — you find exactly 5 valid sequences.
The summary table
| Length () | Heads ratio | Valid sequences | Probability of each |
|---|---|---|---|
| 1 () | 1 | ||
| 3 () | 1 | ||
| 5 () | 2 | ||
| 7 () | 5 | ||
| 9 () | 14 |
Notice the patterns:
- The length is always odd: .
- The ratio of heads is always .
- The probability of each individual sequence is — each of the flips has a one-in-two chance.
But the column that really matters is the number of valid sequences:
Ring a bell?
From manual counting to the Catalan numbers
Those numbers — — have a name. They are the Catalan numbers, one of the most ubiquitous sequences in all of combinatorics.
Their history is itself a story of unexpected connections. The Mongolian mathematician Mingantu (c. 1692–1763), working in China, was the first known person to use them — around the 1730s, in trigonometric series included in his book Ge Yuan Mi Lu Jie Fa. Two decades later, in 1751, Leonhard Euler independently discovered the same sequence in a letter to Goldbach, this time counting the number of ways to cut a polygon into triangles. And nearly a century after Mingantu, the Franco-Belgian mathematician Eugène Charles Catalan (1814–1894) found them again in 1838, while counting the number of ways to parenthesize a product of factors. The sequence bears his name — coined by John Riordan in the 20th century — even though the numbers had been surfacing, in different guises, for over a hundred years before him.
The same sequence, discovered independently across three corners of the world and three centuries, each time in a completely different context. If that pattern sounds familiar... keep reading.
The -th Catalan number is defined as:
where — read " choose " — is the binomial coefficient: the number of ways to pick elements from a set of . In practice, it answers questions like "how many ways can I arrange heads among flips?" We explored this notation in detail in the article on Pascal's triangle.
Let's verify against our data:
A perfect match. The Catalan numbers count precisely how many flip sequences end for the first time with more heads than tails at each possible length.
The connection to Pascal's triangle
There is another way to see why the Catalan numbers appear here. Think of each flip sequence as a path on a lattice: heads moves one step up, tails moves one step down. The total number of paths of length that end one step above zero is the binomial coefficient — an entry in Pascal's triangle. The Catalan numbers count only the paths that never cross above zero before the final step. They are, quite literally, a filtered selection within the triangle — the same tool we used in the previous article to count coin combinations, now with an additional constraint. If you want to explore this connection in more depth, Matt Parker covers it brilliantly in his video.
The infinite series
Back to our table. The contribution of length- sequences to the overall average is:
And the overall average ratio is the sum of all these contributions, from to infinity:
Let's compute the first few terms:
| Contribution | Running total | |
|---|---|---|
| 0 | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 |
With just five terms we are at , slowly approaching . The convergence is slow, but the direction is unmistakable when the number of flips is sufficiently large.
The appearance of arcsine
This is where the magic happens. Let's substitute the Catalan number formula into our series:
When we multiply by , the factor cancels cleanly:
And the series becomes:
Now comes the moment that makes Matt Parker "angry out of sheer disbelief." It turns out there is a classical function in mathematical analysis called the arcsine — the inverse function of sine — whose power series expansion is:
Look familiar? It is exactly our series, multiplied by , with instead of .
If we evaluate at :
And what is ? It is the angle whose sine is , that is, :
Therefore:
This connection was discovered in 2025 by the mathematician Jim Propp. And what makes it extraordinary is not that appears in an infinite series — that is common enough. What is extraordinary is that a series born from a process as elementary as flipping coins turns out to be exactly the same series that defines a trigonometric function.
It is not an approximation or a numerical coincidence — it is an exact mathematical identity.
Of course, that does not make it a practical way to compute . As Propp himself told in the Arxiv paper itself:
To get pi to the accuracy of 3.14, it might take up to one trillion coin flips. This is partially because sequences of coin flips can get really long before heads overtake tails, so much so that the expected value of a sequence's length is infinity! On top of that, you can't flip all the coins at once the same way you can drop needles — the order of heads and tails matters.
Final reflection
In the previous article, we discovered that Pascal's triangle connected combinatorics, algebra, and probability. Three languages for the same story.
Today we have added a fourth character to the plot: the number .
Flipping a coin seems like a purely random process. Pascal's triangle seems like pure arithmetic. The Catalan numbers seem like a curiosity of combinatorics. And seems to belong exclusively to geometry — to circles, to curves, to the continuous world.
And yet, they all end up connected in a single equation.
There is something deeply satisfying about discovering that a new fact about was hiding, all along, behind something as mundane as flipping a coin. And that nobody noticed until 2025.
Mathematics still has secrets. And sometimes, they are closer than we think.
Put the theory into practice: flip a coin online and watch the patterns unfold.