ForHosting KIT · Math

Hypergeometric distribution

Find the chance of drawing an exact number of marked items without putting any back: from an urn of 10 balls with 4 red, drawing 3 gives exactly one red with probability one half. Works for cards, defective lots and tagged fish. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Population
10
Successes
4
Draws
3
K
1
You get
Probability
0.5
Mean
1.2
Variance
0.56

The hypergeometric distribution models how many marked items you observe when you draw a fixed-size sample and never put anything back. A finite population of size N holds exactly K success states; you take n draws; X is the number of successes in that sample. Unlike a binomial model, each draw changes the remaining mix, so successive trials are dependent. This calculator evaluates the probability mass P(X = k) from those four integers, using the combination ratio C(K, k) times C(N minus K, n minus k) over C(N, n).

How the hypergeometric distribution works without replacement

Start with a finite population of N distinct items of which exactly K are labelled success: aces in a deck, defectives in a lot, tagged fish in a lake, or winning tickets in an urn. You draw a sample of size n without replacement, so every subset of size n is equally likely and the order of the draws does not create extra combinations. Let X be the number of successes in that sample.

Then X follows a hypergeometric distribution, and the probability of observing exactly k successes is the combination C(K, k) times the combination C(N minus K, n minus k), divided by the combination C(N, n). The support of X is not simply zero through n: k cannot exceed K or n, and it cannot fall below max(0, n minus (N minus K)), because you may be forced to pick some successes once the non-success pool is exhausted.

A clean classroom check is an urn of ten balls with four red, drawing three, and asking for exactly one red: C(4, 1) times C(6, 2) over C(10, 3) equals one half. Another textbook case is a fifty-two-card deck with four aces, drawing five cards, and asking for exactly two aces.

This implementation never uses Monte Carlo sampling, random seeds, wall-clock time, or network lookups: it evaluates the mass in log-space so intermediate products stay well behaved for larger N, and it also returns the closed-form mean n times K over N and the finite-population variance.

What to enter and which counts are possible

Numeric integer strings are accepted so form widgets can submit text fields without client-side casting. Population must lie between zero and ten thousand inclusive. Successes and draws must be non-negative and cannot exceed the population.

Missing fields, non-integers, decimals where integers are required, and negatives fail the same way and are not billed. Example checks: population ten, successes four, draws three, k one yields probability one half; a fifty-two-card deck with four aces, five cards, and two aces yields the classic two-ace mass.

Where a hypergeometric distribution calculator earns its keep

Introductory statistics and discrete-math courses constantly ask for the chance of exactly k marked items in a hand or sample drawn without replacement, from poker-style card problems to fish-tag recapture sketches that motivate finite-population sampling. Quality engineers use the same mass function when a lot of size N contains K defectives and an inspector draws n units, needing the probability of finding exactly k bad pieces before accepting or rejecting the lot.

Ecologists and survey designers compare observed tag recoveries against hypergeometric expectations when the tagged count is known and sampling is without replacement. Data scientists validate Monte Carlo simulators of finite urns and card shuffles by comparing sampled frequencies against the closed-form mass for modest N before scaling simulations. Educators build answer keys and auto-graders that need a single deterministic value rather than a random simulation that would change between runs.

Game designers and probability demos often expose deck and urn defaults while still allowing full control of population, successes, draws, and k for teaching dependence on population composition. If you later need a cumulative left tail, Fisher's exact test tables, inverse quantiles, or independent-trial binomial odds with replacement, treat those as separate search intents rather than overloading this landing.

Keep N inside the documented bound so free-tier latency stays predictable, and remember that floating-point probability is ideal for ranking and thresholds while mean and variance describe the rest of the distribution.

Cards, urns, and statistics homework

Compute exact without-replacement probabilities for hands, urn draws, and textbook hypergeometric problems with deterministic answer keys.

Simulator and Monte Carlo checks

Validate finite-population sampling code against the closed-form hypergeometric PMF for modest N before trusting large-scale draws.

What formula does the hypergeometric distribution use?

The probability mass function P(X=k) = C(K,k) × C(N−K, n−k) / C(N,n), for sampling without replacement from a finite population of size N with K success states.

How is this different from a binomial distribution?

Binomial models independent trials with a fixed success chance (with replacement, or an infinite population). The hypergeometric distribution models draws without replacement from a finite population, so each draw changes the remaining mix.

Which four numbers do I send?

Send population (N), successes in the population (K), draws (n), and observed successes k. Integer strings are accepted. Successes and draws cannot exceed the population.

Why can't k be any number from zero up to the number of draws?

Because k can exceed neither the successes in the population nor the draws, and it cannot fall below the draws minus the non-successes. Once the non-success items run out, every further draw has to be a success.

What do the mean and variance tell me?

The mean is the number of successes you expect on average: draws times successes divided by population. The variance measures the spread around it for a finite population. In the urn example they are 1.2 and 0.56.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/stat/hypergeometric-distribution

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/stat/hypergeometric-distribution \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"population":10,"successes":4,"draws":3,"k":1}'
{
  "population": 10,
  "successes": 4,
  "draws": 3,
  "k": 1
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "stat.hypergeometric_distribution",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

min_population0
max_population10000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Requests that ask for more observed successes than draws are rejected with invalid_input instead of a silent zero.

Input contract, response fields, and the k-versus-draws error

POST a JSON body with four required integers: population (aliases population_size, N, or pop), successes (aliases success_count, K, or marked), draws (aliases n, sample, or sample_size), and k (aliases observed or sample_successes). On success the body echoes the four normalised integers, returns probability as an IEEE double in zero to one, includes mean and variance of the hypergeometric law for those parameters, and supplies formula as the string P(X=k) equals C(K,k) times C(N minus K, n minus k) over C(N,n). Pricing for successful API calls is the published base of $0.002 per item; the browser tool remains free.

Where a hypergeometric distribution calculator earns its keep

Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.

Lot inspection and quality control

Given a lot of size N with K defectives and a sample of n units, get P(exactly k defectives) for accept-or-reject teaching examples and fixtures.

What happens if k exceeds the number of draws?

The task fails with invalid_input. You cannot observe more successes than items drawn, so the request is rejected and is not billed.

What does the hypergeometric distribution calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →