ForHosting KIT · Math

Coin flip probability

Ten fair flips land exactly five heads with probability 0.24609375, because 252 of the 1024 possible sequences have five heads. Enter the flips, the heads you want and, if the coin is loaded, its chance of heads. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
N
10
Exact number of heads
5
You get
Power (W)
0.5
Probability
0.24609375
Binomial coefficient
252

When you care about exactly k heads in n flips, the right closed form is the binomial probability mass function, which multiplies the number of sequences with k heads by the probability of any one of those sequences. This capability accepts the number of flips n, the exact head count k, and an optional bias p (default one half for a fair coin), then returns the probability, the exact binomial coefficient as a decimal string, a short formula string, and a flag that marks fair coins. Negative k and any k larger than n are rejected with a clear validation error instead of a silent zero or a misleading answer.

How binomial coin-flip probability works

Model each flip as an independent Bernoulli trial with success probability p equal to the chance of heads on a single toss. After n independent flips the number of heads X follows a binomial distribution with parameters n and p. The probability of observing exactly k heads is C(n, k) times p to the k times (1 minus p) to the n minus k, where C(n, k) is the binomial coefficient that counts how many distinct sequences of length n contain exactly k heads.

For a fair coin p equals one half, so every particular sequence of length n has probability two to the minus n, and the formula simplifies to C(n, k) over two to the n. Classic checks include one fair flip and one head giving probability one half; ten fair flips and five heads giving C(10, 5) over 1024 which is 252 over 1024 or about 0.246; and a biased coin with p equal to 0.7 for three heads in five flips using C(5, 3) times 0.7 cubed times 0.3 squared.

Edge cases matter for correctness: if p is zero then only k equals zero has probability one and every positive k has probability zero; if p is one then only k equals n succeeds; if n is zero then only k equals zero is possible. This implementation never uses Monte Carlo sampling, random seeds, wall-clock time, or network lookups: it computes the exact binomial coefficient with BigInt arithmetic and evaluates the probability in log space so intermediate products stay numerically stable for larger n.

Where coin-flip binomial probabilities show up in real work

Introductory statistics and discrete-math courses constantly ask students for the chance of exactly k heads in n tosses, sometimes with a fair coin and sometimes with a loaded coin whose heads rate is not one half. Interview prep and programming contests reuse the same mass function when counting bit patterns, success streaks modeled as independent trials, or quality-control checks that treat each unit as pass or fail with fixed p.

Data scientists validate Monte Carlo simulators and A/B experiment power sketches by comparing sampled frequencies against the closed-form binomial probability for small n before scaling to large-sample approximations. Educators build answer keys and auto-graders that need a single deterministic value rather than a random simulation that would change between runs. Game designers and probability demos on the web often expose a fair-coin default while still allowing a bias slider for teaching dependence of the peak on p.

If you later need the cumulative distribution P(X less than or equal to k), inverse quantiles, hypothesis tests against a hypothesized p, or random generation of flip sequences, treat those as separate search intents rather than overloading this landing. Keep n inside the documented bound so free-tier latency stays predictable, and remember that floating-point probability is ideal for ranking and thresholds while the string binomial coefficient remains exact for combinatorial checks.

Simulator and Monte Carlo checks

Validate sampling code against the closed-form P(X=k) for small n before trusting large-scale coin-flip or Bernoulli simulations.

Interview and contest prep

Quickly evaluate C(n,k) p^k (1-p)^(n-k) when practicing binomial counting, bit-pattern odds, and independent-trial problems.

What formula does this use?

The binomial probability mass function: P(X=k) = C(n,k) × p^k × (1-p)^(n-k), where C(n,k) is the number of sequences with exactly k heads.

What if I omit p?

p defaults to 0.5, which models a fair coin. You can still send any p in [0, 1] for a biased coin.

What happens if k is negative or greater than n?

The number of heads cannot be negative and cannot exceed the number of flips.

Is the binomial coefficient exact?

Yes. C(n,k) is computed with BigInt and returned as a decimal string so every digit is exact within the supported n range.

What does it cost?

The browser tool is free and runs locally.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/prob/coin-flip

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/prob/coin-flip \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":10,"k":5}'
{
  "n": 10,
  "k": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "prob.coin_flip",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

min_n0
max_n1000
min_k0
min_p0
max_p1
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Coin flips are the classic classroom model of independent Bernoulli trials: each toss is heads with probability p and tails with probability one minus p, and the sequence of outcomes does not change the odds of the next toss.

What you send and what you get back

Provide required integers n and k under the fields n and k (aliases flips, trials, or N for n; heads, successes, or K for k). Optionally send p (aliases prob_heads, probability, or bias) as a number in the closed interval from zero to one; when omitted the calculator assumes a fair coin with p equal to one half. Missing required fields, non-integers for n or k, decimals where integers are required, p outside zero to one, negative k, and any k that exceeds n are rejected with invalid_input and are not charged. Error messages name the offending field and the rule that failed so form clients and scripts can correct the request without guessing. On success the response always includes the normalized n, k, and p; probability as a floating-point number in zero to one; binomial_coefficient as an exact decimal string for C(n, k); formula as a short display string of the binomial product; and fair as a boolean true when p is exactly one half. Example checks: n equals ten and k equals five with default p yields probability about 0.24609375 and coefficient 252; n equals one and k equals one with p equals 0.5 yields probability 0.5; n equals five and k equals three with p equals 0.7 yields the biased binomial mass; n equals ten and k equals fifteen yields invalid_input because k exceeds n; n equals eight and k equals negative one yields invalid_input because the number of heads cannot be negative. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.

Where coin-flip binomial probabilities show up in real work

Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.

Statistics homework and answer keys

Compute exact binomial probabilities for fair and biased coin problems in discrete math, intro stats, and automated grading fixtures.

Read the full KIT documentation →