The hypergeometric distribution describes the probability of drawing a specific number of target items from a finite population when sampling occurs without replacement. Unlike the binomial model, which assumes each draw is independent, every item removed from the population permanently alters the odds of the next draw. This distinction is not academic — it is the mathematical boundary between an approximation and an exact answer.

Whenever a quality engineer inspects a batch of manufactured components, a geneticist screens a finite pool of alleles, or an ecologist estimates a species count via capture-recapture, the hypergeometric framework delivers the precise probability. This calculator resolves the full suite of point and cumulative probabilities, central moments, skewness, and odds ratios — all computed through a logarithmic Gamma function pipeline that remains numerically stable even for population sizes in the hundreds of thousands.

Required Project Parameters

Before obtaining results, the following four statistical parameters must be specified:

  • Population Size ($N$): The total number of discrete items in the finite population. Must be a positive integer ($N \geq 1$). In manufacturing, this represents the entire lot or batch size.
  • Successes in Population ($K$): The count of items possessing the target trait within the full population. Bounded as $0 \leq K \leq N$. For a standard 52-card deck screened for spades, $K = 13$.
  • Sample Size ($n$): The number of items drawn without replacement. Bounded as $1 \leq n \leq N$. This is the inspection sample or draw count.
  • Observed Successes ($k$): The target number of successes sought within the drawn sample. Dynamically constrained between $\max(0,; n - (N - K))$ and $\min(n,; K)$, enforcing the pigeonhole principle — if the sample exhausts all failure items, a minimum number of successes is mathematically forced.

Combinatorial Foundations: The PMF, CDF, and Moment Derivations

The Probability Mass Function

The core of the hypergeometric model is its Probability Mass Function (PMF). It answers the question: what is the exact probability of observing precisely $k$ successes in a sample of size $n$?

$$P(X = k) = \frac{\binom{K}{k} \binom{N - K}{n - k}}{\binom{N}{n}}$$

Here, $\binom{K}{k}$ counts the ways to choose $k$ successes from the $K$ available, $\binom{N-K}{n-k}$ counts the ways to fill the remaining sample slots with non-target items, and $\binom{N}{n}$ is the total number of ways to draw any sample of size $n$.

Standard factorial computation fails catastrophically at scale. JavaScript's 64-bit floating-point representation overflows at $171!$, rendering direct evaluation of $\binom{N}{n}$ impossible for populations even modestly above 170. This calculator bypasses the combinatorial explosion by computing all binomial coefficients in logarithmic space using the Lanczos approximation of the Gamma function:

$$\ln \binom{n}{k} = \ln\Gamma(n+1) - \ln\Gamma(k+1) - \ln\Gamma(n-k+1)$$

The final probability is recovered via exponentiation: $P = e^{\ln P}$. This architecture extends accurate computation to populations of arbitrary size — critical for applications such as national lottery odds or large-scale genetic screening panels.

Cumulative and Tail Probabilities

A single point probability rarely suffices in applied analysis. The Cumulative Distribution Function (CDF) and its complementary tail provide the full decision-making toolkit:

$$P(X \leq k) = \sum_{i=i_{\min}}^{k} P(X = i)$$

$$P(X \geq k) = \sum_{i=k}^{i_{\max}} P(X = i)$$

The strict inequalities follow directly:

  • Fewer than $k$: $P(X < k) = P(X \leq k) - P(X = k)$
  • More than $k$: $P(X > k) = P(X \geq k) - P(X = k)$

These cumulative measures are indispensable in lot acceptance sampling, where an inspector must determine the probability that a batch contains at most a certain number of defective items given a fixed inspection sample.

Central Moments — Mean, Variance, and Skewness

The expected value (mean number of successes) is:

$$\mu = E[X] = \frac{nK}{N}$$

The variance introduces the critical Finite Population Correction (FPC) factor:

$$\sigma^2 = \frac{nK(N - K)}{N^2} \cdot \frac{N - n}{N - 1}$$

The term $\frac{N - n}{N - 1}$ is the FPC multiplier. It mathematically quantifies how the shrinking population reduces variability with each draw. When $n$ approaches $N$, the correction factor approaches zero — sampling the entire population eliminates randomness entirely.

The standard deviation is simply $\sigma = \sqrt{\sigma^2}$.

Skewness ($\gamma_1$) measures the asymmetry of the distribution:

