Hypergeometric Distribution Calculator
One probability is rarely the whole question. This page shows P(X = k), the cumulative tail P(X <= k), the support and the mean together, with the right tail and an inclusive range underneath and a plot of the probability across the whole support. The support is the part that is usually got wrong: it runs from max(0, n - (N - K)) to min(n, K), so a sample larger than the number of failures is forced to contain successes, and a count outside those bounds comes back as exactly 0 rather than as a small rounded number. The binomial coefficients are computed in logarithms, so C(100000, 1000) and its 2,431 digits never have to exist as a number, and the same question asked with replacement, which is the binomial, is printed beside the answer so the difference between the two is visible rather than assumed.
There are 2,598,960 ways to draw 5 from 52. Put each item back and the same question becomes the binomial, which answers 0.263672. Standard deviation 0.9295001819, variance 0.8639705882, most likely count 1.
The whole support
How likely each possible count of successes is, across the whole support. It runs 0 to 5, because a sample cannot hold more successes than it drew or more than the population has, and it cannot hold fewer than the failures leave room for.
| k | P(X = k) | P(X <= k) | P(X >= k) | Use |
|---|---|---|---|---|
| 0 | 0.221534 | 0.221534 | 1 | |
| 1 | 0.411420 | 0.632953 | 0.778466 | |
| 2 | 0.274280 | 0.907233 | 0.367047 | |
| 3 | 0.081543 | 0.988776 | 0.092767 | |
| 4 | 0.010729 | 0.999505 | 0.011224 | |
| 5 | 0.000495 | 1 | 0.000495 |
Common questions
- How do you calculate a hypergeometric probability?
- Count the ways. With a population of N items of which K are successes, drawing n of them, the number of samples holding exactly k successes is C(K, k) x C(N - K, n - k), and the number of samples altogether is C(N, n). The probability is the first divided by the second. For two hearts in a five-card hand that is 78 x 9,139 / 2,598,960 = 0.274280, and the page prints that line with your own numbers in it, so a figure typed into the wrong field is easy to spot. The textbook case of 10 items, 4 of them successes and 3 drawn gives exactly 0.500000 for one success.
- What is the difference between the hypergeometric and binomial distributions?
- Replacement. The binomial assumes every draw faces the same odds, which is true when each item goes back; the hypergeometric assumes it does not, so every item drawn changes what is left to draw. Two hearts in five cards is 0.274280 without replacement and 0.263672 with it, and this page prints both so the gap is visible instead of assumed. The gap widens as the sample takes up more of the population, and the variance shows the same effect through its finite population correction.
- What is the support of the hypergeometric distribution?
- It runs from max(0, n - (N - K)) to min(n, K), not from 0 to n. The top end is the obvious one: a sample cannot hold more successes than the items it drew, or more than the population contains. The bottom end catches people out. Draw 35 items from a population of 50 that holds only 30 failures and at least 5 successes have to come with them, so the support runs 5 to 20, the most likely count is 14 at 0.246374, and P(X = 2) is not small, it is zero. The support is a readout cell on this page for that reason.
- Why does it return exactly 0 instead of a tiny number?
- Because a count outside the support has no sample behind it at all, not a rare one. C(K, k) is zero as soon as k passes K, so the whole product is zero and the answer is the number 0 rather than a string of zeros at six decimal places. The page prints 0, says which of the two bounds was crossed, and names the range the count of successes can actually land in with the numbers you entered.
- How do I get at most, at least or a range?
- They are all on the page at once. For two hearts in a five-card hand, P(X = 2) is 0.274280, P(X <= 2) is 0.907233 and P(X >= 2) is 0.367047, while the range row answers an inclusive band: P(1 <= X <= 3) is 0.767242. The two range fields take the ends of that band. Leave one of them empty and it falls back to that end of the support, and the label above the figure says which number it used, so nothing is left implied.
- What are the mean and the variance?
- The mean is n x K / N, so five cards from a deck holding 13 hearts averages 1.25 hearts. The variance is n (K/N) ((N - K)/N) ((N - n)/(N - 1)), which comes to 0.8639705882 for that hand. The last factor is the finite population correction, and it is what makes the spread narrower than the binomial's: every card drawn without replacement tells you something about the cards that are left.
- Can it work out lottery odds?
- Yes, for a draw of distinct numbered balls. A 6 from 49 draw is a population of 49 with 6 successes, which are your numbers, and a sample of 6: matching all six is 7.1511e-8, one in 13,983,816, and that count of possible samples is printed beside the answer. The page describes the draw and nothing beyond it.
- How do I check a card draw or an opening hand?
- Set N to the deck size, K to the copies of the card you care about, n to the cards you draw and k to the number of copies you are asking about. Four copies in a 60-card deck with a 7-card opening hand gives 0.399500 for at least one copy, which is the right-tail row rather than the exact-count figure of P(X = 1). Use the table under the plot to move the target count and watch every figure follow.
- Does the sample have to be small compared with the population?
- No. That rule of thumb belongs to the approximation that swaps this distribution for a binomial once the sample is under about 5% of the population. This page computes the exact thing, so a sample that is most of the population is fine: draw 35 items out of 50 and the answer accounts for the 15 left behind, which is also why the support no longer starts at 0.
- How large can the numbers be, and how accurate is the result?
- Populations up to 100,000, and every count has to be a whole number. The coefficients run past what a number can hold long before that: C(100000, 1000) has 2,431 digits, so the arithmetic is done in logarithms and the coefficient is never formed. Against exact whole-number arithmetic the figures agree to within 1e-9 at the largest sizes the page accepts, and to within 1e-12 at everyday ones, which is far inside the six decimal places it prints.
Exact combinatorial arithmetic done in logarithms so the binomial coefficients cannot overflow, for sampling without replacement from a finite population. That is the difference from the binomial distribution: every item you draw changes what is left to draw. A value outside the support returns exactly zero rather than a very small number.