Formula: Hypergeometric Probability Formula
- populationSizeN: Population Size N (N)
- successStatesInPopK: Success States In Pop K (K)
- sampleDrawsCountSmallN: Sample Draws Count Small N (n draws)
- observedSuccessesSmallK: Observed Successes Small K (k)
Compute exact probability P(X=k) when drawing n items without replacement from population N.
It evaluates P(X = k) = [ C(K, k) × C(N − K, n − k) ] / C(N, n); Mean = n × (K / N) directly in your browser and updates three custom SVG visualizations in real time.
The binomial assumes each draw has the same chance, which is only true with replacement. Without replacement the chance changes after every draw. For the default hand, the binomial gives about 26.4% for two hearts, while the exact answer is 27.428%. The gap shrinks when the sample is a small share of a large population.
Set k to 0, read the probability, and subtract it from 100%. For the default hand, no hearts is 22.153%, so at least one heart is 77.847%. For an audit of 10 invoices from 80 with 8 errors, the chance of finding nothing is 32.567%, so the chance of finding at least one error is 67.433%.
It is C(N, n), the number of different samples of size n that can be drawn from N items when order does not matter. For five cards from 52 it is 2,598,960 hands. Every probability on the page is a count of favourable samples divided by this number, so it is the denominator you use when checking by hand.
The expected count is an average and need not be a whole number. For five cards it is 1.25 hearts, while the single most likely outcome is one heart at 41.142%. The distribution is skewed to the right, and the less common hands with three or more hearts pull the average above the peak.
When the sample is a noticeable share of the population. The factor is (N minus n) over (N minus 1). For 5 cards from 52 it is about 0.92, a modest reduction in variance. If you sample half the population it falls to about a half. If the sample is under a few percent of the population it is close enough to 1 to ignore.
No, the page wants a whole number for K. Convert the rate yourself: multiply the population by the share of successes and round to a whole item. A 15% defect rate in a lot of 40 means K of 6. If the product is not a whole number, the rate you have is an estimate, and you may want to try the counts on either side.
No. The hypergeometric probability counts samples, not sequences. Drawing two hearts first and then three other cards has the same chance as any other arrangement of two hearts in five. When you work it out in sequence by hand, multiply the single-order probability by the number of arrangements, which is C(n, k).
The page refuses it with an error, since you cannot get more successes than items drawn. Asking for 7 hearts in a five-card hand produces a message asking for k no larger than n. If k is within the draws but larger than the number of successes in the population, the page instead reports 0%, which is the correct probability.
Yes, for the main numbers. Set the population to 49, successes and draws to 6, and k to the number of matches. Three matches comes out at 1.765%. Lotteries with a separate bonus ball drawn from another pool need two calculations multiplied together, because the bonus is not part of the same hypergeometric draw.
Try sample sizes on the page with k at 0 until the probability of finding nothing falls below the risk you can accept. For 80 items with 8 errors, a sample of 10 misses all errors 32.567% of the time. Larger samples cut that figure. Your audit standard may set the acceptable risk, so check it rather than picking a number at random.
With K at 0 and k at 0, it reports P(X = 0) = 100%, an expected count of 0 and an SD of 0, because a sample cannot contain items that are not there. Any k above 0 gives 0%. The case is trivial, but it is handy for testing a spreadsheet or script that should handle the same edge without dividing by zero.
No. With replacement every draw has the same chance of success, so the binomial distribution is the right model. You can get close with this page by making the population very large while keeping the share of successes fixed, but a binomial calculator is simpler. For a small population the two answers differ, as the default hand shows.
The default inputs describe a familiar case. A deck of 52 cards holds 13 hearts. You deal five cards without putting any back and ask how likely it is that exactly two of them are hearts. The page answers 27.428%, a little better than one hand in four.
The supporting lines add context. On average a five-card hand holds 1.25 hearts, which is simply five times the share of hearts in the deck, 13 out of 52. The standard deviation is 0.93, so most hands land between zero and two hearts. The last line, 2,598,960 ways, is the number of distinct five-card hands a 52-card deck can produce, and it is the denominator of every probability on the page.
What makes this hypergeometric rather than binomial is that cards are not replaced. Once a heart leaves the deck, there are fewer hearts left for the next card. Each draw changes the odds for the draws that follow, and the formula accounts for that exactly.
The counting method uses combinations. Choose 2 of the 13 hearts: C(13, 2) is 13 times 12 divided by 2, which is 78. Choose the other 3 cards from the 39 non-hearts: C(39, 3) is 39 times 38 times 37 divided by 6, which simplifies to 13 times 19 times 37. Multiply those two counts together and divide by 2,598,960 to get 0.27428.
The sequential method is often easier with a calculator in hand. Work out the chance of one particular order, say heart, heart, then three non-hearts. That is 13/52 times 12/51 times 39/50 times 38/49 times 37/48, about 0.027428. The two hearts can sit in any 2 of the 5 positions, and there are C(5, 2) = 10 such arrangements, so multiply by 10. The result is again 0.27428.
Both methods use only numbers you can see in the problem, so they make a good test for a spreadsheet or a script. If your own code gives a different figure, the usual culprit is a binomial formula used by mistake, which for this hand gives about 26.4% instead of 27.4%.
The page computes one value of k at a time, but running it six times gives the whole distribution for a five-card hand. No hearts: 22.153%. One heart: 41.142%. Two hearts: 27.428%. Three: 8.154%. Four: 1.073%. All five: 0.05%. The six add to 100%, give or take rounding.
The most likely outcome is one heart, not the average of 1.25. That is normal for a skewed count. The mean is pulled upward by the hands with three or more hearts, while the single most common hand has just one.
Questions about at least or at most need sums. The chance of at least two hearts is 27.428 + 8.154 + 1.073 + 0.05, which comes to 36.705%. It is quicker to subtract the small end from 100: 100 minus 22.153 minus 41.142 gives the same 36.705%. The page has no cumulative line, so this addition is something you do yourself.
The expected count is n times K over N. For the default that is 5 times 13 over 52, or 1.25. It is the same mean you would get with replacement, which surprises people. Removing cards changes the spread of the result, not its centre.
The variance starts from the binomial version, n times p times (1 minus p), and multiplies by (N minus n) over (N minus 1). For the default hand that is 5 times 0.25 times 0.75, which is 0.9375, multiplied by 47 over 51. The result is about 0.864, and its square root is the 0.93 SD on the card.
That last factor is the finite-population correction. Here it is about 0.92, so the without-replacement SD is a little smaller than the binomial SD of about 0.968. The correction matters most when the sample is a large share of the population. Draw 26 cards from 52 and the factor falls to about a half. Draw 5 from a population of thousands and it is so close to 1 that the binomial formula works just as well.
For quick estimates the mean and SD are often enough. Two SDs either side of 1.25 runs from below zero to about 3.1, so a five-card hand with four or five hearts sits well outside the usual range. The exact probabilities, 1.073% and 0.05%, confirm how rare those hands are.
The preset comparisons keep 13 successes and 5 draws while changing the population size. With 31 items in total, 13 of them successes, P(X = 2) rises to 37.46%. The expected count is 2.097 and the SD 1.027. There are 169,911 possible samples.
With 78 items, P(X = 2) drops to 16.139%, the mean to 0.833 and the SD to 0.811, from 21,111,090 possible samples. The pattern is about the share of successes, not the size alone. Thirteen out of 31 is about 42% successes, so two in five is near the middle. Thirteen out of 78 is only about 17%, so two successes is already above average.
When you use the page for something other than cards, change K and N together if the share of successes in the population is what you know. A shipment that is 10% defective at 50 items has K of 5. The same rate at 80 items has K of 8.
Auditors and quality inspectors use this distribution to ask how likely a sample is to miss problems altogether. Suppose a batch of 80 invoices contains 8 with errors, and you check 10 at random. Set N to 80, K to 8, n to 10 and k to 0. The page gives 32.567%. Roughly one sample in three would find no errors at all, even though 10% of the batch is wrong.
The complement is the chance the sample catches at least one error: 100 minus 32.567, or 67.433%. The expected number found is 1 and the SD is 0.893. Those figures say a sample of 10 is a weak test for an error rate this low. Doubling the sample would raise the detection chance, and you can find how far by running the page again with n at 20.
This is also how acceptance sampling plans are built. You choose a sample size and a pass rule, such as accept the lot if no defects are found, and then read off the probability of accepting a lot with a given number of bad items. The page handles one point on that curve at a time.
A 6 from 49 lottery is a hypergeometric draw. The population is 49 numbers, the six you picked are the successes, the draw takes six numbers, and k is how many of yours come up. With k of 3 the page gives 1.765%, so about one ticket in 57 matches exactly three numbers. The expected number of matches is 0.735 and the SD 0.76.
Card games are the classic use. The chance that a five-card hand contains exactly one ace is 29.947%, from N of 52, K of 4, n of 5 and k of 1. The expected count of aces in five cards is 0.385. For two specific card types at once, such as exactly one ace and one king, you need the multivariate version, which this page does not cover.
Ecologists use the same mathematics for capture and recapture. Mark some animals, release them, then catch a second sample and count marked ones. The hypergeometric probability describes how many marked animals a sample should contain for a given population size.
Each of these problems has the same four slots. Decide what the population is, what counts as a success, how many items are taken, and which count you care about. Most mistakes come from mixing up the two small letters. The draw size n is how many items you take; k is how many of those turn out to be successes. If you swap them on the default inputs, asking for five successes in two draws, the page returns an error, because k cannot be larger than the number of draws.
All four inputs must be whole numbers, since they are counts. The page also checks that the counts fit together: K cannot exceed N, the draws n must be at least 1 and no more than N, and k cannot exceed n. Break any of those rules and the page returns an error explaining which one, rather than quietly changing your numbers. Ask for P(X = 7) on a five-card hand and you get that message, not a figure.
Some combinations are allowed but have a probability of exactly 0, and the page reports 0% for them. If k is larger than K, the sample cannot hold more successes than exist. If the draws are more than the failures in the population, some successes are forced. Take 8 items with 5 successes and draw 5: only 3 failures exist, so at least 2 successes must appear. Set k to 1 and the page shows 0% out of 56 possible samples, which is correct.
A population with no successes works too. With K at 0 and k at 0, the page gives P(X = 0) = 100%, an expected count of 0 and an SD of 0. That is a trivial case, but it is a useful check that a script handles the edge in the same way.