$$\gamma_1 = \frac{(N - 2K)(N - 1)^{1/2}(N - 2n)}{[nK(N - K)(N - n)]^{1/2}(N - 2)}$$

A positive $\gamma_1$ indicates a right-tailed distribution (successes are rare relative to the sample), while a negative $\gamma_1$ signals left-skew (successes dominate). When $K = N/2$ or $n = N/2$, the distribution is perfectly symmetric ($\gamma_1 = 0$). Tracking skewness reveals how the distribution's shape shifts as the proportion of target items or the sampling fraction changes.

Benchmark Comparisons: Distribution Behavior Across Sampling Regimes

PMF Values Across Varying Population and Sample Configurations

The following table illustrates how the exact probability $P(X = k)$ shifts under different combinations of $N$, $K$, $n$, and $k$. Each row represents a distinct real-world scenario.

Scenario$N$$K$$n$$k$$P(X = k)$$\mu$$\sigma^2$
Card draw (5 from 52, 2 spades)5213520.27431.250.8651
QC inspection (10 from 100, 1 defect)10081010.38310.800.6606
Genetic panel (50 from 500, 5 carriers)500405050.16544.003.2745
Lottery subset (6 from 49, 3 matches)496630.01770.73470.5901
Ecology capture (30 from 200, 8 tagged)200253080.02973.752.9042

Hypergeometric vs. Binomial: When Approximation Fails

Substituting the binomial distribution for the hypergeometric is a common shortcut, valid only when the sampling fraction $n/N$ is small (conventionally below 5–10%). The table below quantifies the divergence.

$N$$K$$n$$k$Hypergeometric $P$Binomial $P$Absolute ErrorSampling Fraction
50101030.24150.20130.040220.0%
200401030.20500.20130.00375.0%
10002001030.20190.20130.00061.0%
1000020001030.20140.20130.00010.1%

At a 20% sampling fraction, the binomial approximation introduces an absolute error exceeding 0.04 — a deviation that is unacceptable in strict ISO 2859-1 acceptance sampling plans and Six Sigma tolerance analysis. The Finite Population Correction embedded in the hypergeometric variance is not optional for small-batch quality control; it is the mathematically exact treatment.

Skewness Transition Reference

$K/N$ Ratio$n/N$ RatioSkewness ($\gamma_1$)Distribution Shape
0.100.10+1.42Strong right skew
0.250.10+0.68Moderate right skew
0.500.100.00Symmetric
0.500.500.00Symmetric
0.750.10−0.68Moderate left skew
0.900.10−1.42Strong left skew

As $K/N$ increases past 0.5 while $n/N$ remains fixed, skewness transitions from positive to negative — the distribution mirror-flips. This symmetry property, $\gamma_1(K) = -\gamma_1(N - K)$, is a direct consequence of the combinatorial duality between "successes" and "failures."

From Lot Acceptance to Genomic Screening: Applied Probability in Practice

Quality Control and ISO Acceptance Sampling

In manufacturing environments governed by ISO 2859-1 (Sampling Procedures for Inspection by Attributes), the hypergeometric distribution underpins every accept/reject decision for small to moderate lot sizes. An inspector draws $n$ units from a lot of $N$ and compares the observed defective count $k$ against an Acceptance Quality Limit (AQL).

Using the binomial model for a 50-unit batch with a 10-unit inspection would overestimate the variance of defect occurrence, potentially rejecting compliant lots or accepting non-compliant ones. The FPC factor corrects this by acknowledging that once a unit is inspected, it cannot appear again — the remaining pool is strictly smaller.

Ecological Capture-Recapture and Genetic Studies

The Lincoln-Petersen estimator, a cornerstone of wildlife population estimation, is a direct application of the hypergeometric model. A known number of animals ($K$) are captured, tagged, and released into a population of unknown size $N$. A second sample ($n$) is drawn, and the number of recaptured tagged individuals ($k$) is observed.

Rearranging the expected value formula yields the classic population estimate:

$$\hat{N} = \frac{nK}{k}$$

In population genetics, the same framework models allele sampling from a finite gene pool. When screening $n$ individuals from a population carrying $K$ copies of a variant allele among $N$ total alleles, the hypergeometric PMF gives the exact probability of detecting a specified number of carriers — essential for powering rare variant association studies.

Variable Sensitivity — How Parameters Reshape the Distribution

