The Binomial Distribution

Probability & Statistics Fundamentals

Chapter 6 · The Binomial Distribution

Chapter 5 covered random variables in general — any list of outcomes and probabilities was fair game. This chapter is about the single most common specific shape that list takes in real engineering work: counting how many times something succeeds out of a fixed number of independent attempts, each with the same fixed probability.

When the Binomial Distribution Applies

The binomial distribution requires four conditions, all of which are worth checking explicitly before using it:

ConditionMeaning
Fixed number of trialsn is decided in advance, not itself random
Two outcomes per trialEach trial is a "success" or "failure" — nothing in between
Fixed success probabilityEvery trial has the exact same probability p of success
Independent trialsOne trial's outcome doesn't affect any other's — Chapter 3's own independence, required here explicitly

The Binomial Formula

X = the number of successes in n trials. The probability of getting exactly k successes is:

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

C(n, k) is "n choose k" — the number of different ways to pick which k of the n trials were the successes (the same combinations formula from Discrete Mathematics Fundamentals Chapter 9, for anyone who's taken that course; here it's just n! / (k! (n−k)!)). The rest of the formula is one specific sequence's own probability — pᵏ for the k successes, (1−p)ⁿ⁻ᵏ for the remaining failures — multiplied by how many different sequences produce that same count.

Worked Example: Flipping a Coin

Flip a fair coin n = 4 times. X = number of heads. What's P(X = 2)?

TermValue
C(4, 2)6
p² = 0.5²0.25
(1−p)² = 0.5²0.25
P(X=2) = 6 × 0.25 × 0.250.375

Mean & Variance — A Shortcut Built on Chapter 5

Computing E[X] and Var(X) the long way, using Chapter 5's own formulas across every possible value of k, works — but the binomial distribution has direct shortcuts that skip all of it:

Binomial mean and variance
E[X] = np    Var(X) = np(1−p)

For the coin-flip example: E[X] = 4 × 0.5 = 2 heads on average, Var(X) = 4 × 0.5 × 0.5 = 1.

A Practical Example: A/B Test Conversions

A new checkout flow has a 20% conversion rate (p = 0.2). Out of the next n = 10 users, what's the probability exactly 3 convert?

TermValue
C(10, 3)120
p³ = 0.2³0.008
(1−p)⁷ = 0.8⁷0.2097
P(X=3) = 120 × 0.008 × 0.2097≈ 0.2013 (20.1%)

E[X] = 10 × 0.2 = 2 expected conversions, Var(X) = 10 × 0.2 × 0.8 = 1.6, SD(X) ≈ 1.26. This exact framing — a fixed conversion rate applied across a fixed number of users — is precisely the model behind Probability & Statistics Fundamentals' own sibling course, Statistical Inference & Applied Statistics, and its A/B testing material.

Revisiting Chapter 1's Defect-Rate Example

Chapter 1's own opening exercise asked: given a known 2% defect rate, how many defects are expected in a batch of 500? That's exactly E[X] = np = 500 × 0.02 = 10 — the binomial mean, finally formalized. The full distribution can answer sharper questions too:

How lucky would a zero-defect batch be?
P(X = 0) = C(500, 0) × 0.02⁰ × 0.98⁵⁰⁰ ≈ 0.000041 — about a 0.004% chance. Even though 10 defects is only "expected," an entirely defect-free batch of this size, at this defect rate, would be a genuinely remarkable outcome, not a plausible one.
Real-world caveat: independence isn't automatic
If defects come from a single faulty machine setting rather than independent random chance, or if one server failure makes a second one more likely (a cascading outage), the fixed-probability-and-independence assumptions this chapter opened with are violated — and the binomial model will systematically underestimate how often extreme outcomes (many defects/failures at once) actually happen. Always check those four conditions before trusting the formula.

The Binomial Distribution in Code

import math def binomial_pmf(n, k, p): return math.comb(n, k) * (p ** k) * ((1 - p) ** (n - k)) print(binomial_pmf(4, 2, 0.5)) # 0.375 — the coin-flip example print(binomial_pmf(10, 3, 0.2)) # 0.2013... — the A/B test example print(binomial_pmf(500, 0, 0.02)) # 4.1e-05 — the zero-defect batch def binomial_mean_var(n, p): return n * p, n * p * (1 - p) print(binomial_mean_var(10, 0.2)) # (2.0, 1.6)

Hands-On Exercises

Exercise 1

Flip a fair coin 5 times. Using this chapter's own binomial formula, compute P(exactly 3 heads), showing the C(n,k), pᵏ, and (1−p)ⁿ⁻ᵏ terms separately before combining them.

📄 View solution
Exercise 2

A new signup flow converts 15% of visitors (p = 0.15). Out of the next 8 visitors, compute P(exactly 2 convert), and separately compute E[X] and Var(X) using this chapter's own mean/variance shortcuts.

📄 View solution
Exercise 3

A batch of 20 units has a 5% defect rate. Compute P(exactly 1 defective unit), and separately compute E[X] using the mean shortcut. Then name which of this chapter's own four required conditions would be violated if the real cause of defects were a single faulty machine setting affecting every unit in the batch identically, and briefly explain the practical consequence.

📄 View solution

Chapter 6 Quick Reference

  • Requires: a fixed number of trials n, two outcomes per trial, a fixed success probability p, and independent trials
  • PMF: P(X=k) = C(n,k) × pᵏ × (1−p)ⁿ⁻ᵏ — combinations × one sequence's own probability
  • Mean/variance shortcuts: E[X] = np, Var(X) = np(1−p) — skip Chapter 5's full sum-over-every-value calculation
  • Models conversion rates, defect rates, and any "how many successes out of n fixed independent attempts" question
  • Always verify independence and a genuinely fixed probability before trusting the model — correlated failures break both assumptions
  • Next chapter: The Poisson distribution