where .
Mean and Variance
Example: Basic Binomial Probability
A coin is tossed 5 times. Find the probability of getting exactly 3 heads.
Example: At Least One Success
A die is rolled 4 times. Find the probability of getting at least one 6.
Example: Mean and Variance
If , find the mean, variance, and standard deviation.
Mode of Binomial Distribution
Finding n and p from Mean and Variance
Example: Find n and p
The mean and variance of a binomial distribution are 4 and 2 respectively. Find and .
Probability of Success Range
Bernoulli Distribution
Mean: , Variance:
Four conditions a trial must satisfy
Before any formula is applied, the experiment has to pass a checklist, because most lost marks come from forcing a binomial model onto a situation that is not one. The four conditions are: the number of trials is fixed in advance; every trial has exactly two outcomes labelled success and failure; the probability of success is the same on each trial; and trials are independent, which in practice means sampling with replacement from a large population.
Checking them one at a time changes the answer. Tossing a fair coin 10 times passes all four. Drawing 5 cards from a 52-card deck without replacement fails the third and fourth conditions, because the probability of success shifts after every card â that experiment is hypergeometric, not binomial. A production line with a 2% defect rate inspected one item at a time passes, provided the items come from a large batch and defects do not cluster. Writing the value of , and before computing anything turns a vague word problem into a single substitution.
Tabulating the full distribution for a coin
For five tosses of a fair coin the whole distribution fits on six lines, and the individual probabilities show the shape clearly. Each entry is divided by .
| Decimal | |||
|---|---|---|---|
| 0 | 1 | 1/32 | 0.0312 |
| 1 | 5 | 5/32 | 0.1562 |
| 2 | 10 | 10/32 | 0.3125 |
| 3 | 10 | 10/32 | 0.3125 |
| 4 | 5 | 5/32 | 0.1562 |
| 5 | 1 | 1/32 | 0.0312 |
Three readings are worth taking from the table. The row sum is exactly 1, which is the first sanity check for any discrete distribution. The two central rows tie at 0.3125, illustrating the rule that is an integer, so the modes are 3 and . Finally the mean sits at , halfway along the axis of symmetry, while the standard deviation is , so values outside roughly 1.4 to 3.6 are already uncommon.
Cumulative questions then become simple addition rather than fresh computation. The chance of at least four heads is the last two rows, , and the chance of at most one head is the first two rows, as well, because the distribution mirrors about its centre. Working from the table in either direction is faster than re-evaluating the formula, and it makes rounding errors impossible to hide.
Computing the mass function directly
The formula converts into three lines of code, and looping over every possible value gives the whole distribution at once. Summing the results should return 1 to within floating-point noise.
from math import comb
def binom_pmf(n, p, r):
q = 1 - p
return comb(n, r) * p**r * q**(n - r)
n, p = 5, 0.5
total = 0.0
for r in range(n + 1):
prob = binom_pmf(n, p, r)
total += prob
print(f"P(X = {r}) = {prob:.4f}")
print("sum:", round(total, 6)) # sum: 1.0
print("mean:", n * p, "sd:", (n * p * (1 - p))**0.5)
# mean: 2.5 sd: 1.118033988749895
Simulating trials to confirm the mean
If you prefer evidence over algebra, repeat the experiment a few hundred thousand times and count outcomes. The empirical frequencies settle near the theoretical values at a rate of roughly one over the square root of the number of runs, so 200,000 runs pin the mean to about two decimal places.
import random
def simulate(n, p, runs=200000):
hits = [0] * (n + 1)
for _ in range(runs):
wins = sum(1 for _ in range(n) if random.random() < p)
hits[wins] += 1
return [h / runs for h in hits]
probs = simulate(10, 0.3)
mean = sum(r * pr for r, pr in enumerate(probs))
var = sum((r - mean) ** 2 * pr for r, pr in enumerate(probs))
print(f"simulated mean = {mean:.3f} theory = {10 * 0.3:.3f}")
print(f"simulated var = {var:.3f} theory = {10 * 0.3 * 0.7:.3f}")
# simulated mean = 3.000 theory = 3.0
# simulated var = 2.100 theory = 2.1
When to reach for the Poisson form
With , and , the exact cumulative probability is
The four terms behind that number are 0.1216, 0.2702, 0.2852 and 0.1901, which add to 0.8670. Replacing the binomial with a Poisson distribution at gives , about one percentage point low. The normal approximation with a continuity correction uses and returns 0.8682, within 0.15 points of the truth. The practical rule: Poisson suits rare events with small and the tail of the distribution, while the normal approximation suits the middle of a distribution where and both exceed about 5.
Key Takeaways
- A binomial model needs four conditions at once: fixed trial count, two outcomes, constant success probability, and independence, and failing any one of them changes which distribution applies.
- The probability mass function sums to one, and when (n+1)p is an integer the distribution has two adjacent modes, which is why P(X = 2) and P(X = 3) tie for five fair coin tosses.
- Mean np, variance npq and standard deviation sqrt(npq) fully describe the shape, and the standard deviation sets how far typical results sit from the mean.
- Poisson with parameter np approximates rare-event binomials while a continuity-corrected normal covers the centre, with each trading accuracy for simplicity in different regimes.
Common Mistakes
Applying the binomial formula to draws without replacement, such as five cards from one deck
Fix: Check independence first: if the pool changes after each draw, the trial is hypergeometric and the binomial answer will be too extreme.
Using the normal approximation when np is smaller than five
Fix: Require both np and nq to clear roughly 5, otherwise keep the exact sum or switch to a Poisson approximation for rare events.
Computing at least one success as 1 minus P(X = 1)
Fix: Use the complement of the whole zero-success term: P(at least one) = 1 - q to the power n, since every other outcome is included.