DigitHelm

Coin Flip Simulator | Heads or Tails Online

Free online coin flip simulator with animated flip, adjustable bias (0–100%), batch flipping up to 100,000 times, live statistics (z-score, chi-square, streak tracking), flip history grid, and session persistence. Demonstrates the law of large numbers in real time.

Press Space or tap Flip to start

Flip simultaneously

Coin Bias

P(H) = 50%P(T) = 50%
Always TailsAlways Heads

Space flip · 1 ×10 · 2 ×100 · 3 ×1000 · Esc reset

What Is the Coin Flip Simulator | Heads or Tails Online?

This coin flip simulator goes far beyond a simple heads-or-tails generator. Every flip is computed using a cryptographically seeded pseudorandom number generator, and the simulator tracks your entire session, streaks, percentages, and statistical tests, so you can actually see probability theory in action rather than just reading about it.

  • Adjustable bias, slide the probability from 0% to 100% to model unfair coins and observe how expected value shifts accordingly.
  • Batch flipping, flip ×10, ×100, ×1000, or any custom count up to 100,000 in a single click to accelerate the law of large numbers.
  • Live statistics, z-score and chi-square test update after each batch so you can see exactly when deviations become statistically meaningful.
  • Streak tracking, current and all-time longest streak are tracked, so you can verify how common long runs really are.
  • Flip history grid, last 60 results shown as colored squares for instant visual pattern recognition.
  • Session persistence, your flips, streaks, and settings are saved automatically in your browser and restored on your next visit.

Formula

Single Flip Probability

P(Heads) = p    P(Tails) = 1 − p    (fair coin: p = 0.5)

Binomial Probability, exactly k heads in n flips

P(X = k) = C(n, k) × pᵏ × (1 − p)ⁿ⁻ᵏ

Expected Value & Variance

μ = np     σ² = np(1 − p)     σ = √(np(1 − p))

z-score (how far from expected)

z = (Observed Heads − μ) / σ = (H − np) / √(np(1 − p))

Chi-Square Fairness Test

χ² = (H − np)² / np + (T − nq)² / nq

SymbolNameDescription
nNumber of flipsTotal coin flips in the experiment
kHeads countNumber of heads observed, the event being measured
pHeads probability0.5 for a fair coin; adjustable to 0–1 in the simulator
qTails probabilityq = 1 − p; for fair coin q = 0.5
μExpected headsMean heads expected over n flips: μ = np
σStandard deviationSpread of outcomes: σ = √(np(1−p))
zz-scoreStandard deviations away from the expected mean
χ²Chi-square statisticMeasures deviation from expected frequencies
C(n,k)Binomial coefficientNumber of ways to choose k successes from n trials

Key Probability Values for a Fair Coin

P(all heads in 5 flips) = 0.5⁵ = 1/32 ≈ 3.1%

P(all heads in 10 flips) = 0.5¹⁰ = 1/1024 ≈ 0.098%

P(streak of 6+ heads) ≈ 1.56% (in 100 flips)

P(exactly 50 heads in 100) = C(100,50) × 0.5¹⁰⁰ ≈ 7.96%

P(45–55 heads in 100 flips) ≈ 72.9%

How to Use

  1. 1
    Set the probability: Leave the slider at 50% for a standard fair coin, or drag it left/right to simulate a biased coin, useful for modeling loaded dice or unfair games.
  2. 2
    Choose how many to flip: Click Flip Once for a single animated flip. Use ×10 / ×100 / ×1000 for batches, or type any number up to 100,000 in the custom field and press Flip.
  3. 3
    Read the distribution bars: The heads and tails progress bars update in real time. On small samples, large imbalances are normal. As you approach hundreds of flips, the bars converge toward 50%.
  4. 4
    Check the statistical analysis: After 10+ flips the panel shows: expected heads (μ = np), standard deviation, z-score (how many σ away from expected), and a chi-square fairness test. A z-score between −2 and +2 is normal. See the z-score calculator for deeper analysis.
  5. 5
    Copy or reset: Use Copy Results to capture all statistics as plain text. Click Reset All to clear everything and start a fresh experiment.

