CoinFlipFree

We flipped a coin 1,000,000 times

A real experiment with real numbers: the split, the streaks and the surprise about who was usually ahead.

A gentleman in a bowler hat points at a giant coin flipping through the air
A coin toss gives each side exactly the same chance.

What we did

We wanted to check the claims we make about coin flips against real data, so we ran an experiment. Using Python's secrets module, which draws from the operating system's cryptographic random source, we generated one million virtual coin flips. We recorded the totals, every streak and the running lead. We then ran a second experiment of 20,000 separate sessions of 100 flips each. The code for the main run is only a few lines long:

import secrets

N = 1_000_000
raw = secrets.token_bytes(N // 8)           # 125,000 random bytes
bits = [(b >> i) & 1 for b in raw for i in range(8)]   # 1 = heads
print(sum(bits), N - sum(bits))

This is a software experiment, not a physical one. A real coin flipped by hand has a tiny bias, as we explain in is a coin flip really 50/50?. The digital coin has none, so it is a clean test of the pure maths. The numbers below come from a single saved run, and we checked every figure a second time with separate code. If you repeat the experiment your exact figures will differ, but the patterns will be the same.

Result 1: the split is almost exactly 50/50

Out of 1,000,000 flips there were 500,445 heads and 499,555 tails, which is 50.044% heads. The gap between them was 890 flips. For a million fair flips the difference between heads and tails typically lands somewhere around a thousand either way, so a gap of 890 is entirely normal.

Result 2: the percentage settles, but the gap does not shrink

Many people believe that if you get too many heads early on, tails will "catch up". Here is how the running totals looked at each stage:

FlipsHeadsHeads %Heads minus tails
10550.0%+0
1005050.0%+0
1,00049949.9%-2
10,0004,97449.74%-52
100,00050,22150.221%+442
1,000,000500,44550.044%+890

The percentage moves towards 50% as the number of flips grows, which is the law of large numbers at work. But look at the last column. After 100,000 flips the gap between heads and tails was 442 flips, and after a million flips it was 890. The raw gap did not "correct" itself, and it can even grow. What shrinks is the gap as a share of the total, which is why the percentage still gets closer to 50%.

Result 3: long streaks are normal

There were 499,623 separate runs of heads or tails in the million flips. The longest was 20 heads in a row, starting at flip 233,307. That sounds extreme, but it is right in line with the maths: the longest run in a sequence of flips is typically close to the base-2 logarithm of the number of flips, which for a million flips is about 20. Here is how many runs of each length we saw compared with what theory predicts:

Run lengthRuns seenExpected
1249,477250,000
2124,537125,000
363,10762,500
431,37331,250
515,57215,625
67,8917,812
73,7643,906
81,9581,953
9971977
10490488
11255244
12113122

The match is very close. Each time the run length goes up by one, the number of runs roughly halves, exactly as it should. You can explore these odds yourself with the coin flip odds calculator.

Result 4: one side is usually "ahead" for most of the run

This is the surprise. If you track heads minus tails flip by flip, you might expect each side to lead about half the time. It does not work like that. In our run heads was ahead for 96.4% of the million flips, and the lead changed hands just 96 times in total. Heads' biggest lead was 976 flips, while its deepest deficit was only 153.

0 (equal heads and tails)01,000,000 flips
Heads minus tails over one million flips, sampled every 5,000 flips. Above the dashed line, heads is ahead.

This is a known feature of random walks: long periods when one side leads are far more common than frequent swaps. In a different run it could just as easily have been tails that led for most of the time. Neither side has any advantage on any single flip, yet one side can stay ahead for most of the experiment. It is another reason why a coin feels "streaky" even when it is perfectly fair.

Result 5: what 100 flips looks like

Most of us flip a coin a handful of times, not a million. So we also ran 20,000 sessions of 100 flips and recorded the longest streak in each session:

Longest streak in 100 flipsSessionsShare
4 or fewer5542.8%
53,26816.3%
65,25926.3%
74,56022.8%
82,88614.4%
9 to 102,60613.0%
11 or more8674.3%

The average longest streak was 6.99 flips. In 97.2% of sessions there was a run of 5 or more, in 80.9% there was a run of 6 or more, and in 54.6% a run of 7 or more. If you flip a coin 100 times and see six heads in a row, that is not suspicious. It is the most likely thing to happen.

What this means for you

Try it yourself

Flip your own coin on our flip a coin page, where the stats box tracks your totals, percentages and best streak. See the coin flip probability chart for the exact odds of any run of heads or tails.

More free tools