The mean and the variance of a random variable *X* with a binomial probability distribution can be difficult to calculate directly. Although it can be clear what needs to be done in using the definition of the expected value of *X* and *X*^{2}, the actual execution of these steps is a tricky juggling of algebra and summations. An alternate way to determine the mean and variance of a binomial distribution is to use the moment generating function for *X*.

### Binomial Random Variable

We start with our random variable *X* and describe the probability distribution more specifically. We perform *n* independent Bernoulli trials, each of which has probability of success *p* and probability of failure 1 - *p*. Thus the probability mass function is

*f* (*x*) = *C*(*n* , *x*)*p ^{x}*(1 –

*p*)

^{n - x}

Here the term *C*(*n* , *x*) denotes the number of combinations of *n* elements taken *x* at a time, and *x* can take the values 0, 1, 2, 3, . . ., *n*.

### Moment Generating Function

We use this probability mass function to obtain the moment generating function of *X*:

*M*(*t*) = Σ_{x = 0}^{n} *e ^{tx}*

*C*(

*n*,

*x*)>)

*p*(1 –

^{x}*p*)

^{n - x}.

We see that we can combine the terms with exponent of *x*:

*M*(*t*) = Σ_{x = 0}^{n} (*pe ^{t}*)

^{x}

*C*(

*n*,

*x*)>)(1 –

*p*)

^{n - x}.

Furthermore, by use of the binomial formula, the above expression is simply:

*M*(*t*) = [(1 – *p*) + *pe ^{t}*]

^{n}.

### Calculation of the Mean

In order to find the mean and variance, we need to know both *M*’(0) and *M*’’(0). We begin by calculating our derivatives, and then we evaluate each of them at *t* = 0.

We see that the first derivative of the moment generating function is:

*M*’(*t*) = *n*(*pe ^{t}*)[(1 –

*p*) +

*pe*]

^{t}^{n - 1}.

From this we can calculate the mean of our probability distribution. *M*(0) = *n*(*pe*^{0})[(1 – *p*) + *pe*^{0}]^{n - 1} = *np*. This matches the expression that we obtained directly from the definition of the mean.

### Calculation of the Variance

The calculation of the variance is performed in a similar manner. We first differentiate the moment generating function again, and then we evaluate this derivative at *t* = 0. Here we see that

*M*’’(*t*) = *n*(*n* - 1)(*pe ^{t}*)

^{2}[(1 –

*p*) +

*pe*]

^{t}^{n - 2}+

*n*(

*pe*

^{t})[(1 –

*p*) +

*pe*

^{t}]

^{n - 1}.

To calculate the variance of this random variable we need to find *M*’’(*t*). Here we have *M*’’(0) = *n*(*n* - 1)*p*^{2} +*np*. The variance σ^{2} of our distribution is

σ^{2} = *M*’’(0) – [*M*’(0)]^{2} = *n*(*n* - 1)*p*^{2} +*np* - (*np*)^{2} = *np*(1 - *p*).

Although this method is somewhat involved, it is not as complicated as calculating the mean and variance directly from the probability mass function.