Skip to content
Statistics

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.

Your details

The "failures" form asks how many failures occur before the r-th success. The "trials" form asks how many total trials are needed to achieve the r-th success. Both describe the same distribution - they are just different ways to count outcomes.
The target number of successes. Must be a positive integer. For example, r = 5 means you want to observe 5 successful outcomes.
The probability of success on any single trial. Must be strictly between 0 and 1. For example, p = 0.4 means each trial has a 40% chance of success.
The specific number of failures to evaluate. For example, k = 4 means you want P(exactly 4 failures before the r-th success).
Exact probability P(X = target)
0.092897

The probability mass function value at your specified outcome.

P(X < target)0.17367
P(X <= target)0.266568
P(X > target)0.733432
P(X >= target)0.82633
Mean (expected value)7.5
Variance18.75
Standard deviation4.3301
Mode5
P(X = target)0.092897
P(X <= target)0.266568
P(X > target)0.733432
00.5101325
Number of failures (k)
Probability
Number of failures (k)PMF - exact probabilityCDF - cumulative probability
00.010.01
10.030.04
20.060.1
30.080.17
40.090.27
50.10.37
60.10.47
70.090.56
80.090.65
90.070.72
100.060.78
110.050.83
120.040.87
130.030.91
140.020.93
150.020.95
160.010.96
170.010.97
180.010.98
190.010.99
2000.99
2100.99
2201
2301
2401
2501
  • PMF - exact probability
  • CDF - cumulative probability

P(X = 4) = 0.092897 for NB(r = 5, p = 0.4)

  • There is a 9.29% chance of observing exactly this outcome. The probability of achieving 5 successes on or before failure 4 is 26.66%.
  • On average, you expect 7.50 failures per 5 successes (with p = 0.4).
  • The most likely outcome (mode) is 5 failures. Your target is 1 failure below the mode.
  • Standard deviation is 4.3301, so roughly 95% of outcomes fall within about -1.2 to 16.2 failures.
  • More than half of outcomes exceed 4 failures (P(X > target) = 73.34%).

Next stepTo explore the full probability distribution, see the chart below. Switch to "Trials" mode to view total-trials results instead of failure counts.

Probability table for NB(r = 5, p = 0.4)

Failures kP(X = val)P(X <= val)P(X > val)
00.0102400.0102400.989760
10.0307200.0409600.959040
20.0552960.0962560.903744
30.0774140.1736700.826330
40.0928970.2665680.733432
50.1003290.3668970.633103
60.1003290.4672260.532774
70.0945960.5618220.438178
80.0851360.6469580.353042
90.0737850.7207430.279257
100.0619790.7827220.217278
110.0507100.8334330.166567
120.0405680.8740010.125999
130.0318300.9058310.094169
140.0245550.9303860.069614

Distribution table showing the probability mass function and cumulative probabilities for NB(r = 5, p = 0.4). Values shown for the most probable range.

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

DistributionQuestion answeredFixedRandomMean
GeometricTrials until first successpTotal trials x1/p
Neg. Binomial (trials)Trials until r-th successr, pTotal trials xr/p
Neg. Binomial (failures)Failures before r-th successr, pFailures kr(1-p)/p
BinomialSuccesses in n trialsn, pSuccesses knp

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

Sources

Written by Dr. Hannah Brandt, PhD Statistician · Munich, Germany

Applied statistician translating rigorous probability theory into clear, accurate tools for researchers and practitioners.

Search 3,500+ calculators

Loading search…