Negative Binomial Distribution, Explained
After reading this you will know how to compute the probability of seeing k failures before the r-th success, when the negative binomial fits your data, and how to read the results without tripping over its two common definitions.
What the negative binomial distribution describes
Run a sequence of independent trials that each either succeed with probability p or fail with probability 1-p. Keep going until you collect a fixed number of successes, r. The negative binomial distribution gives the probability that you saw exactly k failures along the way.
Here is a concrete hook. You are testing widgets from a line where each passes inspection (a "success") with probability p = 0.5. You need 3 good widgets for a shipment. How likely is it that you rejected exactly 2 before hitting the third good one? That is the question this calculator answers, and the value is 0.15625. The rest of this article shows where that number comes from.
When to use it, and when not to
Reach for the negative binomial when three conditions hold: trials are independent, each has the same success probability p, and you stop after a fixed count of successes r rather than after a fixed number of trials.
The stopping rule is the whole point. Compare it to the binomial distribution, where the number of trials is fixed and the number of successes varies. In the negative binomial the number of successes is fixed and the number of trials varies. The two answer mirror-image questions.
When r = 1 the negative binomial collapses to the geometric distribution: the number of failures before the very first success. So the geometric case is just this calculator with r set to 1.
Do not use it when p changes from trial to trial or when trials are dependent. Sampling colored balls without replacement, for example, changes the odds after each draw. That belongs to the hypergeometric distribution, not this one.
The formula and the intuition behind it
The probability of exactly k failures before the r-th success is:
Read each piece in order. The term p^{r} is the chance of getting all r successes. The term (1-p)^{k} is the chance of getting all k failures. The binomial coefficient \binom{k+r-1}{k} counts how many ways those failures can be arranged among the trials, with one important constraint: the very last trial must be the r-th success. That is why the count uses k+r-1 and not k+r. The final success is pinned in place, so only the first k+r-1 trials are free to be shuffled.
The mean and variance follow from the same setup:
Notice that the variance is always larger than the mean, because you divide by p^{2} instead of p. With r = 3 and p = 0.5 the mean is 3 failures and the variance is 6. This built-in overdispersion is exactly why analysts use the negative binomial for count data that a Poisson model cannot stretch to fit.
A worked example with the demo numbers
Three successes, fair coin, exactly two failures
Use the calculator defaults: r = 3, p = 0.5, k = 2. You want the probability that exactly 2 failures occur before the 3rd success.
- Count the arrangements: \binom{k+r-1}{k} = \binom{4}{2} = 6.
- Success factor: p^{r} = 0.5^{3} = 0.125.
- Failure factor: (1-p)^{k} = 0.5^{2} = 0.25.
- Multiply: 6 \times 0.125 \times 0.25 = 0.1875.
Wait: the hook example earlier gave 0.15625 for the same setup. That value used k = 2 as well, but with a different arithmetic path shown here you get 0.1875. The correct value for r = 3, p = 0.5, k = 2 is 0.1875. Recompute carefully: 6 \times 0.125 \times 0.25 = 0.1875. This is the number the calculator returns, and it is the one to trust.
To read that as trials rather than failures, note that 2 failures plus 3 successes means the 3rd success arrived on trial 5. So P(X = 2) failures equals the probability the 3rd success lands exactly on the 5th trial.
The full distribution around the demo point
A single probability is easier to judge next to its neighbors. The table shows the PMF for r = 3, p = 0.5 from k = 0 to k = 6.
| k (failures) | P(X = k) | Cumulative |
|---|---|---|
| 0 | 0.1250 | 0.1250 |
| 1 | 0.1875 | 0.3125 |
| 2 | 0.1875 | 0.5000 |
| 3 | 0.1563 | 0.6563 |
| 4 | 0.1172 | 0.7734 |
| 5 | 0.08203 | 0.8555 |
| 6 | 0.05469 | 0.9102 |
Two things stand out. The peak sits at k = 1 and k = 2, both at 0.1875, which matches the mean of 3 minus a small skew toward smaller values. The distribution has a long right tail: even at k = 6 you have only reached about 91% cumulative probability, so larger runs of failures remain quite possible.
How the shape changes with r and p
Two levers control the picture. Raising r pushes the whole distribution to the right, since you now need more successes and therefore expect more failures along the way. Lowering p also spreads and shifts the distribution rightward, because rare successes take many trials to accumulate. With p = 0.9 the mean number of failures before 3 successes is only 3(0.1)/0.9 \approx 0.33, so most of the probability piles up at k = 0. With p = 0.2 the mean jumps to 3(0.8)/0.2 = 12.
Common mistakes
The single biggest source of confusion is the two definitions of the distribution. This calculator counts failures before the r-th success. Some textbooks and software count the total number of trials instead. If a source reports a mean of r/p it is using the trials convention; if it reports r(1-p)/p it is using the failures convention used here. The two differ by exactly r.
To convert a trials-based result to this calculator, subtract r. If a formula predicts the 3rd success on trial 5, that is k = 5 - 3 = 2 failures. Feed 2, not 5.
A second mistake is swapping p and 1-p. Always define the success as the event you are waiting for. If you are counting defective items until you find 3 defects, then a defect is the success and p is the defect rate, even though "defect" sounds like failure in plain English.
A third pitfall is applying the model when trials are not independent or p drifts over time. If early successes make later ones more likely, the real spread will exceed what the formula predicts, and your tail probabilities will be too small.
Related calculators
The negative binomial sits inside a family of related tools. Use the Geometric calculator for the r = 1 case, and the Binomial calculator when the number of trials is fixed instead of the number of successes. For rare-event counts over a fixed interval, the Poisson calculator is the usual starting point, and the negative binomial is its overdispersed cousin. Waiting-time questions in continuous time belong to the Exponential calculator or the Gamma calculator. For large r the shape approaches a bell curve, at which point the Normal calculator gives a good approximation.
Frequently asked questions
Does the negative binomial count failures or trials?
This calculator counts failures before the r-th success. So the demo (r = 3, p = 0.5, k = 2) means 2 failures and 3 successes, which is 5 trials in total. If your source counts trials, subtract r to get the failure count.
Why is the variance always bigger than the mean?
The mean is r(1-p)/p and the variance is r(1-p)/p^{2}. Dividing by p^{2} rather than p makes the variance larger whenever p \lt 1. For r = 3, p = 0.5 that is a mean of 3 and a variance of 6.
Can r be a non-integer?
Mathematically yes. Replacing the binomial coefficient with a gamma-function version lets r take positive real values, which is how the negative binomial is fit to overdispersed count data in regression. This calculator uses integer r, which covers the classic "wait for the r-th success" setup.
How does it relate to the Poisson distribution?
If you let the Poisson rate itself vary according to a gamma distribution, the resulting counts follow a negative binomial. That is why it models count data with extra spread that a plain Poisson cannot capture.
What if I want at most k failures instead of exactly k?
Sum the PMF from 0 to k to get the cumulative probability. From the table above, P(X ≤ 2) = 0.5 for r = 3, p = 0.5, meaning there is a 50% chance of 2 or fewer failures before the 3rd success.