Negative Binomial Distribution Calculator
Enter the number of successes (r), the probability of success on each trial (p), and your target outcome. Instantly get the exact probability, all four cumulative variants, the mean, variance, and standard deviation - with a full distribution chart and step-by-step working. Toggle between the failures-before-success and total-trials parameterizations.
What is the negative binomial distribution?
The negative binomial distribution models the number of trials (or failures) needed in a sequence of independent Bernoulli trials until a fixed number of successes is achieved. Each trial is independent, and each has the same probability of success p. It naturally answers questions like: "How many times do I need to roll a die before getting three sixes?" or "How many sales calls must I make before closing five deals?" The distribution has two common parameterizations. The failures form counts the number of failures (k) occurring before the r-th success. The trials form counts the total number of trials (x) needed to achieve the r-th success. Both represent the same underlying distribution - the choice between them is one of convention and convenience.
How to use this calculator
Choose whether you want to work with failure counts or total trial counts using the Parameterization selector. Enter the number of successes you are targeting (r) and the probability of success on each trial (p). Then enter your specific outcome - either the number of failures k (in failures mode) or the total number of trials x (in trials mode). The calculator returns the exact probability for that outcome, all four cumulative probability variants, the distribution mean, variance, and standard deviation, and the mode. The distribution chart shows the full PMF and CDF curves so you can visualize the distribution around your target. The probability table provides numeric values for a range of outcomes in one view.
The formulas in detail
Failures parameterization - P(Y = k) = C(k + r - 1, r - 1) x p^r x (1-p)^k, where C(n,k) is the binomial coefficient "n choose k". The mean is r(1-p)/p and the variance is r(1-p)/p^2. The mode (most likely value) is floor((r-1)(1-p)/p) for r greater than 1, or 0 when r = 1. Trials parameterization - P(X = x) = C(x - 1, r - 1) x p^r x (1-p)^(x-r), where x >= r. The mean is r/p and the variance is again r(1-p)/p^2 (variance is the same in both forms because the only difference is the baseline of counting). Note that if r = 1, the distribution reduces to the geometric distribution. Binomial coefficients are computed in log-space for numerical stability at large values.
Real-world applications
The negative binomial distribution appears across many fields. In epidemiology and ecology, it models over-dispersed count data where the variance is larger than the mean - a common situation when individuals cluster spatially or when infection rates vary between people. In quality control, it determines how many items must be inspected before finding a fixed number of defectives. In clinical trials, it models the number of adverse events before a certain threshold is reached. In sports analytics, it models the number of at-bats before a batter achieves a set number of hits. In marketing, it models how many contacts must be made before a fixed number of conversions. When the assumption of a fixed p across all trials is met, and trials are independent, the negative binomial is the appropriate exact model rather than an approximation.
Distribution comparison: Geometric, Negative Binomial, and Binomial
| Distribution | Question answered | Fixed | Random | Mean |
|---|---|---|---|---|
| Geometric | Trials until first success | p | Total trials x | 1/p |
| Neg. Binomial (trials) | Trials until r-th success | r, p | Total trials x | r/p |
| Neg. Binomial (failures) | Failures before r-th success | r, p | Failures k | r(1-p)/p |
| Binomial | Successes in n trials | n, p | Successes k | np |
The negative binomial generalizes the geometric distribution (r = 1 case) and is related to the binomial. Understanding the relationships helps you pick the right model.
Frequently asked questions
What is the difference between the failures and trials parameterizations?
Both describe the same distribution. The failures form asks: "how many failures occur before the r-th success?" The trials form asks: "how many total trials are needed to observe the r-th success?" If you have k failures before the r-th success, then you needed x = k + r total trials. The two forms are connected by x = k + r. The PMF formulas differ in notation but give the same probabilities when you account for this shift. Choose whichever framing matches the way your problem is stated.
How does the negative binomial relate to the geometric distribution?
The geometric distribution is a special case of the negative binomial with r = 1. It models the number of trials until the first success. The negative binomial with r = 1 gives exactly geometric probabilities. When r > 1, the negative binomial extends this idea to waiting for the r-th success, and the sum of r independent geometric random variables (each with probability p) follows a negative binomial distribution.
When should I use the negative binomial instead of the Poisson distribution?
Use the Poisson when you are counting events in a fixed interval of time or space with a known average rate and no clustering. Use the negative binomial when your count data shows over-dispersion, meaning the variance is greater than the mean. The negative binomial has an extra parameter (r) that controls the degree of over-dispersion: as r becomes very large, the negative binomial approaches a Poisson distribution. In practice, the negative binomial is widely used in RNA-sequencing data analysis, insurance claim modeling, and epidemiology precisely because real data is often more spread out than a Poisson model allows.
What are valid values for r and p?
The number of successes r must be a positive integer (1, 2, 3, ...). The probability p must be strictly between 0 and 1 - values of 0 or 1 make the distribution degenerate. In the failures parameterization, the number of failures k can be any non-negative integer (0, 1, 2, ...). In the trials parameterization, the total trials x must be at least r, because you cannot observe r successes in fewer than r trials.
Why does my PMF not sum to exactly 1?
Numerically, if you sum the PMF from k = 0 to infinity (or x = r to infinity), the total is exactly 1. However, when you sum only a finite range, you get less than 1, with the difference being the probability mass in the omitted tail. Very large k values have negligibly small PMF values, so the truncated table typically accounts for 99%+ of the probability. If you are computing cumulative probabilities, the CDF at very large values should reach 1 within floating-point precision.
What does the variance tell me about the distribution?
Variance = r(1-p)/p^2. A higher variance means outcomes are more spread out around the mean. With low p (rare successes), both the mean and variance grow large - it takes many more trials on average and the actual number can vary widely. With high p (frequent successes), the mean is small and the distribution is concentrated near it. The ratio of variance to mean equals (1-p)/p, which is always greater than 0 for a valid probability, confirming that the negative binomial is always over-dispersed relative to the Poisson (for which variance = mean).