Understanding parameter interaction is critical for experimental design:

  • Increasing $n$ while holding $N$, $K$ constant: The expected value $\mu$ rises linearly, but the FPC factor simultaneously compresses the variance. Larger samples yield more precise estimates but with diminishing marginal information gain.
  • Increasing $K/N$ (defect rate or trait prevalence): The distribution's center shifts rightward and skewness transitions from positive to negative as the "success" trait becomes dominant. Past $K/N = 0.5$, the roles of successes and failures effectively swap.
  • $N$ growing while $K/N$ is held constant: The hypergeometric distribution converges toward the binomial. The FPC factor approaches unity, and each draw becomes approximately independent. This convergence is the formal justification for the "5% rule" threshold in applied statistics.

The dynamic constraint on $k$ — specifically $k_{\min} = \max(0, n - (N - K))$ — deserves particular attention. When the sample size $n$ exceeds the number of failure items $(N - K)$, it becomes impossible to draw zero successes. A robust statistical tool must enforce this pigeonhole constraint rather than silently returning a zero-probability result for an impossible input.

Frequently Asked Questions

When should the hypergeometric distribution be used instead of the binomial?

The hypergeometric distribution is the correct model whenever sampling is performed without replacement from a finite population and the sampling fraction $n/N$ is non-trivial. The conventional threshold is a sampling fraction exceeding 5%, though in high-stakes applications such as pharmaceutical batch release testing or aerospace component inspection, the exact model is preferred regardless of fraction size.

The binomial distribution assumes each trial is independent with a fixed success probability $p = K/N$. This assumption holds only when the population is effectively infinite relative to the sample, so that removing one item does not measurably change the composition. For a 200-unit lot inspected with a 20-unit sample (10% fraction), the binomial approximation introduces measurable probability errors that propagate into incorrect accept/reject boundaries.

How does the Finite Population Correction factor affect variance, and why does it matter?

The FPC factor $\frac{N - n}{N - 1}$ multiplies the base variance term and always reduces it below the binomial variance $np(1-p)$. Intuitively, sampling without replacement extracts information about the population more efficiently than sampling with replacement — each drawn item directly eliminates one possibility.

When $n = 1$, the FPC is approximately $1$ and the hypergeometric variance nearly equals the binomial variance. When $n = N$ (a census), the FPC equals zero and the variance collapses — there is no uncertainty because every item has been observed. In Six Sigma quality programs, ignoring the FPC for small batches leads to artificially wide control limits, reducing the sensitivity of defect detection and undermining process capability indices like $C_{pk}$.

Why does this calculator use log-gamma computation instead of direct factorials?

Direct factorial computation in standard 64-bit floating-point arithmetic overflows at $171!$, producing Infinity. Since the hypergeometric PMF requires evaluating three binomial coefficients — $\binom{K}{k}$, $\binom{N-K}{n-k}$, and $\binom{N}{n}$ — any scenario where $N$ exceeds roughly 170 will cause catastrophic numerical failure in a naive implementation.

The Lanczos approximation of $\ln\Gamma(x)$ converts these multiplications into additions and subtractions of logarithms, keeping intermediate values well within representable range. The final probability is recovered by exponentiating a single small number. This is not merely an optimization — it is a numerical necessity for modeling real-world scenarios such as national lottery draws ($N = 49$ to $90$, manageable but with intermediate factorials exceeding $10^{100}$), industrial batches ($N > 1{,}000$), or genomic variant panels ($N > 100{,}000$).

Precision Over Approximation: The Case for Exact Discrete Modeling

The hypergeometric distribution occupies a unique position in applied probability: it is the exact model for finite-population sampling without replacement, yet it is routinely approximated away in favor of the simpler binomial. This substitution is justified only when the sampling fraction is negligibly small.

For quality engineers enforcing ISO compliance on moderate lot sizes, for geneticists powering rare-variant detection studies, and for ecologists estimating population counts through capture-recapture, the approximation introduces quantifiable error that compounds across repeated decisions. Automated computation — particularly through log-gamma numerical architectures that eliminate factorial overflow — removes every practical barrier to using the exact model.

The discipline of specifying $N$, $K$, $n$, and $k$ with full awareness of their dynamic constraints is itself a form of statistical rigor. A tool that enforces the pigeonhole boundary on $k$ and reports the complete moment profile — mean, variance, standard deviation, and skewness — does not merely compute a number. It encodes the structural logic of combinatorics into every result.