Statistics & Probability Probability Distributions & Critical Values Binomial distribution (Bernoulli trials)

Binomial Distribution Calculator

Enter the number of trials, the probability of success on each one, and the number of successes you care about, and this calculator returns the exact probability of that many successes, the cumulative probabilities at most and at least that many, and the probability of landing anywhere in a range. It also gives the mean and standard deviation of the distribution and prints the full probability mass function so you can see the shape rather than a single figure.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Number of trials nHow many independent attempts, items inspected or people surveyed.20
Probability of success pThe chance of a success on a single trial, as a decimal - 5% is 0.05.0.5
Number of successes kThe count you want the probability of; also the lower end of the range.12
Upper end of rangeUsed only for the interval probability P(k to k2 inclusive); set it equal to k for a single value.15

It returns

  • P(X = k), exactly k successes — The exact probability of hitting that count.
  • P(X <= k), at most k
  • P(X >= k), at least k
  • P(k <= X <= k2), inclusive
  • Mean n x p
  • Standard deviation

The formula

P(X=k)=(nk)pk(1p)nk
(nk)=n!k!(nk)!

In plain text: P(X = k) = C(n,k) x p^k x (1 - p)^(n - k); mean = np; variance = np(1 - p)

  • nNumber of independent trials (count)
  • pProbability of success on a single trial (probability)
  • kNumber of successes whose probability you want (count)
  • C(n,k)Binomial coefficient: the number of ways to choose k trials out of n (count)

The formula requires a fixed number of trials, two possible outcomes per trial, a constant success probability, and independence between trials. If any of those fails, the binomial model is the wrong one.

Updated Category Probability Distributions & Critical Values Verified against published test cases Reading time 10 min

When the binomial distribution applies

The binomial distribution counts successes in a fixed number of independent attempts, each with the same chance of succeeding. Twelve heads in twenty coin flips, three defective units in a sample of fifty, seven conversions from a hundred visitors: all the same structure.

Four conditions have to hold, and they are worth checking rather than assuming.

  • Fixed n. You decide the number of trials before you start. If you keep going until you get a success, the count follows a geometric or negative binomial distribution instead.
  • Two outcomes. Each trial either succeeds or it does not. Anything with three or more categories needs a multinomial model.
  • Constant p. The success probability is the same on every trial. Sampling without replacement from a small population violates this, because each draw changes the composition of what remains.
  • Independence. One trial's outcome does not affect any other's.

When those hold, everything about the distribution follows from n and p alone. The mean is np, the variance is np(1 - p), and the probability of any particular count comes from a single formula. That is a lot of leverage from two numbers, which is why the binomial is the workhorse of quality inspection, survey work and A/B testing.

Why the formula has three factors

P(X = k) = C(n,k) x pk x (1 - p)n-k. Each factor answers a separate question.

pk is the probability that k specified trials all succeed. Independence lets you multiply, so five particular flips all coming up heads has probability 0.55.

(1 - p)n-k is the probability that the remaining n - k trials all fail. Together these two factors give the probability of one specific sequence - say success, failure, success, success, failure - with exactly k successes.

C(n,k) counts how many such sequences exist. Every arrangement of k successes among n trials has the same probability, so you multiply by the number of arrangements. This is the binomial coefficient, n! divided by k!(n-k)!, and it is the factor people forget: without it you get the probability of one particular ordering rather than of the count.

The mean np is intuitive - twenty trials at 50% average ten successes. The variance np(1 - p) is less obvious, and its shape is informative: it is largest at p = 0.5 and shrinks towards zero as p approaches either 0 or 1. A process that almost always succeeds is highly predictable in its count; one that succeeds half the time is as unpredictable as it can be.

Cumulative probabilities are sums of the individual terms. P(X <= k) adds up the terms from 0 to k, and P(X >= k) is 1 minus the sum up to k - 1. That off-by-one is the most common error in cumulative binomial work, and the reason the calculator reports both cumulative directions explicitly.

Worked example: five heads in ten fair flips