Example Calculation

Example 1, Fair coin, 100 flips

Suppose after 100 flips you observe 56 heads and 44 tails. Is this unusual for a fair coin?

n = 100, p = 0.5, H = 56

μ = np = 100 × 0.5 = 50

σ = √(100 × 0.5 × 0.5) = 5.00

z = (56 − 50) / 5 = 1.20 → Normal variation

χ² = (56−50)²/50 + (44−50)²/50 = 0.72 + 0.72 = 1.44 (p ≈ 0.23, not significant)

Conclusion: 56 heads in 100 flips is well within normal variation, you would expect results this extreme about 23% of the time with a fair coin.

Example 2, Biased coin experiment (70% heads)

Set the bias slider to 70%. After 50 flips, expected results:

n = 50, p = 0.7

Expected heads: μ = 50 × 0.7 = 35

Std deviation : σ = √(50 × 0.7 × 0.3) = 3.24

68% of runs will land in [31.76, 38.24] heads

95% of runs will land in [28.52, 41.48] heads

Example 3, Probability of a streak of 7 heads

P(7 consecutive heads) = 0.5⁷ = 1/128 ≈ 0.78%

Expected wait time = 2⁷ = 128 flips until first streak of 7

P(at least one streak of 7 in 200 flips) ≈ 60%

This explains why long streaks feel surprising but are actually common in extended coin flip experiments. Use the simulator to verify, flip 200 times and check the longest streak displayed.

Understanding Coin Flip Simulator | Heads or Tails Online

The coin flip is the simplest model of a random binary outcome, it underpins some of the most important ideas in probability theory, statistics, and decision science. Understanding what a "50/50 chance" actually means in practice, and why results deviate from it in short runs, is one of the most practically useful things anyone can learn about probability.

The Law of Large Numbers

The law of large numbers states that as the number of trials increases, the sample mean converges to the theoretical mean. For a fair coin, this means the percentage of heads approaches 50% as n grows, not because the coin "remembers" past results, but because the noise of individual variation becomes proportionally smaller. Try flipping 10, 100, then 1,000 times in the simulator to watch this convergence in real time.

The Gambler's Fallacy

One of the most common and costly probability mistakes is believing that a streak of heads makes tails "due." Each coin flip is completely independent, the probability of heads is always p = 0.5 regardless of past outcomes. The coin has no memory. A run of 10 heads does not make tails any more likely on the 11th flip. The law of large numbers corrects short-run imbalances through dilution, not compensation.

Why Results Deviate from 50/50

With n flips, the standard deviation of the heads count is σ = √(n × 0.5 × 0.5) = √n / 2. For 100 flips, σ = 5. This means seeing 55 or 45 heads (one standard deviation away) happens roughly 68% of the time. In other words, getting "far from" 50% is the norm for small samples, not evidence of an unfair coin. The z-score and chi-square test in this simulator quantify exactly how unusual any given result is.

Binomial Distribution Connection

Repeated coin flips follow the binomial distribution. The probability of getting exactly k heads in n flips is P(X = k) = C(n, k) × 0.5ⁿ. For large n, the binomial distribution approaches the normal distribution, which is why the z-score interpretation becomes increasingly accurate as your flip count grows.

Real-World Applications

FieldApplication
Probability educationTeaching the difference between theoretical and empirical probability
Game designVerifying randomness in board games, card games, and RPG mechanics
Sports & competitionsCoin toss for side selection, overtime, and kickoff decisions
Statistics teachingDemonstrating the law of large numbers and central limit theorem
Decision makingBreaking ties, choosing order, randomizing study lists
Psychology researchDemonstrating cognitive biases like the gambler's fallacy
Software testingTesting random number generator output distributions
Cryptography validationChecking that a PRNG produces balanced binary output

Streak Probability Reference

