Guides
Hypergeometric Distribution Explained with Lottery, Cards and Urn Examples
Pewniaki.pl editorial team
In short
The hypergeometric distribution answers one question: if a set of N items contains K “successes” and you draw n items without replacement, how likely are you to get exactly k successes? The formula is P(X = k) = C(K, k) × C(N − K, n − k) ÷ C(N, n). Balls in an urn, aces in a hand of cards and matches in Lotto are all calculated the same way.
In probability lessons this distribution usually appears as a problem about balls in an urn. In practice it describes every situation in which items are taken out and not put back: quality control of a batch, a hand of cards and the numbers drawn in a lottery. You can check every example in this article in the hypergeometric distribution calculator.
Drawing without replacement
Imagine an urn with 10 balls, 4 of them red. The chance that the first ball drawn is red is 4 in 10. If you do draw a red one and do not put it back, 9 balls remain, 3 of them red — the chance of red on the second draw falls to 3 in 9. Every draw changes what is left.
That is the difference from drawing with replacement, where the ball goes back after each draw and the chance stays the same. Drawing with replacement is described by the binomial distribution, drawing without replacement by the hypergeometric one.
Four numbers: N, K, n and k
- N — the number of all items in the population (balls in the urn, cards in the deck, numbers in the pool).
- K — how many of them are “successes” (red balls, aces, the numbers that will be drawn).
- n — how many items you draw (the sample size).
- k — the number of successes in the sample you ask about.
Not every k is possible. You cannot draw more successes than there are in the sample or in the population, so k ≤ min(n, K). If there are few failures, a large sample must contain some successes: k ≥ max(0, n − (N − K)). Outside this range the probability is 0.
The formula step by step
P(X = k) = C(K, k) × C(N − K, n − k) ÷ C(N, n)
- C(N, n) — the number of all possible samples: how many ways there are to choose n items out of N, ignoring order. This is the denominator.
- C(K, k) — how many ways there are to choose k successes out of K.
- C(N − K, n − k) — how many ways there are to fill the remaining n − k places with failures.
- The product of the last two numbers is the number of samples with exactly k successes. Divide it by the number of all samples.
C(n, k) is the binomial coefficient — we show how to calculate it in How Are Lottery Odds Calculated?.
A classroom example: balls in an urn
An urn holds 10 balls, 4 of them red. We draw 3 balls without replacement. What is the probability that exactly 2 are red? Here N = 10, K = 4, n = 3, k = 2.
- All samples: C(10, 3) = 10 × 9 × 8 ÷ 6 = 120.
- Choosing 2 red balls out of 4: C(4, 2) = 6.
- Choosing 1 ball that is not red out of 6: C(6, 1) = 6.
- Favourable samples: 6 × 6 = 36.
- P(X = 2) = 36 ÷ 120 = 0.3, i.e. 30%.
The other values are calculated in the same way. All rows add up to 120 ÷ 120 = 1 — some number of red balls always comes out.
| k | Favourable samples | P(X = k) |
|---|---|---|
| 0 | C(4, 0) × C(6, 3) = 20 | 20/120 ≈ 16.7% |
| 1 | C(4, 1) × C(6, 2) = 60 | 60/120 = 50% |
| 2 | C(4, 2) × C(6, 1) = 36 | 36/120 = 30% |
| 3 | C(4, 3) × C(6, 0) = 4 | 4/120 ≈ 3.3% |
Number of red balls among the 3 drawn (10 balls, 4 red)
An example with cards
A deck has 52 cards, including 4 aces. You are dealt 5 cards. What is the chance that you hold exactly one ace? N = 52, K = 4, n = 5, k = 1.
- All hands: C(52, 5) = 2,598,960.
- One ace out of four: C(4, 1) = 4.
- Four cards out of the 48 that are not aces: C(48, 4) = 194,580.
- Favourable hands: 4 × 194,580 = 778,320.
- P(X = 1) = 778,320 ÷ 2,598,960 ≈ 0.2995, about 29.95%.
“At least one ace” is easier through the complement: no ace means C(48, 5) = 1,712,304 hands, so P(X ≥ 1) = 1 − 1,712,304 ÷ 2,598,960 ≈ 34.12%.
A lottery example: matches in Lotto
In Lotto the population is 49 numbers. The successes are the 6 numbers that will be drawn, and your sample is the 6 numbers you marked. N = 49, K = 6, n = 6, and k is the number of matches. The denominator is C(49, 6) = 13,983,816.
| Matches k | Favourable sets | P(X = k) |
|---|---|---|
| 0 | C(6, 0) × C(43, 6) = 6,096,454 | ≈ 43.60% |
| 1 | C(6, 1) × C(43, 5) = 5,775,588 | ≈ 41.30% |
| 2 | C(6, 2) × C(43, 4) = 1,851,150 | ≈ 13.24% |
| 3 | C(6, 3) × C(43, 3) = 246,820 | ≈ 1.765% |
| 4 | C(6, 4) × C(43, 2) = 13,545 | ≈ 0.0969% |
| 5 | C(6, 5) × C(43, 1) = 258 | ≈ 0.00184% |
| 6 | C(6, 6) × C(43, 0) = 1 | ≈ 0.0000072% |
Number of matches in Lotto (6 of 49)
The favourable sets add up to 13,983,816, so the probabilities add up to 1. The table also shows something that surprises many players: the most common result of a ticket is zero matches, closely followed by one. The same calculation for Keno (20 numbers drawn from 70) is shown by the Keno odds calculator.
Expected value and variance
E(X) = n × K ÷ N
Var(X) = n × K/N × (1 − K/N) × (N − n)/(N − 1)
In Lotto E(X) = 6 × 6 ÷ 49 ≈ 0.735 — on average a little less than one match per ticket. The variance is 6 × 6/49 × 43/49 × 43/48 ≈ 0.578 and the standard deviation ≈ 0.76. The expected value is the average over a very large number of tickets, not a prediction for one ticket.
The last factor, (N − n)/(N − 1), is the correction for drawing without replacement. When n = N it equals 0: if you take out every item, the result is certain and the variance disappears. For N = 1 the formula cannot be used directly (division by zero), but the result is certain too, so the variance is 0 — which is how the calculator handles it.
Hypergeometric or binomial?
If the population is very large compared with the sample, taking out a few items hardly changes the proportions and the two distributions give similar results. In an urn of 10 balls or a deck of cards the difference is clear — there you need the hypergeometric formula. The same goes for a lottery: the machine does not put drawn balls back.
Exercises
Level: secondary school and introductory university. Every exercise links to the calculator with the numbers filled in.
Exercise 1. Blue balls
An urn holds 12 balls, 5 of them blue. You draw 4 balls without replacement. What is the probability that exactly 2 are blue?
Show solution
- N = 12, K = 5, n = 4, k = 2.
- All samples: C(12, 4) = 495.
- C(5, 2) = 10 and C(7, 2) = 21, so there are 10 × 21 = 210 favourable samples.
- P(X = 2) = 210 ÷ 495 = 14/33 ≈ 0.4242.
Answer: about 42.42%.
Exercise 2. At least one heart
You are dealt 5 cards from a 52-card deck (13 hearts). What is the probability that you hold at least one heart?
Show solution
- Complement: zero hearts, i.e. 5 cards from the other 39.
- C(39, 5) = 575,757 and C(52, 5) = 2,598,960.
- P(X = 0) = 575,757 ÷ 2,598,960 ≈ 0.2215.
- P(X ≥ 1) = 1 − 0.2215 = 0.7785.
Answer: about 77.85% (in the calculator: the P(X ≥ k) row for k = 1).
Exercise 3. Quality control
A batch of 50 items contains 3 defective ones. An inspector picks 5 items at random. What is the chance that none of them is defective?
Show solution
- N = 50, K = 3, n = 5, k = 0.
- C(47, 5) = 1,533,939 — samples without defective items.
- C(50, 5) = 2,118,760 — all samples.
- P(X = 0) = 1,533,939 ÷ 2,118,760 ≈ 0.7240.
Answer: about 72.40% — checking 5 items easily lets such a batch through.
Exercise 4. The average in Keno
In Keno 20 numbers are drawn from 70. You pick 10 numbers. How many matches does a ticket get on average?
Show solution
- N = 70, K = 20, n = 10.
- E(X) = n × K ÷ N = 10 × 20 ÷ 70 ≈ 2.857.
Answer: about 2.86 matches on average; the most common single result is 3 matches (about 28.7%).
Calculate it yourself
- Hypergeometric Distribution Calculator — P(X = k), P(X ≤ k), P(X ≥ k), the table, mean and variance.
- Lottery Odds Calculator — the same formula for lotteries, including two pools.
- Keno Odds Calculator — the full distribution of matches for 1–20 numbers.
- Probability Academy — all calculators and articles.
Lottery games are for adults only (18+). Probability describes the chances but does not change them — no choice of numbers makes a ticket more likely to win.
Tags: hypergeometric distribution probability combinatorics lotto keno