Skip to main content
v2026.11,858 entries · CC-BY 4.0

Hypergeometric Distribution Formula: Definition, Worked Example and Software

The hypergeometric distribution formula, a worked example, how to interpret it, and Excel, R and Python code with the notation differences explained.

Written and maintained by CASRAI Editorial Board

Last updated

The hypergeometric distribution gives the probability of drawing exactly k items of a particular type when you draw a fixed number of items without replacement from a finite population. Its probability mass function is C(K, k) × C(N − K, n − k) / C(N, n). This page explains each symbol, works one example through by hand, shows the same numbers in Excel, R and Python, and lines up the three programs’ different notations, because they do not agree with each other.

What is the hypergeometric distribution?

It is a discrete probability distribution for counting “successes” in a sample taken without replacement from a population that contains a known number of successes. Because each draw changes what is left, draws are not independent. That is the difference from the binomial distribution, which assumes a constant success probability on every trial. The Microsoft Excel documentation states the use case directly: “HYPGEOM.DIST is used in sampling without replacement from a finite population.”

Hypergeometric distribution formula and symbols

This page uses the following notation. Other sources use different letters (see the notation table below), so always check which symbol means which quantity before copying a formula.

P(X = k) = C(K, k) × C(N − K, n − k) / C(N, n)

  • N: population size (total items).
  • K: number of “success” items in the population.
  • n: sample size (items drawn, without replacement).
  • k: number of success items observed in the sample.
  • C(a, b): the binomial coefficient, “a choose b” = a! / (b! (a − b)!).

The probability is non-zero only for max(0, n − (N − K)) ≤ k ≤ min(n, K). Writing p = K/N, the mean is n·p and the variance is n·p·(1 − p)·(N − n)/(N − 1), as given in the R documentation. The last factor, (N − n)/(N − 1), is the finite-population correction: it is the amount by which the variance is smaller than the binomial variance n·p·(1 − p).

Same quantity, different letters in SciPy, R and Excel

SciPy’s documentation notes that “the symbols used to denote the shape parameters (M, n, and N) are not universally accepted.” The table maps each program’s arguments to the symbols used on this page.

Quantity This page SciPy hypergeom.pmf(k, M, n, N) R dhyper(x, m, n, k) Excel HYPGEOM.DIST(…)
Population size N M m + n (computed) number_pop
Successes in population K n m (white balls) population_s
Failures in population N − K M − n (computed) n (black balls) number_pop − population_s (computed)
Items drawn n N k number_sample
Successes observed k k x sample_s

The same letter “n” therefore means the sample size on this page, the number of successes in the population in SciPy, and the number of failures in R. R takes the number of failures directly, while SciPy and Excel take the total population size.

Hypergeometric distribution examples: a worked calculation

Take a population of N = 20 items of which K = 8 are successes, and draw n = 4 without replacement. What is the probability of exactly k = 1 success? (These are the inputs of the official Microsoft Excel example.)

  1. Ways to choose 1 success from 8: C(8, 1) = 8.
  2. Ways to choose the other 3 items from the 12 failures: C(12, 3) = 220.
  3. Ways to choose any 4 items from 20: C(20, 4) = 4,845.
  4. P(X = 1) = 8 × 220 / 4,845 = 1,760 / 4,845 = 0.3633.

The cumulative probability of at most one success adds P(X = 0) = C(12, 4) / 4,845 = 495 / 4,845 = 0.1022, giving P(X ≤ 1) = 2,255 / 4,845 = 0.4654. Both values match the results Microsoft publishes for this example (0.3633 for the probability mass, 0.4654 for the cumulative form).

The full distribution for this example, computed the same way, sums to 4,845 / 4,845:

k Count of samples, C(8,k)×C(12,4−k) P(X = k) P(X ≤ k)
0 495 0.1022 0.1022
1 1,760 0.3633 0.4654
2 1,848 0.3814 0.8468
3 672 0.1387 0.9856
4 70 0.0144 1.0000

Here p = 8/20 = 0.4, so the mean is 4 × 0.4 = 1.6 and the variance is 4 × 0.4 × 0.6 × (16/19) = 0.8084. A binomial model with the same n and p would give a variance of 0.96, which overstates the spread by about 19%.