Flip a fair coin ten times. What is the probability of exactly five heads?

  1. Count the arrangements. C(10,5) = 10! / (5! x 5!) = 3,628,800 / (120 x 120) = 252. There are 252 different orders in which five heads can appear among ten flips.
  2. Probability of the successes. pk = 0.55 = 0.03125.
  3. Probability of the failures. (1 - p)n-k = 0.55 = 0.03125.
  4. Multiply. 252 x 0.03125 x 0.03125 = 252 / 1024 = 0.24609375.

So the single most likely outcome happens only about 25% of the time. That is worth sitting with: "exactly the expected number" is usually a minority outcome, and it gets rarer as n grows because the probability spreads over more possible counts.

For the cumulative version, add the terms. C(10,0) through C(10,5) are 1, 10, 45, 120, 210 and 252, summing to 638. So P(X <= 5) = 638 / 1024 = 0.623046875. By symmetry P(X >= 5) is also 638/1024, and the two overlap in exactly the P(X = 5) term - which is why they add to more than 1.

Now check the summary statistics. The mean is np = 10 x 0.5 = 5, matching the peak. The variance is np(1 - p) = 10 x 0.5 x 0.5 = 2.5, so the standard deviation is sqrt(2.5) = 1.5811. Two standard deviations from the mean spans roughly 1.8 to 8.2 heads, and indeed P(2 <= X <= 8) works out at 0.978515625 - close to the 95% a normal approximation would promise, which is what makes that approximation usable at n = 10 for p = 0.5.

Reading the answer

Decide first which probability you actually want. "Exactly k" is rarely the interesting question outside a textbook; real problems usually ask "k or more" (is this many defects surprising?) or "k or fewer" (will this batch pass?). The cumulative outputs answer those directly, and the interval output covers acceptance ranges of the kind used in sampling plans.

Judge surprise against the mean and standard deviation. A count of 15 successes in 20 trials at p = 0.5 sits (15 - 10) / 2.236 = 2.24 standard deviations above the mean, which the exact calculation puts at P(X >= 15) = 0.020695. Reporting the tail probability is more informative than reporting the count alone, because it accounts for n.

The shape of the distribution depends on p. At p = 0.5 it is symmetric. As p moves towards 0 the distribution is right-skewed, piling up at low counts with a tail to the right; as p moves towards 1 it is left-skewed. The skew fades as n grows, which is the practical content of the central limit theorem for counts: the rule of thumb is that both np and n(1 - p) should exceed about 5 before a normal approximation is trustworthy, and the calculator flags when they do not.

Two related approximations are worth knowing. When n is large and p is small with np moderate, the Poisson distribution with mean np is an excellent and much simpler approximation - the standard case is rare defects in a large batch. When n is large and p is moderate, the normal approximation with mean np and standard deviation sqrt(np(1-p)) works well, provided you apply a continuity correction of half a unit when converting a discrete count into a continuous range.

Ten fair coin flips: the complete distribution

n = 10, p = 0.5. Each probability is C(10,k)/1024, so the numerators are the tenth row of Pascal's triangle.
Heads kC(10,k)P(X = k)P(X <= k)
010.000976560.00097656
1100.009765630.01074219
2450.043945310.05468750
31200.117187500.17187500
42100.205078130.37695313
52520.246093750.62304688
62100.205078130.82812500
71200.117187500.94531250
8450.043945310.98925781
9100.009765630.99902344
1010.000976561.00000000

The coefficients add to 1024 = 2^10, which is the total number of possible sequences. Each probability column entry is the coefficient divided by 1024, and the cumulative column is the running total.

Assumptions that fail in practice

  • Sampling without replacement from a small population. Drawing 10 items from a lot of 50 changes p at every draw. The correct model is the hypergeometric distribution; the binomial is an acceptable approximation when the sample is under about 10% of the population.
  • Trials that are not independent. Machine faults cluster, customers influence each other, and consecutive items from one shift share a cause. Positive dependence makes extreme counts more likely than the binomial predicts, so tail probabilities are understated.
  • A success probability that drifts. Tool wear, operator fatigue and seasonal effects all move p during the run. The observed variance then exceeds np(1 - p), a pattern called overdispersion.
  • Stopping when you get the result you wanted. The binomial requires n to be fixed in advance. Continuing to sample until enough successes appear changes the distribution and invalidates any p-value computed from it.
  • Confusing at least with more than. P(X >= 5) includes k = 5; P(X > 5) does not. On a discrete distribution the gap between them is a full probability mass, which can be a fifth of the total.
  • Applying a normal approximation in the tail. Even when np and n(1-p) exceed 5, the approximation is worst exactly where you usually need it - far out in the tail. Use the exact figures, which is what this page computes.

