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 π4\frac{\pi}{4}.

Yes, π\pi. 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:

  1. Flip a fair coin repeatedly.
  2. Stop the moment the number of heads exceeds the number of tails.
  3. 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 11=1\frac{1}{1} = 1 (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 12\frac{1}{2}. So the average must land somewhere between 0.50.5 and 11. 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.

O\textbf{O}

We stop. We have 1 heads and 0 tails. The ratio is 11=1\frac{1}{1} = 1 and the probability of this happening is 12\frac{1}{2}.

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:

X O O\textbf{X O O}

Tails, heads, heads. The third flip gives us 2 heads versus 1 tails. Ratio: 23\frac{2}{3} (2 heads out of 3 flips). Probability: (12)3=18\left(\frac{1}{2}\right)^3 = \frac{1}{8}. 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 +1+1 and X as 1-1, the running totals are:

1,  2,  1,  0,  +1-1,\; -2,\; -1,\; 0,\; +1

Never exceeds zero until the fifth flip. ✅

Now the second: XOXOO.

1,  0,  1,  0,  +1-1,\; 0,\; -1,\; 0,\; +1

It returns to zero at the second and fourth flip, but never exceeds it. This is the first time it reaches +1+1. ✅

What about OXXOO? Let's see: +1,0,1,0,+1+1, 0, -1, 0, +1. The first flip already puts us at +1+1: we would have stopped right there. Not valid. ❌

So there are exactly 2 sequences of length 5, each with probability (12)5=132\left(\frac{1}{2}\right)^5 = \frac{1}{32} and ratio 35\frac{3}{5} (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 (2n+12n+1)Heads ratioValid sequencesProbability of each
1 (n=0n=0)11\frac{1}{1}112\frac{1}{2}
3 (n=1n=1)23\frac{2}{3}118\frac{1}{8}
5 (n=2n=2)35\frac{3}{5}2132\frac{1}{32}
7 (n=3n=3)47\frac{4}{7}51128\frac{1}{128}
9 (n=4n=4)59\frac{5}{9}141512\frac{1}{512}

Notice the patterns:

  • The length is always odd: 2n+12n + 1.
  • The ratio of heads is always n+12n+1\frac{n+1}{2n+1}.
  • The probability of each individual sequence is (12)2n+1\left(\frac{1}{2}\right)^{2n+1} — each of the 2n+12n+1 flips has a one-in-two chance.

But the column that really matters is the number of valid sequences: 1,1,2,5,14,1, 1, 2, 5, 14, \ldots

Ring a bell?

From manual counting to the Catalan numbers

Those numbers — 1,1,2,5,14,42,132,1, 1, 2, 5, 14, 42, 132, \ldots — 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 nn-th Catalan number is defined as:

Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}

where (2nn)\binom{2n}{n} — read "2n2n choose nn" — is the binomial coefficient: the number of ways to pick nn elements from a set of 2n2n. In practice, it answers questions like "how many ways can I arrange nn heads among 2n2n flips?" We explored this notation in detail in the article on Pascal's triangle.

Let's verify against our data:

C0=11(00)=1C1=12(21)=1C_0 = \frac{1}{1}\binom{0}{0} = 1 \qquad C_1 = \frac{1}{2}\binom{2}{1} = 1

C2=13(42)=2C3=14(63)=5C_2 = \frac{1}{3}\binom{4}{2} = 2 \qquad C_3 = \frac{1}{4}\binom{6}{3} = 5

C4=15(84)=14C_4 = \frac{1}{5}\binom{8}{4} = 14

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 2n+12n+1 that end one step above zero is the binomial coefficient (2n+1n+1)\binom{2n+1}{n+1} — 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-(2n+1)(2n+1) sequences to the overall average is:

(12)2n+1probability×Cnno. of sequences×n+12n+1heads ratio\underbrace{\left(\frac{1}{2}\right)^{2n+1}}_{\text{probability}} \times \underbrace{C_n}_{\text{no. of sequences}} \times \underbrace{\frac{n+1}{2n+1}}_{\text{heads ratio}}

And the overall average ratio is the sum of all these contributions, from n=0n = 0 to infinity:

Average=n=0Cn22n+1n+12n+1\text{Average} = \sum_{n=0}^{\infty} \frac{C_n}{2^{2n+1}} \cdot \frac{n+1}{2n+1}

Let's compute the first few terms:

nnContributionRunning total
012×1×1=0.5\frac{1}{2} \times 1 \times 1 = 0.50.50000.5000
118×1×230.0833\frac{1}{8} \times 1 \times \frac{2}{3} \approx 0.08330.58330.5833
2132×2×35=0.0375\frac{1}{32} \times 2 \times \frac{3}{5} = 0.03750.62080.6208
31128×5×470.0223\frac{1}{128} \times 5 \times \frac{4}{7} \approx 0.02230.64310.6431
41512×14×590.0152\frac{1}{512} \times 14 \times \frac{5}{9} \approx 0.01520.65830.6583

With just five terms we are at 0.65830.6583, slowly approaching π40.7854\frac{\pi}{4} \approx 0.7854. 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:

Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}

When we multiply CnC_n by n+12n+1\frac{n+1}{2n+1}, the factor (n+1)(n+1) cancels cleanly:

1n+1(2nn)n+12n+1=(2nn)2n+1\frac{1}{n+1}\binom{2n}{n} \cdot \frac{n+1}{2n+1} = \frac{\binom{2n}{n}}{2n+1}

And the series becomes:

Average=n=0(2nn)22n+1(2n+1)=12n=0(2nn)4n(2n+1)\text{Average} = \sum_{n=0}^{\infty} \frac{\binom{2n}{n}}{2^{2n+1}(2n+1)} = \frac{1}{2} \sum_{n=0}^{\infty} \frac{\binom{2n}{n}}{4^n(2n+1)}

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:

arcsin(x)=n=0(2nn)4nx2n+12n+1\arcsin(x) = \sum_{n=0}^{\infty} \frac{\binom{2n}{n}}{4^n} \cdot \frac{x^{2n+1}}{2n+1}

Look familiar? It is exactly our series, multiplied by 22, with xx instead of 11.

If we evaluate at x=1x = 1:

arcsin(1)=n=0(2nn)4n(2n+1)\arcsin(1) = \sum_{n=0}^{\infty} \frac{\binom{2n}{n}}{4^n(2n+1)}

And what is arcsin(1)\arcsin(1)? It is the angle whose sine is 11, that is, 90°90°:

arcsin(1)=π2\arcsin(1) = \frac{\pi}{2}

Therefore:

Average=12π2=π4\text{Average} = \frac{1}{2} \cdot \frac{\pi}{2} = \frac{\pi}{4}

This connection was discovered in 2025 by the mathematician Jim Propp. And what makes it extraordinary is not that π\pi 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 π\pi. 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 π\pi.

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 π\pi 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 π\pi 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.

Did you enjoy this story?

Visit the Blog

Read more stories about coin tosses

"You are what you are today because of the choices you made yesterday, and the choices you make today will make you what you are tomorrow."
— Michael Josephson
© 2026 Flip The Coin App. All rights reserved.
🪙