Written and maintained by CASRAI Editorial Board
Last updated
The moment generating function (MGF) of a binomial random variable X with n trials and success probability p is M(t) = (pet + 1 − p)n, defined for every real t. Differentiating it at t = 0 gives the mean np and, after one subtraction, the variance np(1 − p); multiplying two such functions shows that independent binomial counts with the same p add up to another binomial. This guide derives the result with the binomial theorem, works the numbers for n = 10 and p = 0.3 with the arithmetic shown, and checks the answer in Excel, R and Python.
Definition in one paragraph: moment generating function of the binomial distribution
The moment generating function of a random variable X is M(t) = E[etX], the expected value of etX viewed as a function of t. When it exists on an interval around t = 0, its derivatives at 0 are the raw moments of X: M′(0) = E[X], M″(0) = E[X2], and so on. A binomial variable counts successes in n independent trials that each succeed with probability p, so its MGF is a finite sum and exists for all real t. For the distribution itself see the CASRAI guide to the probability mass function and the random variable concept it builds on.
Formula: moment generating function for the binomial distribution
If X ~ Binomial(n, p) and q = 1 − p, then
MX(t) = (pet + q)n = (pet + 1 − p)n
- X: the number of successes, an integer from 0 to n.
- n: the number of trials. Wolfram MathWorld writes this as N and uses n for the number of successes, so check which letter a source uses before copying a formula.
- p: the probability of success on each trial, with 0 ≤ p ≤ 1; q = 1 − p is the probability of failure.
- t: a real number that acts only as a dummy argument; you evaluate derivatives at t = 0.
- et: the exponential function evaluated at t.
The NIST/SEMATECH e-Handbook of Statistical Methods gives the probability mass function as P(x; p, n) = C(n, x) px (1 − p)n−x for x = 0, 1, …, n, where C(n, x) = n!/(x!(n − x)!), and states the mean as np and the standard deviation as √(np(1 − p)). Wolfram MathWorld lists the moment generating function (pet + 1 − p)N, the mean Np, and the second central moment Npq.
Derivation with the binomial theorem
- Start from the definition: M(t) = E[etX] = Σx=0n etx · C(n, x) px qn−x.
- Combine the exponentials: etx px = (pet)x, so M(t) = Σ C(n, x) (pet)x qn−x.
- The binomial theorem says Σ C(n, x) ax bn−x = (a + b)n. Here a = pet and b = q.
- Therefore M(t) = (pet + q)n.
A shorter route uses a Bernoulli variable, which takes the value 1 with probability p and 0 otherwise. Its MGF is E[etB] = pet + q. A binomial variable is the sum of n independent copies, and the MGF of an independent sum is the product of the MGFs, so the result is (pet + q)n again. The Bernoulli distribution and the Bernoulli versus binomial comparison cover that relationship in detail.
Worked example with real numbers: n = 10, p = 0.3
Let X ~ Binomial(10, 0.3), so q = 0.7 and M(t) = (0.3et + 0.7)10.
Mean from the first derivative
By the chain rule, M′(t) = 10 (0.3et + 0.7)9 · 0.3et = 3et (0.3et + 0.7)9. At t = 0, e0 = 1 and 0.3 + 0.7 = 1, so M′(0) = 3 × 1 × 1 = 3. This equals np = 10 × 0.3 = 3.
Variance from the second derivative
Apply the product rule to M′(t) = 3et (0.3et + 0.7)9:
M″(t) = 3et (0.3et + 0.7)9 + 3et · 9 (0.3et + 0.7)8 · 0.3et.
At t = 0 both brackets equal 1, so M″(0) = 3 + 3 × 9 × 0.3 = 3 + 8.1 = 11.1. This is E[X2], not the variance. The variance is Var(X) = M″(0) − [M′(0)]2 = 11.1 − 32 = 11.1 − 9 = 2.1, which equals np(1 − p) = 10 × 0.3 × 0.7 = 2.1. The standard deviation is √2.1 ≈ 1.449.
A numeric check of the formula itself
At t = 0.5, e0.5 ≈ 1.648721, so 0.3 × 1.648721 + 0.7 ≈ 1.194616 and M(0.5) = 1.19461610 ≈ 5.9195. Summing e0.5x times the binomial probability over x = 0 to 10 gives the same value, 5.9195, which confirms that the closed form and the definition agree.
Interpretation: reading the binomial MGF
| Quantity | How to get it from M(t) | Binomial result | Example (n = 10, p = 0.3) |
|---|---|---|---|
| Total probability | M(0) | 1 | 1 |
| Mean | M′(0) | np | 3 |
| Second raw moment | M″(0) | np(1 − p) + (np)2 | 11.1 |
| Variance | M″(0) − [M′(0)]2 | np(1 − p) | 2.1 |
Two further properties follow from the form (pet + q)n. First, if X1 ~ Binomial(n1, p) and X2 ~ Binomial(n2, p) are independent, the MGF of X1 + X2 is (pet + q)n1 (pet + q)n2 = (pet + q)n1+n2, so the sum is Binomial(n1 + n2, p). Second, taking the logarithm turns the power into a multiple: ln M(t) = n ln(pet + q), so the mean and variance both scale linearly with n. For a related count model see the Poisson distribution moment generating function, and for the mean on its own the binomial distribution expected value guide.
Assumptions and common mistakes
- Fixed n and constant p. The formula assumes a fixed number of independent trials with the same success probability. If p changes between trials, the MGF is a product of different factors (piet + qi), not a single power.
- The sum rule needs the same p. Independent binomials with different p values do not add to a binomial.
- Mixing up n, N and x. Some sources use N for trials and n for successes. Match the letters to the source you are following.
- Writing et where etx belongs. The MGF is E[etX]; inside the sum each term carries etx, and only after the binomial theorem does it collapse to (pet)x.
- Stopping at M″(0). The second derivative at 0 is E[X2]. Subtract the squared mean to get the variance.
- Forgetting to set t = 0. Derivatives of M(t) are functions of t until you evaluate them at 0.
How to report it (APA example)
Example wording for a methods note or problem solution: The number of successes was modelled as X ~ Binomial(10, 0.3). Its moment generating function is M(t) = (0.3et + 0.7)10, giving E(X) = M′(0) = 3 and Var(X) = M″(0) − [M′(0)]2 = 2.1 (Weisstein, n.d.; National Institute of Standards and Technology, n.d.).
Reference list entries in the same style:
- National Institute of Standards and Technology. (n.d.). Binomial distribution. In NIST/SEMATECH e-handbook of statistical methods. https://www.itl.nist.gov/div898/handbook/eda/section3/eda366i.htm
- Weisstein, E. W. (n.d.). Binomial distribution. Wolfram MathWorld. https://mathworld.wolfram.com/BinomialDistribution.html
How to calculate it in Excel, R or Python
Each snippet evaluates the closed form (0.3et + 0.7)10 at t = 0.5 and compares it with the defining sum of etx times the binomial probability. Both return about 5.9195.
Excel
Closed form: =(0.3*EXP(0.5)+0.7)^10
Defining sum (x = 0..10 in A2:A12):
=SUMPRODUCT(BINOM.DIST(A2:A12,10,0.3,FALSE)*EXP(0.5*A2:A12))
R
t <- 0.5; n <- 10; p <- 0.3
(p * exp(t) + 1 - p)^n
sum(dbinom(0:n, n, p) * exp(t * (0:n)))
Python
from math import comb, exp
n, p, t = 10, 0.3, 0.5
closed = (p * exp(t) + 1 - p) ** n
summed = sum(comb(n, x) * p**x * (1 - p)**(n - x) * exp(t * x) for x in range(n + 1))
print(closed, summed) # both about 5.9195
FAQ
What is the moment generating function of the binomial distribution?
It is M(t) = (pet + 1 − p)n, where n is the number of trials and p is the success probability. It is defined for all real t.
How do you get the mean and variance from the binomial moment generating function?
Differentiate once and set t = 0 to get the mean np. Differentiate twice, set t = 0 to get E[X2], and subtract the squared mean to get the variance np(1 − p). For n = 10 and p = 0.3 these are 3 and 2.1.
Why is the binomial MGF the n-th power of the Bernoulli MGF?
A binomial variable is the sum of n independent Bernoulli variables with the same p, and the MGF of an independent sum is the product of the individual MGFs.
Does the binomial MGF exist for every t?
Yes. The sum has finitely many terms, so M(t) is finite for every real t, unlike distributions whose MGF exists only on part of the real line.
Sources
- Weisstein, E. W. Binomial distribution. Wolfram MathWorld (checked 2026-10-29).
- National Institute of Standards and Technology. Binomial distribution, NIST/SEMATECH e-Handbook of Statistical Methods (checked 2026-10-29).