Relatives of the binomial

Set n = 1 and the binomial becomes the Bernoulli distribution, a single trial. Let n grow with p shrinking so that np stays fixed, and it converges to the Poisson distribution, which is why Poisson is used for defect counts and arrivals. Let n grow with p fixed and it converges to the normal distribution with mean np and variance np(1 - p) - the earliest form of the central limit theorem, proved by de Moivre for p = 0.5 and extended by Laplace.

Sampling without replacement gives the hypergeometric distribution, which is the correct model for acceptance sampling from a finite lot. Counting trials until the first success gives the geometric distribution, and until the r-th success gives the negative binomial.

The binomial coefficient at the front of the formula is pure counting, and the combination calculator computes it on its own. For the underlying probability rules that justify multiplying independent trial probabilities together, see the probability calculator; for updating a belief about p in the light of observed successes, see the Bayes' theorem calculator.

In applied work the binomial usually appears through its tail probabilities. A quality plan that accepts a lot when 2 or fewer of 50 items are defective is a statement about P(X <= 2). An A/B test comparing two conversion rates is comparing two binomial proportions. A confidence interval for a proportion inverts the binomial tails, which is why the exact Clopper-Pearson interval is wider and more conservative than the familiar normal-approximation interval.

Frequently asked questions

What is the difference between binompdf and binomcdf?

The pdf function gives P(X = k), the probability of exactly k successes. The cdf gives P(X <= k), the running total from 0 up to and including k. This calculator reports both, plus P(X >= k), which is 1 minus the cdf at k - 1. Mixing up the two, or getting that off-by-one wrong, is the most common error in binomial homework.

When can I use a normal approximation instead?

The usual rule of thumb is that np and n(1 - p) should both be at least about 5, and some texts require 10. Even then the approximation is weakest in the tails, and you should apply a continuity correction of half a unit. Since this page computes the exact answer, the approximation is only worth using when you are working by hand from a z table.

What if my trials are not independent?

The binomial does not apply, and the direction of the error is predictable: positive dependence between trials inflates the variance above np(1 - p), so extreme counts occur more often than the formula says. Use a model that allows for clustering, such as a beta-binomial, or account for the dependence directly.

Can I use this for sampling without replacement?

Only as an approximation, and a good one when the sample is less than about 10% of the population. Beyond that, each draw changes the composition of what remains and p is not constant, so the hypergeometric distribution is the correct model. The binomial overstates the variance in that case.

Why is P(X <= k) plus P(X >= k) more than 1?

Because both include the value k itself, so they overlap by exactly P(X = k). For ten fair flips at k = 5, each cumulative probability is 0.623047 and the two add to 1.246094, which is 1 plus the 0.246094 counted twice. Discrete distributions behave this way; continuous ones do not, because a single point has zero probability.

What does the standard deviation tell me?

How much the count typically varies around np. For twenty trials at p = 0.5 it is sqrt(5) = 2.236, so counts between about 5.5 and 14.5 cover roughly 95% of outcomes. Note that it is largest at p = 0.5 and falls to zero as p approaches 0 or 1, because a process that nearly always does the same thing has a nearly fixed count.

How large can n be here?

Up to 2,000 trials. The calculation works in logarithms of factorials rather than the factorials themselves, so it does not overflow the way a direct C(n,k) computation would at around n = 170. Above a few hundred trials the cumulative sums are still exact to floating-point precision.

Is p the same as the observed proportion in my data?

No. p is the underlying probability on each trial, which you either know by design - a fair coin, a specified defect rate - or must estimate. If you estimate it from the same data you are testing, the resulting probabilities are optimistic. Use a specification value or a long-run historical rate where you can.

References