Probability That You Have the Bad Coin

Probability · Medium · Free problem

You have 1000 coins in a bag. One of them is a "bad" coin that always lands heads. The other 999 are fair coins with $P(H) = 0.5$. You draw one coin uniformly at random and start flipping it.

  1. After flipping 10 heads in a row, what is the probability you are holding the bad coin?
  1. What if you had only flipped 9 heads in a row?
  1. How many consecutive heads do you need to see before you can be at least 95% confident you have the bad coin?

Hints

  1. Think about the problem in terms of odds ratios. What are your prior odds of holding the bad coin versus a fair coin, and how does each observed head update those odds?
  2. Each consecutive head multiplies the likelihood ratio by
$ (since $P(H \mid \text{bad}) / P(H \mid \text{fair}) = 1/0.5 = 2$). After $k$ heads the posterior odds are ^k : 999$.
  • The posterior simplifies to $P(\text{bad} \mid kH) = 2^k / (2^k + 999)$. For $k = 10$, note that ^{10} = 1024 \approx 999$, so the posterior is near
    /2$.
  • Worked Solution

    How to Think About It: You picked a coin at random, so your prior on holding the bad coin is

    /1000$. Each consecutive head you flip should make you more suspicious. The key question is: how quickly does the evidence pile up? A fair coin flips 10 heads in a row with probability
    /2^{10} = 1/1024$, which is almost exactly
    /1000$ -- suspiciously close to your prior odds against the bad coin. So after 10 heads, you should expect the posterior to be right around 50-50. That is the quick intuition before doing any algebra.

    Quick Estimate: The prior odds of bad-to-fair are

    : 999$. Each head multiplies the likelihood ratio by
    / 0.5 = 2$. After $k$ heads, the odds become
    ^k : 999$. For $k = 10$:
    024 : 999 \approx 1 : 1$, so roughly even odds -- about 50%. For $k = 9$: $512 : 999 \approx 1 : 2$, so about 33%. For 95% confidence, you need
    ^k / 999 \geq 19$ (since 95/5 = 19), giving
    ^k \geq 18981$, so $k \geq 15$ (since
    ^{14} = 16384 < 18981 < 32768 = 2^{15}$).

    Formal Derivation: Apply Bayes' theorem. Let $B$ denote the event that the coin is bad and $kH$ denote $k$ consecutive heads.

    $P(B \mid kH) = \frac{P(kH \mid B)\,P(B)}{P(kH \mid B)\,P(B) + P(kH \mid \text{fair})\,P(\text{fair})}$

    Since $P(kH \mid B) = 1$ and $P(kH \mid \text{fair}) = (1/2)^k$:

    $P(B \mid kH) = \frac{\frac{1}{1000}}{\frac{1}{1000} + \frac{1}{2^k} \cdot \frac{999}{1000}} = \frac{1}{1 + \frac{999}{2^k}} = \frac{2^k}{2^k + 999}$

    Part 1 ($k = 10$):

    $P(B \mid 10H) = \frac{1024}{1024 + 999} = \frac{1024}{2023} \approx 0.506$

    After 10 heads, you are just barely more likely than not to have the bad coin -- about 50.6%.

    Part 2 ($k = 9$):

    $P(B \mid 9H) = \frac{512}{512 + 999} = \frac{512}{1511} \approx 0.339$

    After 9 heads, you are only about 34% confident -- not enough to call it.

    Part 3 (finding the threshold for 95% confidence): Set $P(B \mid kH) \geq 0.95$:

    $\frac{2^k}{2^k + 999} \geq 0.95 \implies 2^k \geq 0.95(2^k + 999) \implies 0.05 \cdot 2^k \geq 0.95 \cdot 999$

    $2^k \geq \frac{0.95 \times 999}{0.05} = 18981$

    Since

    ^{14} = 16384$ and
    ^{15} = 32768$, you need $k \geq 15$. At $k = 15$:

    $P(B \mid 15H) = \frac{32768}{32768 + 999} = \frac{32768}{33767} \approx 0.970$

    Interpretation: The posterior depends on the interplay between two quantities: your prior odds (

    /999$ against the bad coin) and the likelihood ratio per flip (
    :1$ in favor of bad). Each head doubles your odds. At 10 heads the likelihood ratio ( ^{10} = 1024$) roughly matches the prior odds against ($999$), so the posterior lands near 50%. Getting to high confidence requires the likelihood to overwhelm the prior by a factor of 19 or more, which takes 15 flips.

    Answer: After 10 heads: $P(B) = 1024/2023 \approx 50.6\%$. After 9 heads: $P(B) = 512/1511 \approx 33.9\%$. You need at least 15 consecutive heads for 95% confidence ($P(B) \approx 97.0\%$).

    Intuition

    This problem is a clean illustration of how Bayesian updating works through the odds form of Bayes' rule. Your prior odds are

    :999$ against the bad coin, and each observed head multiplies those odds by 2. The posterior only crosses 50% when the cumulative likelihood ratio (
    ^k$) exceeds the prior odds against ($999$) -- and since ^{10} = 1024 \approx 999$, it takes about 10 heads just to reach even odds. This is why 10 consecutive heads from a fair coin is not as shocking as it sounds when you have 999 fair coins in the mix.

    In practice, this same structure appears whenever you are trying to detect a rare signal in noisy data -- a rogue trader, a biased instrument, or an informed counterparty. The lesson is that even strong per-observation evidence (a 2:1 likelihood ratio) accumulates slowly against a steep prior. You need roughly $\log_2(\text{prior odds against})$ observations just to reach 50-50, and several more to reach high confidence. Understanding this tradeoff between prior rarity and evidence accumulation rate is central to quality control, anomaly detection, and market-making with adverse selection.

    Open the full interactive solver →