P ProbLab
Tools/Coin Flip Sequence Analyzer

Coin Flip Sequence Analyzer

Compute the probability of any specific sequence (e.g. HTHTHT), the expected length of the longest streak in N flips, and visualize the underlying Markov chain. Includes a gambler's-fallacy debunker at the bottom.

Setup

Advertisement

Key results

Markov chain (transition diagram)

Two states: previous flip was H or T. Each transition has probability ½. The chain is memoryless except for the previous state.

Streak probability table

Streak length kP(at least one streak ≥ k)

Why this tool exists

"What are the odds of getting 5 heads in a row?" is one of the most-Googled probability questions on the internet. Most answers are wrong or misleading — they either ignore dependence (each flip is independent) or compute the wrong event ("5 heads in 5 flips" vs "5 heads in a row anywhere in N flips"). This tool computes the right thing and shows why the gambler's fallacy fails.

Who uses it

  • Educators teaching the difference between independent trials and conditional probability.
  • Sports bettors checking "streak" claims in team performance.
  • Anyone who's argued with a friend about whether 5 heads in a row is "due" to flip tails next.

How to read the output

For N flips, "P(at least one streak ≥ k)" is the chance that somewhere in those N flips there's a run of k or more identical outcomes. Expected longest streak is roughly log₂(N) − 1 for fair coins, so in 100 flips the expected longest streak is about 5–6, and in 1000 flips it's about 8–9.

Limitations

  • Pattern matching uses the exact Markov-chain analytical formula; we do not enumerate for N > 1000 to avoid floating-point blow-up.
  • "At least one streak" treats H and T runs symmetrically — for biased coins this tool does not apply.

Gambler's fallacy, formally

If you have just observed 5 heads in a row on a fair coin, the probability the next flip is heads is still exactly ½. The sequence of 5 heads has probability (½)⁵ = 1/32 ≈ 3.1%, which is rare but not rare enough to "balance out". To balance out, you'd need to flip about 32 more heads to make the long-run ratio 50%, but that's not how individual flips work. The Markov chain here shows exactly this: the next state depends only on the previous flip, not on the streak history.