ForHosting KIT · Math

Negative binomial calculator

With a success chance of 0.4 per trial, the third success lands exactly on trial 8 just over 10 percent of the time, and on average it arrives at trial 7.5. Enter the successes needed, the trial and the chance. 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
Resistance (Ω)
3
K
8
Power (W)
0.4
You get
Probability
0.10450944
Mean
7.5
Variance
11.25
Formula pmf
P(X=k) = C(k-1,r-1) * p^r * (1-p)^(k-r)

You supply the required success count r, the trial index k (which must be at least r), and the success probability p on the unit interval. The engine returns the point probability from the negative binomial mass function, together with the mean and variance of the trial-number random variable when p is positive. Arithmetic is deterministic floating-point with a log-space binomial coefficient path, so the same inputs always produce the same outputs without network calls or random sampling.

What the negative binomial tells you

A negative binomial experiment in the trial-number parameterization keeps running independent Bernoulli trials with fixed success probability p until a prescribed number of successes r has been reached. If X denotes the trial index on which that r-th success occurs, then X takes values r, r plus one, r plus two, and so on, and its probability mass function is P(X equals k) equals the binomial coefficient C(k minus one, r minus one) times p to the r times (1 minus p) to the power of k minus r.

That formula encodes a simple story: among the first k minus one trials there must be exactly r minus one successes (and therefore k minus r failures), and trial k itself must be a success. This calculator returns that point probability, echoes the normalized r, k, and p, attaches the PMF formula string so learners can cross-check by hand, and includes mean r over p and variance r times (1 minus p) over p squared when p is strictly positive.

When p equals zero the mean and variance are returned as null because the waiting time for a success is infinite in the model, while the probability mass for any finite k and r greater than or equal to one is zero. The contract is intentionally strict. The trial index k must be an integer at least r and at most the published maximum; k below r is rejected rather than returning a silent zero that could hide an off-by-one bug in a caller.

If you need the ordinary binomial P of exactly k successes in a fixed n trials, use the dedicated binomial calculator; here the search intent is the probability that the r-th success occurs on trial k, with exact formulas and free browser execution.

How r, k, and p are read and how the PMF is computed

Optional leading plus signs on integers are allowed; embedded spaces, hex prefixes, negative signs where forbidden, and exponential notation on integer fields are rejected so a bad spreadsheet cell does not become a wrong probability. Probability p accepts ordinary decimal numbers and scientific notation as a finite real, then enforces the closed unit interval with an explicit error that names the field when the value falls outside zero to one.

After parsing, the engine checks that k is at least r and rejects earlier trial indices with a message that names both values. Computation of the mass function uses logarithms: log C(k minus one, r minus one) is built from a multiplicative product of ratios, then r log p and (k minus r) log (1 minus p) are added, and the exponential recovers a probability in zero to one. That path avoids intermediate overflow that full factorials would cause for moderate k.

Boundary cases p equals zero and p equals one short-circuit to exact zero or one masses without taking logs of zero: with p equals one the r-th success always occurs on trial r, and with p equals zero no finite trial ever delivers r successes. Mean and variance use the closed forms r over p and r times (1 minus p) over p squared when p is positive.

Where negative binomial probabilities fit in study, reliability, and code

Students meet the negative binomial distribution when a textbook asks for the chance that the third heads appears on the eighth toss of a biased coin, when a worksheet wants the probability that the fifth defective item is found on the twentieth inspection, or when they verify that the mean and variance formulas match the definition from the probability mass function. Teachers can pre-generate answer keys for modest r and k without trusting opaque calculator apps that round intermediate coefficients or hide which parameterization is in use.

Reliability and operations teams sketch waiting-time models: keep testing units until r failures are observed, with p the failure probability per unit, and ask how likely it is that the r-th failure lands on unit k. Product and growth analysts use the same structure for conversion funnels that stop after a target number of successful events, for example the chance that the r-th signup occurs on the k-th visit if each visit converts with probability p.

Developers call the contract from scripts to seed deterministic test vectors, to illustrate log-space coefficient tricks, or to satisfy programming-challenge statements that demand P of the r-th success on trial k for given r, k, and p. Contest practice often needs a fast offline source of negative binomial values so solutions can be checked without embedding large static tables by hand.

Homework and exam preparation

Look up exact negative binomial P(X=k) for textbook waiting-time exercises with known r, k, and p, plus mean and variance checks.

Reliability and conversion waiting times

Model how likely the r-th failure or conversion lands on trial k given a fixed per-trial success probability p.

What does the negative binomial calculator cost?

It is free in your browser on this page.

What formula is used for P(X = k)?

P(X = k) = C(k − 1, r − 1) · p^r · (1 − p)^(k − r), the probability that the r-th success occurs on trial k for independent Bernoulli trials with success probability p.

What happens if p is outside 0 to 1?

The success probability must lie in the closed interval from zero to one.

What if k is less than r?

The r-th success cannot occur before trial r, so k must be an integer at least r.

What are the mean and variance of the trial-number random variable?

When p is positive, the mean is r / p and the variance is r (1 − p) / p². When p equals zero they are returned as null because the waiting time is infinite in the model.

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/prob/negative-binomial

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/prob/negative-binomial \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"r":3,"k":8,"p":0.4}'
{
  "r": 3,
  "k": 8,
  "p": 0.4
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "prob.negative_binomial",
  "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.

max_k1000
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.

The negative binomial calculator answers a classic waiting-time question in discrete probability: if each independent trial succeeds with probability p, what is the chance that the r-th success lands exactly on trial k? Edge cases are explicit: p equals zero or one yield exact zero-one masses where the definition allows, any p outside the closed unit interval is rejected with invalid_input rather than clamped, and any k below r is rejected because the r-th success cannot occur before trial r.

What the negative binomial answers and what the response contains

Probability p must lie in the closed interval from zero to one; values below zero or above one are invalid_input, not clipped.

How r, k, and p are read and how the PMF is computed

The preferred fields are r for the required success count, k for the trial number of that r-th success, and p for the per-trial success probability, but aliases are accepted so forms and scripts can reuse familiar names. For r the aliases are successes, num_successes, and target_successes; for k they are trial, trials, and n; for p they are probability, success_prob, and prob. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing negative-binomial coefficients yourself.

Where negative binomial probabilities fit in study, reliability, and code

On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result. Pair it with the binomial probability calculator when the number of trials is fixed instead of the number of successes, with combinatorial counters when you need only C(n, k), and with other math endpoints when you are building a small lab of free, deterministic probability helpers.

Deterministic test fixtures

Generate reproducible probability, mean, and variance fields for unit tests and CI assertions without hand-rolled negative binomial formulas.

Read the full KIT documentation →