Hypergeometric Calculator

Hypergeometric probability

Describe the population

Count all items and how many meet the outcome you call a success. Draws are without replacement. Use whole numbers without grouping separators.

When you draw from a finite group without putting items back, each draw changes what remains. This calculator finds the chance of exactly, at most or at least a chosen number of successes. Enter the population size, the successes in that population, the sample size and the target. It also shows the feasible range, expected successes, variance and a CSV of every feasible exact outcome.

How to use the hypergeometric calculator

  1. 1

    Count the population

    Enter the total number of items N and the number K that count as successes. N must be 1 to 1,000,000,000; K can be 0 to N.

  2. 2

    Choose the sample

    Enter the number n drawn without replacement, from 0 to the smaller of N and 1,000.

  3. 3

    Set the target and event

    Enter k from 0 to n, then choose exactly k, at most k or at least k successes.

  4. 4

    Read or export the result

    See the selected probability and up to 15 nearby exact outcomes. Download the CSV for every feasible outcome and its base-10 log probability.

What the calculation means

Let N be the population size, K the successes in that population, n the items drawn and X the successes in the sample. Sampling is without replacement: after an item is drawn, it cannot be drawn again.

For an exact outcome k:

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

Here C(a, b) means the number of ways to choose b items from a. Only max(0, n - (N - K)) through min(n, K) successes are feasible. An exact target outside that range has probability zero, even if the target is between zero and the sample size. At most k adds the exact probabilities through k; at least k adds them from k upward. A cumulative event below or above the feasible range can therefore be zero or one.

Worked example: five draws from 20 items

Suppose a box holds 20 items, seven of them marked. Draw five without replacement and ask for exactly two marked items. Enter N = 20, K = 7, n = 5, k = 2 and choose Exactly k.

P(X = 2) = C(7, 2) × C(13, 3) / C(20, 5) = 21 × 286 / 15,504 = 6,006 / 15,504 ≈ 0.387384.

That is about 38.74%. Change the event to At most k for P(X ≤ 2) ≈ 0.793215, or At least k for P(X ≥ 2) ≈ 0.594169. Both cumulative events include the outcome of exactly two.

Marked items drawn Exact probability
0 0.083011
1 0.322820
2 0.387384
3 0.176084
4 0.029347
5 0.001354

Mean, variance and the binomial distinction

The expected number of successes is n × K / N. When N > 1, the variance is n × (K/N) × (1 - K/N) × (N - n)/(N - 1); for N = 1, it is zero. The final factor accounts for the changing composition of the remaining population.

The R documentation for the hypergeometric distribution describes the corresponding exact probability and cumulative distribution functions.

Use a binomial model when trials are independent and each has the same success probability, as with draws that replace the item before the next draw. Use this hypergeometric model for a fixed number of draws from a finite population without replacement. The calculator accepts whole-number inputs and computes the distribution in the browser. The guided steps keep inputs in this tab temporarily; a separate tab or an expired session may ask you to start again.

For extremely small nonzero probabilities, the display may say Less than 10^-300 because ordinary decimal numbers cannot show the full value. The CSV also includes a base-10 log probability for each feasible outcome so you can inspect its order of magnitude.

Frequently Asked Questions

It is the outcome you choose to count, such as a marked item in a box or a defective unit in a batch. It does not imply that the outcome is desirable.

Some targets cannot occur. If you draw five items but the population has only one marked item, exactly two marked items is impossible. The result shows the full feasible range so you can check the target.

Yes. At least k means X is greater than or equal to k. At most k also includes exactly k. Choose Exactly k when you want only that single outcome.

It lists every feasible number of sample successes, its exact probability and its base-10 log probability. The page table shows up to 15 nearby outcomes.

The population can contain up to 1,000,000,000 items. The sample can contain up to 1,000 items and cannot exceed the population. All four counts must be whole numbers; enter them without grouping separators.

Related Tools

Tool available in other languages