Interpretation

A single value P(X = k) is the chance of exactly that count; for a significance-style question you usually want a tail probability. The table summarises how to read the numbers from the example above.

What you compute How to read it Example result
P(X = k) Chance of exactly k successes in the sample P(X = 1) = 0.3633
P(X ≤ k) Chance of k or fewer successes (cumulative; TRUE in Excel, phyper in R) P(X ≤ 1) = 0.4654
P(X ≥ k) Chance of k or more = 1 − P(X ≤ k − 1) P(X ≥ 2) = 1 − 0.4654 = 0.5346
Mean n·K/N Expected successes in a sample 1.6

When a tail probability is used as a p-value (for example in an exact test on a 2×2 table), read it as you would any p-value. For comparing proportions in larger samples, the chi-square test is the large-sample approximation to that kind of exact calculation.

Assumptions and common mistakes

  • Sampling is without replacement. If items are returned after each draw, use the binomial distribution instead.
  • The population is finite and K is known. If you do not know the number of successes in the population, the formula does not apply directly.
  • Mixing up the letters. Passing SciPy’s (M, n, N) in the R or Excel order silently gives a different, wrong probability. Use the notation table above.
  • Out-of-range k. The support is max(0, n − (N − K)) ≤ k ≤ min(n, K). In Excel, arguments outside the allowed range return #NUM! and non-numeric arguments return #VALUE!; Excel also truncates arguments to integers.
  • Using the binomial variance. It ignores the factor (N − n)/(N − 1) and overstates variability when the sample is a large share of the population. See the binomial expected value guide for that model.
  • Treating draws as independent when computing joint events. Successive draws change the remaining population; for the rules on combining probabilities, see joint probability.

How to report it

State the population size, the number of successes in it, the sample size, the observed count and the probability, so a reader can reproduce the value. Example wording:

Under a hypergeometric model (N = 20, K = 8, n = 4), the probability of observing exactly one success was P(X = 1) = .363; the probability of observing at most one success was P(X ≤ 1) = .465.

Name the software and function you used (for example HYPGEOM.DIST in Excel, dhyper/phyper in R, scipy.stats.hypergeom in Python) and say whether the probability is exact or cumulative.

How to calculate the hypergeometric distribution in Excel, R or Python

All three snippets reproduce the worked example (N = 20, K = 8, n = 4, k = 1).

Excel

Arguments are sample_s, number_sample, population_s, number_pop, cumulative.

=HYPGEOM.DIST(1, 4, 8, 20, FALSE)
=HYPGEOM.DIST(1, 4, 8, 20, TRUE)

The first returns 0.3633 (exact probability), the second 0.4654 (cumulative).

R

Arguments are x (successes drawn), m (successes in the population), n (failures in the population), k (items drawn).

dhyper(1, 8, 12, 4)
phyper(1, 8, 12, 4)

The first returns 0.3633, the second (cumulative) 0.4654.

Python (SciPy)

Arguments are k, M (population size), n (successes in the population), N (items drawn).

from scipy.stats import hypergeom
print(hypergeom.pmf(1, 20, 8, 4))
print(hypergeom.cdf(1, 20, 8, 4))

The two lines print 0.3633 and 0.4654 (rounded).

FAQ

What is hypergeometric distribution?

It is the distribution of the number of successes in a sample drawn without replacement from a finite population with a known number of successes. Its mean is n·K/N and its probability mass function is C(K, k) × C(N − K, n − k) / C(N, n).

What is the hypergeometric distribution formula?

P(X = k) = C(K, k) × C(N − K, n − k) / C(N, n), where N is the population size, K the successes in the population, n the sample size and k the observed successes.

How is it different from the binomial distribution?

The binomial distribution assumes independent trials with a constant success probability (sampling with replacement or from a very large population). The hypergeometric distribution samples without replacement, so the probability changes after every draw and the variance is reduced by the factor (N − n)/(N − 1).

Why do Excel, R and SciPy give different results for the same numbers?

They usually do not; they simply define their arguments differently. Use the notation table above to map each argument before calling a function.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Hypergeometric Distribution Formula: Definition, Worked Example and Software

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.