Negative Binomial Distribution Calculator

Find the probability of getting exactly k failures before the r-th success, plus the cumulative probability, mean, and variance, for independent trials with success probability p.

Quick Facts

Formula
P(X=k) = C(k+r-1, k) · pr · (1-p)k
X = failures before the r-th success. Mean = r(1-p)/p, Variance = r(1-p)/p².

Your Results

Calculated
P(X = k)
-
Exactly k failures before the r-th success
P(X ≤ k)
-
Cumulative probability (at most k failures)
Mean
-
Expected number of failures
Variance
-
Spread of the distribution

Ready

Enter r, p, and k, then press Calculate.

Understanding the Negative Binomial Distribution

Negative Binomial PMF (failures before the r-th success):

P(X = k) = C(k + r - 1, k) × pr × (1 - p)k

r = number of successes to reach; k = number of failures before the r-th success (k = 0, 1, 2, …); p = probability of success on each trial. C(k+r-1, k) is the binomial coefficient "k+r-1 choose k".

The negative binomial distribution answers a question the ordinary binomial cannot: instead of fixing the number of trials and counting successes, it fixes the number of successes r and asks how many failures k pile up before you get there. Each trial is an independent Bernoulli experiment with the same success probability p. The last trial in the sequence is always a success (the r-th one), which is why the coefficient is C(k+r-1, k) rather than C(k+r, k) — you are only free to arrange the first k failures and r−1 successes among the first k+r−1 trials.

Why the formula has each piece

  • pr: every valid sequence contains exactly r successes, each contributing a factor of p.
  • (1 - p)k: it also contains exactly k failures, each contributing a factor of (1 - p).
  • C(k + r - 1, k): the number of distinct orderings of those k failures among the k+r−1 trials that precede the final, guaranteed r-th success.

Mean, variance, and over-dispersion

For this "number of failures" parameterization the expected number of failures is μ = r(1 - p)/p and the variance is σ² = r(1 - p)/p². Notice that the variance is always the mean divided by p, so it is strictly larger than the mean whenever p < 1. This "variance > mean" property, called over-dispersion, is exactly why statisticians reach for the negative binomial to model count data (insurance claims, disease cases, website purchases) that is too spread out for a Poisson model, where variance and mean are forced to be equal.

A worked example

Suppose you flip a fair coin (p = 0.5) and want the 3rd head (r = 3). What is the probability of exactly 2 tails before that 3rd head (k = 2)? Then C(2+3−1, 2) = C(4, 2) = 6, so P(X = 2) = 6 × 0.5³ × 0.5² = 6 × 0.03125 = 0.1875. On average you would expect r(1−p)/p = 3(0.5)/0.5 = 3 tails before the 3rd head.

Frequently Asked Questions

What does the negative binomial distribution model?
It models the number of failures k that occur before you reach a fixed number r of successes in a sequence of independent trials, each with the same success probability p. Classic examples: the number of tails before your 3rd heads, or the number of good parts inspected before you find the 5th defective one.
How is it different from the binomial distribution?
In the binomial distribution the number of trials n is fixed and the number of successes is random. In the negative binomial the number of successes r is fixed and the number of trials (or failures) needed to reach them is random. When r = 1 the negative binomial reduces to the geometric distribution — the number of failures before the very first success.
Why does k start at 0 instead of 1?
This calculator counts failures, and it is entirely possible to reach r successes with zero failures (for example, three heads in a row). If you prefer to count the total number of trials n, note that n = k + r, so the smallest possible n is r, not 0.
Can p be exactly 1?
Yes. If p = 1 every trial succeeds, so you reach r successes with exactly 0 failures: P(X = 0) = 1 and P(X = k) = 0 for all k > 0. The calculator handles p = 1 but rejects p = 0, because with p = 0 you would never reach r successes and the distribution is undefined.