Streak LengthP(streak)≈ Expected flips to first occurrence
3 in a row12.5%~14 flips
5 in a row3.125%~46 flips
7 in a row0.781%~128 flips
10 in a row0.098%~1,024 flips
15 in a row0.003%~32,768 flips
20 in a row0.0001%~1,048,576 flips

Frequently Asked Questions

Is the coin flip simulation truly random?

The simulator uses JavaScript's Math.random(), which is a pseudorandom number generator (PRNG) seeded by the browser's entropy sources including hardware timing.

For all practical purposes, classroom demos, decisions, and statistical experiments, it is indistinguishable from true randomness. Each flip is statistically independent with exactly the probability you set on the bias slider.

Why doesn't the result come out exactly 50/50?

Because random variation is the norm, not the exception. The standard deviation for n coin flips is σ = √n / 2. For 100 flips, that's ±5, so seeing 45 to 55 heads is entirely expected.

The z-score in the statistics panel tells you exactly how unusual your current result is. A z-score between −2 and +2 (covering ~95% of outcomes) means the coin is behaving normally.

  • Small samples (< 50 flips): large percentage swings are completely normal
  • Medium samples (50–500 flips): results usually settle within 5% of expected
  • Large samples (1,000+ flips): the percentage reliably approaches the true probability

What is the Law of Large Numbers?

The Law of Large Numbers (LLN) states that as the number of independent trials grows, the sample average converges to the theoretical expected value.

For a fair coin: the more flips you do, the closer the heads percentage gets to 50%. But it does not "correct" past results, it dilutes them. The coin has no memory.

You can watch LLN in action by pressing ×1000 several times in the simulator. The percentage converges steadily even though each individual flip is just as random as the first.

What does the z-score mean?

The z-score measures how many standard deviations your observed heads count is from what you would expect for a fair coin.

  • |z| < 1.0, very normal, happens ~68% of the time
  • |z| < 2.0, normal variation, happens ~95% of the time
  • |z| ≥ 2.0, somewhat unusual, happens ~5% of the time
  • |z| ≥ 3.0, very unlikely for a fair coin (~0.3%)

A large |z| does not prove the coin is biased, it just means your result is statistically uncommon. With enough experiments, a fair coin will produce |z| ≥ 2 about 5% of the time by chance.

What does the chi-square test show?

The chi-square (χ²) fairness test compares the observed heads and tails counts to what you would expect from a fair coin. A larger χ² means a bigger discrepancy.

  • χ² < 3.84 (p > 0.05), consistent with a fair coin
  • χ² ≥ 3.84 (p < 0.05), marginal significance
  • χ² ≥ 6.63 (p < 0.01), statistically significant
  • χ² ≥ 10.83 (p < 0.001), highly significant

The chi-square test becomes more reliable with larger samples. For fewer than 10 flips, the statistics panel does not show the test because the result would not be meaningful.

What is the Gambler's Fallacy?

The Gambler's Fallacy is the mistaken belief that a run of one outcome makes the opposite outcome "due." For example: "I've flipped 8 heads in a row, tails must be coming next."

This is completely false. Each coin flip is independent. The probability of heads on the next flip is always p = 0.5, regardless of past outcomes. The coin has no memory of previous results.

The simulator demonstrates this clearly, use the history grid to track streaks, and you'll see that the flip after a long streak is just as likely to continue it as to break it.

Can I simulate an unfair or biased coin?

Yes, drag the probability slider away from 50% to set any heads probability from 0% to 100%. This lets you model:

  • A weighted coin (e.g., 60% heads)
  • A nearly-always-heads coin (e.g., 90%)
  • Any real-world binary event with a known probability

The expected value, standard deviation, and all statistical tests update automatically to reflect your chosen probability. Click the "Fair (50%)" label to snap back to a fair coin instantly.

How are the results saved between sessions?

Your flip counts, streaks, history, and probability setting are saved automatically to your browser's localStorage, no account or server required.

The data stays on your device and is restored the next time you visit this page. To clear everything and start fresh, click the Reset All button, which wipes both the display and the saved state.

Related Calculators