---
title: 'Calculating pi from coin flips (without randomness)'
source: 'https://youtube.com/watch?v=kahGSss6SsU'
video_id: 'kahGSss6SsU'
date: 2026-06-28
duration_sec: 0
---

# Calculating pi from coin flips (without randomness)

> Source: [Calculating pi from coin flips (without randomness)](https://youtube.com/watch?v=kahGSss6SsU)

## Summary

Eight years ago, the creator flipped a coin 10,000 times to study how often it lands on its edge. Recently, a new mathematical discovery revealed that if you flip a coin until you have more heads than tails, the average ratio of heads to total flips converges to π/4. This video uses that fact to calculate π from the old coin-flipping data, explaining the math behind it and showing the Python code used to process the results.

### Key Points

- **New math fact: π/4 from coin flips** [1:28] — The video is about a new mathematical fact: if you flip a coin until there are more heads than tails, the average ratio of heads to total flips is π/4.
- **10,000 coin flips from 8 years ago** [0:08] — The creator flipped a coin 10,000 times eight years ago to study edge landings, and now uses that data to calculate π.
- **Range of average ratio** [3:54] — The range of possible average ratios is between 0.5 and 1, which narrows π to between 2 and 4.
- **Catalan numbers count sequences** [8:33] — The number of valid sequences of a given length is given by Catalan numbers.
- **Connection to arcsin(1)** [13:20] — The series from the coin-flipping process matches the Taylor expansion of arcsin(1), which equals π/2, leading to the average ratio being π/4.
- **Edge landings: 14 times** [16:07] — The coin landed on its edge 14 times out of 10,000 flips.
- **Python code for calculation** [16:43] — The Python code processes the data, calculates the average ratio, and multiplies by 4 to get π.
- **Result: π ≈ 3.2266** [21:24] — The calculated value of π from the data is 3.2266.

## Transcript

[music]
Eight years ago, a younger version 
of me sat down and flipped a coin  
10,000 times. If you're wondering 
why would anyone do that,  
look, we don't welcome those sorts of questions 
around here. But more to the point, I want to see  
how often it would land on its edge. And later on, 
I'll explain why I was doing that, how many times  
it landed on its edge if you want to see if you 
can have a guess. 10,000 flips, how many edges,  
and I have a ridiculous joke collaboration we 
shot, which has never seen the light of day.  
That'll be right at the end of the video. See if 
you can guess who else is involved. But for now,  
we're going to speed forward 8 years to 
when these flips finally became useful.  
That's because of Pi Day. Yes, a few years ago I 
flipped a coin 10,000 times. I don't know what I  
was thinking, but I've finally come up with a use 
for that footage. I'm going to use it this Pi Day.  
So, hey, happy Pi Day 2026. Although, shouldn't 
have said that. Forget [music] it's Pi Day.  
Spoiler. This is not a video about that. 
This is a video about flipping a coin to  
about flipping Thank you. a coin to see 
what the ratio between heads and tails is.
Yes. Late last year, a new bit of math 
dropped relating to if you flip a coin,  
keep track of if it's heads or tails, and you 
stop when there are more heads than tails.  
And let's say you do that over and over. And 
then you ask the question, hang on a second. If  
I stop whenever there are more heads than tails, 
what's the average ratio of all those sequences  
where I compare the number of heads to the 
number of tails? And there's going to be  
more heads than tails, but how many more? And if 
you calculate that and work it out in general,  
turns out, and yes, this is why it's a Pi 
Day video. And look, I'm as angry as you are.  
It's pi. It's pi on four. If you flip a coin until 
there are more heads than tails, the ratio is pi  
on four. So that's what we're going to do. This 
Pi Day, I'm going to calculate pi from my 10,000  
coin flips, which has actually come together quite 
well. Previously, this Pi Day was going to be  
us calculating pi on the moon. You may have seen 
the update about that that went out recently.  
Sadly, like a lot of space missions, it's been 
delayed. So, we can't do that. That would be next  
Pi Day hopefully. Previously, previously, 
there should have been a Pi by hand year.  
I was going to try and break the record. Turns out 
that's going to take longer than I expected. So,  
that's also delayed, but will happen. link in the 
description if you want to sign up for updates.  
So, what I'm going to do is basically go back to 
normal. I'm going to do a standard pi by hand,  
but this time instead of doing long tedious 
working out by hand, I've previously flipped  
a coin 10,000 times by hand. And from that, we 
can extract a value of pi. And unbelievably,  
no one noticed that you get this value of pi on 
four from multiple coin flips until last year.  
And so I'm like, well, this is great. Breaking 
news. So here's what we're going to do. I'm going  
to explain why you get pi when you flip a coin. 
Then we're going to get pi from flipping a coin.  
Let's do it. Right. I'm going to use these to 
represent a sequence of heads and tails. We  
can kind of arrange them across here. 
And actually before we even start,  
we've got a pretty tight range on what the average 
ratio can be. Because the highest it can be is if  
boom, straight out of the gate, you flip a heads. 
You've now got more tails than heads as required  
and it's 100% 100% heads. It's the highest 
possible ratio. Or we could have like, you know,  
thousands of flips before eventually we have 
more heads than tails. And when that happens,  
it will have just because there's so many just 
gone over 50%. So really our range is 0.5 to one.  
Because we're calculating pi on four, 
it means we've already narrowed pi down  
to between two and four, which you know, compared 
to some historic pi days, we're doing pretty good.  
Now, what if we didn't get head straight 
away? What if the very first flip was tails?  
Well, now we're going to have to keep going. 
And the shortest sequence it could be now is  
three flips. It can't be two because 
the best case scenario is we get heads,  
right? And but now it's 50/50. Has to be more 
has to be greater than 50%. So potentially  
another heads. So now that's the Whoops. Shortest 
sequence where it goes tails, heads, heads, stop.  
And that's a well, I guess that's a a half time a 
half times a half. That's a half cubed probability  
of happening. And the ratio is two out of three. 
But what if we didn't get that second heads?  
The next shortest would be five flips. So 
for us to keep going in the first place,  
that would have to be tails there. Okay. And then 
the next one will Oh, it has to be two more heads,  
right? Cuz we need to get it needs to be three 
out of five heads for us to stop after five.  
So it would look like that. There it is. Okay. 
Next shorter sequence is five. It ends on when  
we flip this heads. And that's the one that 
tips us over to more heads than tails. So the  
probability of this sequence happening half times 
a half times over five of them half the power of  
five. We can add that in and the ratio is 3 out of 
five. Great. So we've Oh, hang on. Wait a minute.  
Yeah, this one works. But so does so is this 
one. That's also a perfectly valid sequence.  
That's five long and would end at the same 
point exactly when we flip that one. So there's  
I'll pick that up later. There's I can replace 
it. So there's there's two of them. Okay, so now  
for each run of coins, we need the probability, we 
need the ratio, and we need how many options there  
are. So we multiply this one by two. Let's have 
a go at seven. Right, I've set us up seven spots,  
and we're going to think about what sequences 
could possibly end at the seventh flip. And  
by end, it means that has to be us flipping a 
head because that's the point at which we have  
more heads than tails and we stop. And at no point 
before then can we have had more heads than tails  
otherwise we would have stopped including the very 
first flip. There has to be a tails otherwise we  
would have stopped on the heads. The second one 
could be heads or tails. We'll come back to that.  
Let's start by the case where we flip three tails 
first. So tails are way out in front and then  
heads come slamming back and they get it right at 
the end because four out of seven is the point at  
which this one means we've got more heads and 
tails. So that's one. Write that down. However,  
this third tails here, that could happen later. 
We could have that one was a heads and that one  
was a tails. That would work nicely. We can move 
it further. That's two. If you're counting, we can  
move it down again. That could be uh heads. That 
could be the tails. We can't do it again, however,  
because if this was heads and that was tails, 
it doesn't work because we've already now look  
at that. Two tails, three heads, we would have 
stopped. So, we only get those two extra ones.  
So, now we're up to uh three alto together. Now, 
the other case was if that was a heads there.  
Now, if that's a heads, this one can't 
be heads cuz otherwise we'll have more  
heads than tails. It's got to be tails like 
that. And then that's still heads over there.  
And then these can go either way. This is either 
a heads than a tails or it's a tails than a heads.  
Both of those work. You can't delay it any 
longer. So, that that's five. If you want to  
pause and go through that yourself, you're very 
welcome to. I spent a long time in my notebook,  
which I'm pointing down here because I've still 
got all my This was me trying to work it out  
the other night, and I got all these sketches 
of me going through being like, "Oh, what do I  
get in the sequence of heads and tails and tails 
and heads? There's my there's me counting five,  
and I was right." So, I was able to fill that into 
the table. And the next one, we could do it for  
nine. There's 14 ways to do it. I didn't bother 
working that out. I put the sequence of 125 into  
the online encyclopedia of integer sequences and 
it was all like, do you mean the Catalan numbers?  
And I was like, turns out I do. So why the 
Catalan numbers? Well, to get my head around it,  
I then drew a diagram which I'm going to recreate 
for you very quickly here on my whiteboard  
where I thought, you know what? Let's represent on 
a kind of tree diagram. If you get a tails, you go  
down. If you get a heads, you go up. I had to roll 
that in around the dog so I didn't hit the dog.  
And the goal is to end up above water. Very 
simple. So, you start here on the surface  
and then if your first flip is a heads, you're 
high and dry, you stop. If it's a tails,  
you're down here. To clarify, when 
I mean above water, we stop flipping  
once we're one above this blue line. Because 
if tails moves us down and heads moves us up,  
being one above our starting point means we've 
now had more heads than tails. And then I just  
expanded the tree diagram because the next 
one would bring you back up to the surface.  
This one would bring you even further below the 
surface. Then you've got a chance to get out here  
heads. And there's only one way that that's 
one way to do that. There's one way to do that,  
but there are multiple ways. If you go up here 
next or down there and then up there and then out,  
then if you count that, you're like, "Oh, actually 
there's two ways because I could have gone all the  
way down and all the way back and out or down, up, 
down, up and out." And so if you start building up  
this diagram of all the ways you can flip 
heads and tails and all the places you can end  
up and all the times that you break the 
surface and escape and then you got to  
count the number of paths. Ah, you know what this 
is reminding me of. But if we flipped it over,  
it's Pascal's freaking triangle. If you'd like 
to learn more about Pascal's triangle and the  
Catalan numbers, my friend Sophie Mlan already 
has a fantastic number file video all about it. I  
highly recommend you check that out. And it works 
very neatly because Pascal triangle is effectively  
counting the number of ways you can get to any 
given point. And we can use the Catalan numbers  
to normally cross over in the middle. Ah, it's 
all it's really nice. Check out Sophie's video.  
But for our purposes, we're just going to 
use the fact that the Catalan numbers counts  
the number of possible head or tail sequences. 
Right now we're going to put it all together.  
So we can take our table from before and put it 
into a generalized form. Catalan numbers start at  
n equals 0. The zeroth Catalan number which is 
1. So we're going to use counting from zero.  
And the formula in general is going 
to be 1 / 2 to the power of 2 n + 1  
multiplied by the nth Catalan number multiplied 
by n +1 over 2 n + 1. That's just what we had in  
the table. But now you put in whatever value of 
n and you get the next term in the series. And so  
we want to sum these from n equals z up infinitely 
many of them. Then we get some result. And we do.  
I wrote down here last night. You can see there 
was my terrible attempt at that tree diagram. Um,  
and over here next to it, I've written the formula 
for the catland numbers. 1 / n +1 multiplied  
by 2 n choose n. And you can put that in terms 
of factorials. We just substitute that in.  
And now we have one big chunky equation that 
gives us each of the terms from n equals z  
all the way up. We just got to work out how we 
turn that into pi. Okay, now we just need some  
kind of substitution or a way to rearrange 
this to get closer to pi. What's that noise?  
It's arc sign. It's the inverse 
function of sign that can be written  
as a series. Look at that. Isn't that amazing? I 
mean, okay, look, here's the thing. I can't derive  
everything from first principles. It'll be a very 
long and I'm aware of the things I'm about to say  
boring video. So at some point you've just got to 
take something on faith and we're going to use the  
series expansion of aride. If you want to look 
up how it's done, you can. In fact, it involves  
binomials and once again Pascal's triangle. Lovely 
bit of mathematics. That's now your problem. All  
I'm saying is doesn't that look similar? In fact, 
instead of ark sine of x, we could do ar sign of  
one. Just put that in. Why not? And that means the 
x becomes one. That whole thing vanishes. And it  
looks pretty much exactly like what we had before. 
In fact, it's just twice as big. It's two times  
whatever the average ratio of heads to tails is 
in our previous calculation. And what's the arc  
sign of one? The inverse sign of one. What value 
gives you one when you put it in sign? It's 90°.  
It's pi on 2. So pi on 2 equals twice the average. 
The average is pi on four. It's still making me  
angry. I mean, here's the thing. We're not 
surprised that if you flip a coin lots, the  
dogs come over to see why I'm getting emotional. 
Uh, we're not surprised that stopping lots of  
different length sequences of flips and adding 
them together gives us a series. That's what  
we'd anticipate and we're not surprised that you 
can represent pi with an infinite series. That's  
classic pi. But I expect them to be separate 
things. What stuns me is that one of the series  
for pi happens to match a series for flipping a 
coin. It's ridiculous. I'm not happy about it.  
Thank goodness I got my therapy dog right here. 
Oh, who's a good dog? This ridiculous pi coin fact  
was discovered last year by a mathematician I know 
named James prop. And James is going to put up a  
blog post for this pi day going through all the 
mathematics behind it. So I'll link to that below.  
You can check it out if you want to go through 
the detail. It's even a bit of calculus in there  
if you're into that kind of thing. But 
for me normally my problem would be oh I'm  
like a such a good fact. I need to do a thing 
for pi day. I could sit here and flip a coin  
over and over and over again and calculate pi by 
hand. But this time, I don't have to because it  
turns out it's already been done by my longtime 
collaborator, past Matt. So, here's why past Matt  
was flipping a coin 10,000 times. I've had this 
longunning project in my creator calculate how  
thick a three-sided coin would have to be, which 
is a coin where it's equally likely to land heads,  
tails, or edge. And I've talked about this 
before. or it's been on hold for a long time,  
but I found the current state-of-the-art. 
But I realized the state-of-the-art was a  
single paper. In fact, to this day, if you go to 
Wikipedia and look at the entry on coin flipping,  
the one citation for landing on edge is the 
paper probability of a tossed coin landing on  
edge from 1993. So, I thought I would recreate 
their experiments and I'll do my own experiment  
in an attempt to investigate that. 
Now, I never got around to analyzing  
the data. I did recreate their experiment by 
sliding the pound coin, which is what they used,  
off a horizontal surface a thousand times. Then, 
I did my own 10,000 flips. I'll link to it below  
if you want to have a look at the data. You can 
analyze it yourself. Uh the big reveal 14 times  
landed on its edge 14 times. Now this whole 
experiment was a complete waste. It became  
a whole section in my book humble pie. But the 
footage the footage I never had a reason to use  
until now. Until I wanted to calculate pi. 
So here's my big spreadsheet of data. I'll  
link to this below if you want to check it out 
for yourself. It's got the exact time I flipped  
every single coin. Wow, that was a late night. 
And then over here, started heads, landed heads,  
every single landing one. And that's just my kind 
of count count if 14 edges. Ah, good times. Now,  
we need to analyze this, which means we got 
to get into Python. And I thought it might be  
fun to write the code. So, all I'm doing here is 
I'm using open py. That's Python for Excel files.  
I've I've I've set up the name of the file and 
everything. We want to count how many sequences  
we've been through and that starts with 
zero of them. I try to have remotely  
useful names. That's also zero. And then for each 
one, we need to count two things. How many heads  
and how many flips? What are 
we going to do with edges?  
Let's ignore them. [laughter] Let's say they 
don't they don't count. They don't count. It's  
got to be heads or tails. Lowerase H or T. So what 
we'll do now is if the flip result equals heads  
then we increment head count. So that goes up by 
one. And then if flip result doesn't equal e then  
that's our total number of flips. Okay. So, all 
I've done there is each time we flip it, if it's  
heads, we add to the running head count. If it's 
not edge, we add to the running total number of  
flips count. Great. Now, we got to check if we've 
hit the end of a sequence. So, if that happens,  
we want to work out the ratio of heads to tails in 
that run. So, we're going to say this ratio equals  
uh headcount divided by flip count. I could 
do all this in one big long chunky line.  
I like to split things out because it makes my 
life a little easier to try and read it. So,  
I'm going to take running ratio total add on 
this ratio. And we've had one more sequence.  
So, uh what do we call our sequence count? Count 
sequences. Well done. Pass mat always there for  
me. So, we add one onto that. Now, we want to 
reset cuz we're going to start another run. So,  
flip count and head count now get set back to 
zero. Okay, that should be everything. Oh, that's  
I can't increment flip result. That's 
what I It's flip count. What a dingus.  
Okay, that fixed. I kind of want to check it's 
working before we get the big result. Let's run  
it first without calculating the result. That's 
the big reveal. Each time we'll print the result  
and then down here we'll print what we think 
the ratio was. Okay, so now we can run it.  
It'll do that for all 10,000 flips. make sure it 
functions and make sure it's doing what we expect.  
You never know with code. It's like if you just 
run it without making sure you've gone through to  
make sure everything's working properly. It's 
a very opaque process which makes me nervous.  
Ah. Oh, there it is. It ran. Oh, these 
are long runs. Oh, okay. It is working.  
So, that was a super long run. Look at it. And 
when it finally ended, it was just over a half.  
Next one was a heads. So, it was one heads was 
one. So this was a total of 1 2 3 4 5 6 7 8 9  
10 11 flips of which one two three four five six. 
So yeah, so it was five and five. One more heads  
tipped it over to six and five. It stopped and 
ratio 54.54%. Okay, I'm happy the code is working.  
I'm going to undo that one. Now once 
it finishes running, let's just print.  
Should we do it all at once? Should we just print 
pi? Let's just print pi. You know what? Let's do  
pi val equals running ratio total divided by count 
sequences. So that's the total of all the ratios  
divided by how many there are. That gives us 
the average. And then we multiply that by four.  
And then we print pi val. So this is it folks. 
This is the value of pi for pi day 2026.  
We're going to zoom. Let's get right in. I know 
that's messy, but I want a big number. Okay.  
Ready? Okay. Here we can't see producer Nicole is 
just out of shot over there. Very excited. Camera  
person Alex is over there wildly indifferent. 
And now we run the code. 3.2266. [music]
That's better than I was braced for 
cuz it converges so slow. Wow. 3.2266.
For everyone who keeps a running record of 
my successes and failures, write that down.  
That's good stuff. Obviously, while I was 
flipping a coin 10,000 times, I had a bit of fun.  
did some ridiculous bits to camera and then I 
thought, you know what? Why don't I try this  
in a fake collaboration where a coin 
unexpectedly keeps landing miraculously  
on its edge. In a previous video, I said there 
was a trivial chance when you flip a coin  
of it landing on its edge. And even though you 
can balance a coin on its edge, it's a common  
misconception that that can happen when it's 
in motion. If you actually flip a real coin,  
it lands on a physical surface. It will 
never land on its edge. And to prove why  
that's impossible, you need some very nice 
mathematics, some interesting physics,  
and some things you might not know. The first 
step, however, is just to actually flip a coin and  
take a close look at what happens. If you watch 
what actually happens when you what? Oh, come on.
Okay. Okay. All right. Okay. About about the 
collaboration. I got it. It landed on its edge.  
No, you didn't. No. Seriously. Seriously. I 
flipped it. That's not possible. First take  
I landed on its edge. Is we pro? We No, I know. I 
know. I know what we proved, but I'm just saying  
it happened. Do it again. There's no Look, 
there's no way. What? You You show me then.
See? No. Yes. Wait. No. Yeah. I don't 
care what your physics says. It can't  
happen. I know. I know. But I did 
it again and it's bang on the edge.  
Okay. You're kind of the worst 
time. It's ended on the edge.  
I've got some terrible news about our collab. 
[laughter] It's been literally minutes.
See you later.
Yes, Steve Mold and Tom Scott did stand around 
waiting for as long as it took for me to get that  
coin to land on an edge. Absolute legends. Sorry 
it took me 8 years to get it out, folks. Uh but  
here we are. And now back to Modern Matt for the 
final wrap-up. And we're done. Ah, it's so great.  
2026 literally 26 in the digits of pi. So write 
that down for the next 12 months. Pi equ= 3.2266.  
Ah, fantastic. Now, some updates for the people 
who watch right till the end of the video. Yes,  
we will do pi by hand again. We've done some 
testing. We got a new method. We've done a bunch  
of research. We got a whole team on it. It's going 
to take it's going to take so many people for so  
long. I'm going to need so many volunteers that 
are all prepared to sit there for a while. And we  
haven't really got a plan for that. We're trying 
to work out the best way to do it. If Moonpie is  
a success on the first launch, the leftover 
funding from that will go into Pi by hand,  
which means we can probably do it at the scale 
it requires. I promise I will give you at least  
12 [music] months warning if you want to come 
along and be part of the pie by hand calculation.  
Link in the description for the sign up form. 
I will keep you in the loop and I will tell you  
more than a year in advance when we're going to 
attempt it. So don't panic. You will be there.  
Moonpie, the update is out. That's a lot of fun. 
Go check it out. Link to it below. Hopefully we  
will launch um at some point this year. Um we'll 
see what happens. Uh and [music] just in general,  
thanks for watching the videos. Oh my goodness. 
This is a wonderful tradition calculating pie.  
And I couldn't have done it without Passmat. 
Big thanks to Passmat. Um thanks to Sophie Mlan  
for all things Catalan numbers. Jim Prop for 
discovering this ridiculous thing. I'll check out  
uh I'll link his blog post. You should check that 
out. Uh, and of course, Steve Mold Tom Scott for  
for waiting for a ridiculous amount of time for 
a dumb joke that I didn't release for 8 years.  
That's a pretty accurate representation of what 
it's like um to be friends with me. Um, so that's  
it. Thanks. Thanks for supporting the videos. 
Thanks for everyone on Patreon. Uh, you know,  
I feel like Pi Day is like uh end of one year. 
You know, you get like financial years and school  
years. I run on pi years. So, that was the end of 
the 2025 2026 Pi Day season and now we're going to  
go uh into the next one. And so, um that's it. So, 
I guess we don't need this coin until next time.
Oh, no. [laughter] Oh. Oh, that's so unfair.
