Negative Binomial Distribution Calculator

Negative binomial: probability the r-th success happens on trial k, within k trials or after k trials, plus the mean and variance of the number of trials.

A whole number, 1 or more. With r = 1 this is the geometric distribution.
A decimal greater than 0 and at most 1. Trials are independent with the same p.
The trial on which you want the r-th success. Must be at least r, and at most 200,000.

Results

P(X = 5)
0.1875
P(X ≤ 5)
0.50
P(X > 5)
0.50
Mean number of trials (r ÷ p)
6.00
Variance (r(1 − p) ÷ p²)
6.00
Standard deviation
2.4495

How it’s calculated

The negative binomial distribution asks: how many independent trials does it take to get the r-th success, if each trial succeeds with probability p? It generalizes the geometric distribution (r = 1) and is often used for "how many tries until I have 3 sales" or "how many games until the 4th win".

P(X = k) = C(k − 1, r − 1) · p^r · (1 − p)^(k − r) for k = r, r + 1, … P(X ≤ k) = P(at least r successes in k trials) P(X > k) = P(at most r − 1 successes in k trials) mean = r ÷ p, variance = r(1 − p) ÷ p²

The factor C(k − 1, r − 1) counts the ways to place the first r − 1 successes among the first k − 1 trials; trial k itself must be the r-th success.

Worked example: a fair coin (p = 0.5). What is the chance the 3rd head comes on flip 5? C(4, 2) × 0.5³ × 0.5² = 6 ÷ 32 = 0.1875. The chance of getting 3 heads within 5 flips is (10 + 5 + 1) ÷ 32 = 0.5, so P(X > 5) is also 0.5. The mean number of flips is 3 ÷ 0.5 = 6, with variance 3 × 0.5 ÷ 0.25 = 6.

Some software counts only the failures before the r-th success. That variable is X − r, with mean r(1 − p) ÷ p and the same variance. This calculator counts all trials.

Frequently asked questions

How is it different from the binomial distribution?

The binomial fixes the number of trials and counts successes. The negative binomial fixes the number of successes and counts trials.

Why must k be at least r?

You need at least r trials to get r successes, so P(X = k) is 0 for smaller k.

What if my textbook counts failures instead of trials?

Let Y be the failures before the r-th success. Then Y = X − r, so P(Y = j) equals P(X = j + r) here, and the mean of Y is r(1 − p) ÷ p.

Is there an upper limit on k?

The calculator accepts k up to 200,000, which keeps the page fast. Beyond that the probabilities are usually tiny or the normal approximation is adequate.

Embed this calculator

Add this free calculator to your own website. Copy the code below into your page’s HTML:

Need this calculator branded, changed or built around your own prices?See custom business solutions →

Sources

Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.

Added · Last updated · How we check our calculators

Spotted a mistake or missing option? Report a problem· Suggest a calculator