Hypergeometric Distribution Calculator

Sampling without replacement — probability of exactly, at most or at least k successes in a sample of n from a finite population of N with K successes. Full distribution chart and show/hide step-by-step working.

What is the hypergeometric distribution?

The hypergeometric distribution is the probability model for sampling without replacement from a finite population. Picture an urn with N balls, K of them red and N − K blue. You reach in and grab n balls (without putting any back). Let X be the number of red balls you pulled out. Then X follows a hypergeometric distribution, and the probability of getting exactly k red is C(K, k) · C(N − K, n − k) / C(N, n).

The classic example is a card deck: N = 52 cards, K = 4 aces. If you deal a five-card hand, the number of aces in that hand is hypergeometric. Same idea applies to lottery matches (K winning numbers in the pool), quality control (K defective units in a batch), and card-game deckbuilding (K copies of a specific card in a shuffled deck).

The hypergeometric distribution, piece by piece

PMF — sampling without replacement

Pick k successes out of the K available, then fill the remaining n − k spots from the N − K failures, and divide by all equally-likely samples of size n. That ratio is the exact probability of observing k successes.

P(X = k)
= C(K
k) · C(N − K
n − k) / C(N
n)
Npopulation size·Ksuccesses in the population·nsample size·kobserved successes in the sample
population Nsample nk successes in sample
Example
Given
N=52
K=4 aces
n=5
k=2
Substitute
C(4,2)·C(48,3)/C(52,5) = 6·17,296/2,598,960
Answer
≈ 0.03993 (≈ 4.0%)

Expected number of successes

The mean is the fraction of the population that is a success, scaled up by the sample size. It matches the intuition: sampling 10% of a population is expected to give you 10% of the successes.

E[X] = n · K / N
nsample size·K / Nshare of successes in the population
012345μ = nK/N ≈ 0.385
Example
Given
N=52
K=4
n=5
Substitute
5 · 4 / 52 = 20/52
Answer
≈ 0.385 aces per hand

Variance and the finite-population correction

Hypergeometric variance is the binomial variance n·p·(1 − p) multiplied by the finite-population correction (N − n)/(N − 1). Every draw without replacement removes uncertainty, so the sampling distribution is tighter than the with-replacement (binomial) counterpart.

Var(X) = n · K/N · (N − K)/N · (N − n)/(N − 1)
(N − n)/(N − 1)finite-population correction (FPC)·n · K/N · (N − K)/Nthe corresponding binomial variance
binomialn/N = 0.3n/N = 0.9FPC (N − n)/(N − 1) shrinks Var toward 0 as n → N
Example
Given
N=52
K=4
n=5
Substitute
5·(4/52)·(48/52)·(47/51)
Answer
Var ≈ 0.3273

Valid range of k

k can't exceed either the sample size n or the number of successes K, and it can't be so small that the remaining n − k failures exceed the N − K available failures. Anything outside that range has probability exactly 0.

max(0
n − (N − K)) ≤ k ≤ min(n
K)
min(n, K)upper bound — can't observe more successes than exist·max(0, n − (N − K))lower bound — some successes are forced when failures run out
max(0, n − (N−K))min(n, K)outside this range, P(X = k) = 0
Example
Given
N=10
K=8
n=5
Substitute
max(0, 5 − 2) = 3 ≤ k ≤ min(5, 8)
= 5
Answer
k ∈ {3, 4, 5}

Hypergeometric vs binomial — when does 'without replacement' matter?

Binomial assumes every trial has the same success probability p — i.e. you're replacing each item before drawing the next, or the population is effectively infinite. Hypergeometric samples without replacement, so p changes after each draw.

For the 5-card / 2-aces example above, the binomial approximation with p = 4/52 = 1/13 gives:

C(5, 2) · (1/13)² · (12/13)³ = 10 · (1/169) · (1728/2197) ≈ 0.04655 (≈ 4.66%)

vs the true hypergeometric answer of 3.99%. The binomial is off by about 17% relative — noticeable, because the sample (5) is a meaningful fraction of the population (52). If you were drawing 5 cards from a shoe of 5,000 shuffled cards instead, the two answers would be nearly identical.

Rule of thumb: if n / N < 0.05 the binomial approximation is usually fine. Above that, use the hypergeometric formula.

Real-world uses

  • Card games. Poker odds, bridge hand distributions, and MTG opening-hand probabilities (e.g. "chance of at least 3 lands in a 7-card opening hand of a 60-card deck with 24 lands" = hypergeometric with N = 60, K = 24, n = 7, k ≥ 3).
  • Lottery matches. How many of your r picked numbers match the r drawn numbers, out of a pool of N.
  • Quality control on small batches. A batch of N units contains K defective items. You test n units. What is the probability of finding k defects?
  • Ecology — capture-recapture. Given K tagged animals in a population of N, the number tagged in a recapture sample of n is hypergeometric.
  • A/B sampling from a finite audience. When your test population is small enough that draws aren't independent, the hypergeometric is the correct model.

Common mistakes

  • Using the binomial when the sample is large relative to the population. For n/N > 5% you'll systematically over- or underestimate — use hypergeometric.
  • Forgetting the k range. If N − K < n − k the probability is 0 (you can't have that many failures) even though the formula "looks" like it should produce a number. This calculator handles it automatically.
  • Confusing K (successes in the population) with k (successes in the sample). Different letters, different roles — K is a fixed population parameter, k is the observed count in your draw.
  • Mixing up P(X = k) with P(X ≥ k). For "at least" questions (like MTG mulligans — "probability of at least 3 lands"), you need the cumulative sum, not the point probability.

Features of this calculator

  • Exact P(X = k) via combinations — uses BigInt so the numbers stay exact for large N.
  • Cumulative P(X ≤ k) and P(X ≥ k) computed across the full valid k range.
  • Mean nK/N and variance with the finite-population correction (N − n)/(N − 1) printed alongside.
  • Full probability bar chart across max(0, n − (N − K)) … min(n, K) with your target k highlighted.
  • Side-by-side binomial comparison so you can see when 'with vs without replacement' makes a real difference.
  • Works for card hands, lottery matches, quality-control batches, and card-game (MTG/deckbuilding) hand probabilities.
  • Show/hide step-by-step working with each combination and the final division.
  • Copy the summary as text or download the result panel as a PNG.

Frequently asked questions

+What is C(n, r) — the combinations formula?

C(n, r) = n! / (r! · (n − r)!). It counts the number of ways to choose r items from n where order doesn't matter. See the Combinations Counter.

+Does the order of the sample matter?

No. Hypergeometric treats the sample as a set — {A, K, Q} is the same as {Q, K, A}. If order matters you'd use permutations instead.

+Can I use this for MTG or Yu-Gi-Oh deck probabilities?

Yes. Set N to your deck size (60 for standard MTG, 40 for Commander opening, etc.), K to the number of the target card in the deck, n to the hand size and k to how many copies you want to see.

+What if K = 0 or K = N?

If K = 0 there are no successes to draw, so P(X = 0) = 1. If K = N every item is a success, so P(X = n) = 1. The calculator handles both.

+How large an N does this handle?

Up to 100,000. Combinations use BigInt intermediates so the ratio stays accurate; final probabilities are converted to standard doubles.

+Why does the variance use (N − n)/(N − 1)?

That's the finite-population correction. It shrinks the variance below the binomial value n·p·(1−p) because sampling without replacement removes uncertainty faster — every draw actually tells you more.

Related calculators