Binomial Distribution Calculator
Calculate binomial probability P(X=k), CDF, mean, variance, and distribution statistics for any n and p. Includes bar chart and full probability table.
Quick Presets
Query Type
What Is the Binomial Distribution Calculator?
This calculator computes the complete picture of a binomial distribution for any n (trials) and p (success probability). Beyond the basic PMF, it gives four probability modes, exact, at most, at least, and range, plus a bar chart, scrollable probability table, and full distribution statistics.
- ›Four query modes, calculate P(X = k), P(X ≤ k), P(X ≥ k), or P(k₁ ≤ X ≤ k₂) without manual summing.
- ›Log-space computation, handles n up to 500 without numeric overflow by computing log factorials once and evaluating each PMF in log space.
- ›Visual bar chart, shows up to 51 bars centered on k, with selected bars highlighted in a different colour for instant visual context.
- ›Full probability table, every (k, PMF, CDF) row for the entire distribution, scrollable and capped at 101 rows for large n.
- ›Normal approximation notice, when np ≥ 5 and n(1−p) ≥ 5 the equivalent Normal(μ, σ²) parameters are shown alongside the exact answer.
- ›Step-by-step derivation, collapsible panel showing exactly how P(X = k) is broken into C(n,k), pᵏ, and (1−p)ⁿ⁻ᵏ components.
Formula
Probability Mass Function (PMF)
P(X = k) = C(n, k) × pᵏ × (1 − p)ⁿ⁻ᵏ
Binomial Coefficient
C(n, k) = n! / (k! × (n − k)!)
Cumulative Distribution (CDF)
P(X ≤ k) = Σᵢ₌₀ᵏ C(n, i) × pⁱ × (1 − p)ⁿ⁻ⁱ
Complement / Survival Function
P(X ≥ k) = 1 − P(X ≤ k − 1)
| Symbol | Name | Description |
|---|---|---|
| n | Number of trials | Fixed, non-negative integer, e.g. 10 coin flips |
| k | Number of successes | The outcome you are measuring, must satisfy 0 ≤ k ≤ n |
| p | Success probability | Probability of success on any single trial, between 0 and 1 |
| 1−p | Failure probability | Also written q; probability of failure on any single trial |
| C(n,k) | Binomial coefficient | "n choose k", the count of ways to pick k successes from n trials |
| μ | Mean | μ = np, the expected number of successes |
| σ² | Variance | σ² = np(1−p) |
| σ | Standard deviation | σ = √(np(1−p)) |
Distribution Statistics
Mean: μ = np
Variance: σ² = np(1 − p)
Std Dev: σ = √(np(1 − p))
Skewness: γ₁ = (1 − 2p) / σ
Kurtosis: γ₂ = (1 − 6p(1−p)) / σ² (excess kurtosis)
Mode: ⌊(n+1)p⌋ or ⌊(n+1)p⌋ − 1 (bimodal when (n+1)p is a whole number)
How to Use
- 1Enter n: Type the number of independent trials. Accepted range is 1–500.
- 2Enter p: Type the success probability for a single trial (0 to 1, e.g. 0.5 for a fair coin).
- 3Enter k: Type the number of successes you want to evaluate (0 to n).
- 4Select a query mode: Choose Exact P(X=k), At Most P(X≤k), At Least P(X≥k), or Range P(k₁≤X≤k₂). For range mode a second value k₂ appears.
- 5Try a preset: Click Fair Coin, Dice, Quality Control, Clinical Trial, or Free Throw to load a real-world example instantly.
- 6Press Enter or click Calculate: Results appear: main probability, all four probability types, six distribution statistics, bar chart, and full table.
- 7Expand step-by-step: Click the derivation panel to see how C(n,k), pᵏ, and (1−p)ⁿ⁻ᵏ are evaluated for your inputs.
Example Calculation
Fair coin, 10 flips, what is the probability of exactly 3 heads?
Given: n = 10, p = 0.5, k = 3
Step 1: Binomial coefficient
C(10, 3) = 10! / (3! × 7!) = 120
Step 2: pᵏ = 0.5³ = 0.125
Step 3: (1−p)ⁿ⁻ᵏ = 0.5⁷ = 0.0078125
Step 4: PMF = 120 × 0.125 × 0.0078125
P(X = 3) ≈ 0.11719 → 11.72%
| k | P(X = k) | P(X ≤ k) |
|---|---|---|
| 0 | 0.00098 | 0.00098 |
| 1 | 0.00977 | 0.01074 |
| 2 | 0.04395 | 0.05469 |
| 3 ★ | 0.11719 | 0.17188 |
| 4 | 0.20508 | 0.37695 |
| 5 | 0.24609 | 0.62305 |
Distribution statistics for this example
Understanding Binomial Distribution
When Does the Binomial Distribution Apply?
The binomial distribution models a very specific type of random experiment. It requires exactly four conditions, sometimes called the BINS conditions:
- ›B, Binary outcomes. Each trial results in exactly one of two outcomes: success or failure. Heads or tails, defective or good, responded or didn't.
- ›I, Independence. The outcome of one trial does not affect any other trial. Drawing with replacement from a deck satisfies this; drawing without replacement does not (use the hypergeometric distribution instead).
- ›N, Fixed number of trials. The number of trials n is decided in advance. You flip the coin exactly 10 times, not until you get 3 heads.
- ›S, Same probability. The probability p of success is identical for every trial. A fair coin always has p = 0.5; a biased coin has a fixed p ≠ 0.5.
The Binomial Coefficient, Combinatorics in Probability
The term C(n, k), read "n choose k", is the heart of the binomial formula. It counts the number of distinct ways to choose k successes from n trials, regardless of order. If you flip a coin 5 times and want exactly 2 heads, there are C(5, 2) = 10 different sequences that give 2 heads (HHTTT, HTHTT, HTTHT, …).
The formula C(n, k) = n! / (k! × (n−k)!) involves factorials that grow astronomically. For n = 500, k = 250, the factorials are thousands of digits long. The calculator avoids overflow by working in log space: log C(n,k) = log(n!) − log(k!) − log((n−k)!), then exponentiating the final result. This gives full double-precision accuracy up to n = 500.
Pascal's triangle and binomial coefficients
Pascal's triangle is a compact way to compute all binomial coefficients. Each entry is the sum of the two entries above it: C(n, k) = C(n−1, k−1) + C(n−1, k). Row n of the triangle lists C(n, 0), C(n, 1), …, C(n, n). The entire triangle can be built without computing a single factorial, which is why it was used for centuries before the factorial notation existed.
Cumulative vs Exact Probability
In practice, "exactly k successes" is rarely what you need. More often the question is:
- ›P(X ≤ k), "at most k". Quality control: what fraction of batches have 3 or fewer defects? Insurance: what is the chance of 2 or fewer claims?
- ›P(X ≥ k), "at least k". Clinical trials: what is the probability 6 or more patients respond? Sports: what are the odds a player scores in 8 or more of 10 games?
- ›P(k₁ ≤ X ≤ k₂), "between k₁ and k₂". "What fraction of batches have between 2 and 5 defects?"
The CDF P(X ≤ k) is computed by summing the PMF from 0 to k. This calculator displays all four probability types simultaneously so you never need to do this summation manually.
Distribution Shape and Skewness
The binomial distribution is not always bell-shaped. Its symmetry depends entirely on p:
- ›p = 0.5, Perfectly symmetric. The distribution is centred at n/2, and skewness = 0.
- ›p < 0.5, Right-skewed. Most results cluster near 0; the tail extends towards n. Skewness is positive.
- ›p > 0.5, Left-skewed. Most results cluster near n; the tail extends towards 0. Skewness is negative.
- ›As n increases with any fixed p, the distribution becomes more symmetric and bell-shaped, a direct consequence of the Central Limit Theorem.
Normal Approximation to Binomial
When n is large enough that both np ≥ 5 and n(1−p) ≥ 5, the binomial distribution is well approximated by a Normal distribution with μ = np and σ² = np(1−p). This approximation, due to the De Moivre–Laplace theorem (a precursor to the Central Limit Theorem), allows the use of z-score tables instead of summing binomial probabilities.
For integer comparisons a continuity correction improves accuracy: use P(k − 0.5 ≤ X ≤ k + 0.5) in the normal model to approximate P(X = k) in the binomial model. The calculator displays the equivalent normal parameters when the approximation condition is satisfied.
Real-World Applications
| Field | Typical Question | Parameters |
|---|---|---|
| Quality control | How many defective items in a batch of 200? | n = 200, p = defect rate |
| Medical trials | How many patients respond to treatment? | n = trial size, p = response rate |
| Marketing | How many visitors convert from 1,000 sessions? | n = 1 000, p = conversion rate |
| Sports analytics | How many free throws made in 20 attempts? | n = 20, p = player accuracy |
| Finance | How many of 50 loans default? | n = 50, p = default probability |
| Genetics | How many offspring inherit a recessive trait? | n = offspring, p = 0.25 (Mendel) |
Frequently Asked Questions
When does the binomial distribution apply?
Use the binomial distribution when all four BINS conditions hold:
- ›Binary outcomes, each trial ends in success or failure, nothing else
- ›Independence, one trial's result does not change another's probability
- ›Fixed n, the number of trials is decided before the experiment begins
- ›Same p, the success probability is identical for every trial
If sampling is done without replacement from a finite population, independence is violated , use the hypergeometric distribution instead. If events occur continuously in time at a known rate, use the Poisson distribution.
What is the difference between P(X = k) and P(X ≤ k)?
P(X = k) is the exact (point) probability, the single bar in the distribution chart for that value of k.
P(X ≤ k) is the cumulative probability, the total area of all bars from 0 up to and including k.
Which to use:
- ›"What is the chance of exactly 3 defects?" → use P(X = k)
- ›"Is the batch acceptable if it has 3 or fewer defects?" → use P(X ≤ k)
- ›"Is there at least a 5% chance of 6 or more failures?" → use P(X ≥ k)
- ›"What fraction of outcomes fall between 4 and 8 successes?" → use the range mode
How is the binomial coefficient C(n, k) calculated?
The binomial coefficient C(n, k) counts distinct subsets of size k from a set of size n:
Example: C(5, 2) = 120 / (2 × 6) = 10. There are exactly 10 ways to pick 2 items from 5.
For large n the factorials are astronomically large. The calculator avoids overflow by:
- ›Pre-computing log(0!), log(1!), … log(500!) as a Float64Array once
- ›Evaluating log C(n,k) = logFact[n] − logFact[k] − logFact[n−k]
- ›Then computing PMF = exp(log C(n,k) + k·log(p) + (n−k)·log(1−p))
This gives full precision up to n = 500 in ordinary floating point.
What are the mean and standard deviation of a binomial distribution?
- ›Mean μ = np, the long-run average number of successes per n trials
- ›Variance σ² = np(1−p)
- ›Standard deviation σ = √(np(1−p))
- ›Skewness γ₁ = (1−2p) / σ, zero at p = 0.5 (symmetric), positive when p < 0.5, negative when p > 0.5
- ›Excess kurtosis γ₂ = (1−6p(1−p)) / σ²
Intuition: n and p pull in opposite directions. High p near 1 means most trials succeed, so variance is low. Variance is maximised at p = 0.5, where uncertainty is highest.
When can I use the normal approximation for a binomial?
The rule of thumb: apply the normal approximation when both conditions hold:
- ›np ≥ 5, enough expected successes for the distribution to be bell-shaped
- ›n(1−p) ≥ 5, enough expected failures for the same reason
When both conditions are met, B(n, p) ≈ Normal(np, np(1−p)).
Continuity correction (improves accuracy for integer events):
- ›P(X = k) ≈ P(k − 0.5 ≤ Z ≤ k + 0.5) in the normal model
- ›P(X ≤ k) ≈ P(Z ≤ k + 0.5)
- ›P(X ≥ k) ≈ P(Z ≥ k − 0.5)
This calculator shows the exact binomial probability alongside the normal approximation parameters whenever the approximation condition is satisfied.
What is the difference between binomial and Poisson distributions?
Both count discrete successes, but in different experimental settings:
- ›Binomial: n is fixed. "10 coin flips, how many heads?", discrete, bounded by n.
- ›Poisson: no upper bound. "How many cars pass per hour?", n is not fixed or even finite.
- ›Binomial requires two known parameters: n and p. Poisson needs only λ (rate).
- ›When n is very large and p is very small (rare events), Binomial(n, p) ≈ Poisson(λ = np).
Rule of thumb: use Poisson when p < 0.05 and n > 20 (or equivalently, λ = np < 5 with large n).
Can a binomial distribution have two modes?
The mode (most probable value) of B(n, p) is:
- ›Normally: ⌊(n+1)p⌋, the floor of (n+1)p
- ›Bimodal case: when (n+1)p is a positive integer, the PMF is equal at k = (n+1)p − 1 and k = (n+1)p
- ›Special cases: p = 0 → mode is 0; p = 1 → mode is n
Example: n = 4, p = 0.4 → (n+1)p = 2.0 (integer) → modes are k = 1 and k = 2. The calculator flags bimodal distributions and shows both modal values.
Does the calculator save my inputs?
Yes, inputs are automatically persisted to your browser's localStorage:
- ›n, p, k (and k₂ for range mode) are saved after each calculation
- ›The selected query mode (exact / at most / at least / range) is preserved
- ›All data stays in your browser, nothing is sent to any server
- ›Inputs are restored the next time you open the page
Click Reset All to clear both the form and the saved localStorage data.