Why We Divide by n − 1

The Problem

Suppose we observe nn i.i.d. samples y1,y2,,yny_1,y_2,\ldots,y_n from a random variable YY with unknown mean μ\mu and variance σ2\sigma^2. We want to estimate

σ2=E[(Yμ)2].\sigma^2 = \mathbb{E}[(Y-\mu)^2].

If we knew the true mean μ\mu, the obvious estimator would be

1ni=1n(yiμ)2.\frac{1}{n}\sum_{i=1}^{n}(y_i-\mu)^2.

It varies from one dataset to another, but it is correct on average:

E ⁣[1ni=1n(yiμ)2]=σ2.\mathbb E\!\left[\frac{1}{n}\sum_{i=1}^{n}(y_i-\mu)^2\right] =\sigma^2.

The problem is that μ\mu is unknown. The natural replacement is the sample mean

m^=1ni=1nyi.\hat m=\frac1n\sum_{i=1}^n y_i.

Plugging m^\hat m into the same formula gives the estimator we want to understand:

1ni=1n(yim^)2.\frac1n\sum_{i=1}^n(y_i-\hat m)^2.

This looks like the known-mean estimator with one reasonable substitution. Yet it underestimates σ2\sigma^2 on average. The standard correction replaces nn in the denominator with n1n-1.

Why does estimating the mean cost exactly one? We did not remove an observation. We used all nn of them. The missing piece is that m^\hat m was chosen from those same observations, and it was chosen to make their squared deviations as small as possible.

Variance as an Optimization Problem

To see that choice explicitly, let mm be any candidate center and define

V(m)=1ni=1n(yim)2.V(m)=\frac1n\sum_{i=1}^n(y_i-m)^2.

Here mm is a free variable. For every value of mm, the function V(m)V(m) returns the average squared distance of the observations from that center. Evaluating it at the true mean gives the known-mean estimator, V(μ)V(\mu). Evaluating it at the sample mean gives the plug-in estimator introduced above:

V(m^)=1ni=1n(yim^)2.V(\hat m)=\frac1n\sum_{i=1}^n(y_i-\hat m)^2.

The useful question is therefore not merely whether m^\hat m estimates μ\mu well. It is: how was m^\hat m selected, and what does that selection do to VV?

Indeed, m^\hat m is exactly the value of mm that minimizes V(m)V(m). Differentiate VV with respect to mm:

dVdm=1ni=1n2(yim),dVdm=0m=1ni=1nyi=m^.\begin{aligned} \frac{dV}{dm} &= \frac{1}{n}\sum_{i=1}^{n} -2(y_i - m),\\ \frac{dV}{dm}=0 &\Longleftrightarrow m = \frac{1}{n}\sum_{i=1}^{n} y_i = \hat m. \end{aligned}

Since VV is a quadratic with second derivative 2>02>0, this critical point is the unique minimum.

Key Insight

m^\hat m is not just an estimate of μ\mu. It is the point that makes the squared deviations as small as possible on this dataset. Therefore

V(m^)V(m)for all m,V(m^)V(μ).V(\hat{m}) \leq V(m) \quad \text{for all } m, \qquad V(\hat{m}) \leq V(\mu).

Try it yourself. Drag mm across the axis and watch V(m)V(m) change. Notice it always bottoms out at m^\hat{m}.

mV(m)mμ
V(m) = 3.45
minimum
V(μ) = 5.40
true mean
V(m) = 5.40
m = 5.0
realized gap = 1.95 = (m − μ)² (shaded region)
Drag m along the axis. V(m) is always minimized at the sample mean m, so V(m) ≤ V(μ).

That is the sample-by-sample comparison we need. The true mean μ\mu usually does not land exactly at the dataset’s minimizer m^\hat m, so replacing μ\mu with m^\hat m can only move us downward on the curve.

Bias is still a statement about expectations, not about one dataset. Since V(m^)V(μ)V(\hat m)\le V(\mu) for every dataset and V(μ)V(\mu) is unbiased for σ2\sigma^2, we have E[V(m^)]σ2\mathbb E[V(\hat m)]\le \sigma^2, with strict inequality whenever σ2>0\sigma^2>0. The next section computes the exact gap.

Computing the Bias

So far we know the sign of the bias: the expectation of V(m^)V(\hat{m}) is too small.

Now we compute exactly how small. The trick is to compare V(μ)V(\mu) and V(m^)V(\hat{m}) directly. Expand (yiμ)2(y_i-\mu)^2 around m^\hat{m}, then average over ii. The cross-term vanishes because i(yim^)=0\sum_i(y_i-\hat m)=0.

The important thing is not that this expansion is clever. The important thing is that it expands around the value chosen by the optimization problem. That is why one term disappears instead of becoming another nuisance term to carry around.

(yiμ)2=(yim^)2+2(yim^)(m^μ)+(m^μ)2(algebraic identity)V(μ)=V(m^)+2(m^μ)ni(yim^)=0+(m^μ)2(average over i)V(μ)V(m^)=(m^μ)2(rearrange)E[V(μ)V(m^)]=E[(m^μ)2]=Var(m^).(expectation)\begin{aligned} (y_i - \mu)^2 &= (y_i - \hat{m})^2 + 2(y_i - \hat{m})(\hat{m} - \mu) + (\hat{m} - \mu)^2 && \text{(algebraic identity)} \\ V(\mu) &= V(\hat{m}) + \underbrace{\tfrac{2(\hat{m}-\mu)}{n}\sum_i(y_i - \hat{m})}_{=\,0} + (\hat{m} - \mu)^2 && \text{(average over }i\text{)} \\ V(\mu) - V(\hat{m}) &= (\hat{m} - \mu)^2 && \text{(rearrange)} \\ \mathbb{E}[V(\mu) - V(\hat{m})] &= \mathbb{E}[(\hat{m} - \mu)^2] = \text{Var}(\hat{m}). && \text{(expectation)} \end{aligned}

Two things stand out. First, the identity in line 1 is exact, not a Taylor approximation, so the gap in line 3 is precisely the squared error of m^\hat{m} as an estimator of μ\mu. Second, the last step uses E[m^]=μ\mathbb{E}[\hat{m}] = \mu (the sample mean is unbiased): under that condition, E[(m^μ)2]\mathbb{E}[(\hat{m} - \mu)^2] is exactly the variance of the estimator m^\hat{m}.

All that’s left is to plug in a specific value for Var(m^)\text{Var}(\hat{m}). Since m^\hat{m} is an average of nn independent draws each with variance σ2\sigma^2, we get Var(m^)=σ2/n\text{Var}(\hat{m}) = \sigma^2/n. Substituting into the last line of the previous derivation and rearranging isolates the expected value of our estimator.

E[V(μ)V(m^)]=σ2n(plug in Var(m^)=σ2/n)E[V(m^)]=σ2σ2n=n1nσ2.(rearrange, E[V(μ)]=σ2)\begin{aligned} \mathbb{E}[V(\mu) - V(\hat{m})] &= \frac{\sigma^2}{n} && \text{(plug in } \text{Var}(\hat{m}) = \sigma^2/n\text{)} \\ \mathbb{E}[V(\hat{m})] &= \sigma^2 - \frac{\sigma^2}{n} = \frac{n-1}{n}\,\sigma^2. && \text{(rearrange, } \mathbb{E}[V(\mu)] = \sigma^2\text{)} \end{aligned}

The nn in the denominator of σ2/n\sigma^2/n comes from averaging nn independent samples. The more data we have, the less m^\hat{m} wobbles, and the less we underestimate.

The expectation of V(m^)V(\hat{m}) is too small by a factor of n1n\frac{n-1}{n}. Rescaling by the reciprocal cancels the 1n\frac{1}{n} inside V(m^)V(\hat{m}) and gives the familiar unbiased estimator s2=1n1i(yim^)2s^2 = \frac{1}{n-1}\sum_i (y_i - \hat{m})^2.

See the bias in action. Draw repeated samples and watch the two estimators converge.

1. Population we sample from: N(0, σ² = 4)-4-20242. From those n points, compute Vn and Vn−13. Where the two estimates land across 0 trialsσ² = 4Estimated variance0246810121416
Vn: avg = 0.00
Vn−1: avg = 0.00
Trials: 0
Each trial draws a fresh sample of n points from the population (top), then computes Vn and Vn−1 from those points; the histogram (bottom) shows where each estimator's value lands. The final bin collects estimates at or above 16. Increase trials to sharpen the histograms; increase n to shrink the gap between them.

One Parameter, One Sample Lost

Notice something striking about the bias σ2/n\sigma^2/n. Our estimator V(μ)V(\mu) is an average of nn terms, each with expectation σ2\sigma^2:

V(μ)=1ni=1n(yiμ)2,E[(yiμ)2]=σ2.V(\mu) = \frac{1}{n}\sum_{i=1}^{n}(y_i - \mu)^2, \qquad \mathbb{E}[(y_i - \mu)^2] = \sigma^2.

So V(μ)V(\mu) itself has expectation σ2\sigma^2, but V(m^)V(\hat{m}) falls short by σ2/n\sigma^2/n. That gap is exactly one term’s worth of variance, averaged out.

Why exactly one, and not some data-dependent fraction? Our derivation gave the right number for this particular case (k=1k = 1, the sample mean), but it leaned on a clean algebraic identity, V(μ)=V(m^)+(m^μ)2V(\mu) = V(\hat{m}) + (\hat{m} - \mu)^2, that doesn’t obviously extend to fitting more parameters. If we tried the same calculation for simple linear regression, the analogous identity wouldn’t be so clean: the Hessian of the regression loss has data-dependent entries.

So we don’t yet have a general reason for the "11" to come out as an integer. The parameter-counting hint above (“the 11 counts the parameter we fit”) is suggestive, but we have not justified it. In the next post we use the projection view of ordinary least squares (OLS), with the hat matrix making that projection explicit. For a correctly specified, full-rank linear least-squares model, the cost of fitting kk coefficients is the dimension of the subspace onto which OLS projects. That dimension is kk, and it explains the "11" in n1n - 1 as the intercept-only special case.

The Takeaway

To collect the whole post in two formulas: the naive estimator, VV evaluated at the fitted center m^\hat{m}, is biased low,

E[V(m^)]=n1nσ2,\mathbb{E}[V(\hat{m})] = \frac{n-1}{n}\,\sigma^2,

so one should instead use the rescaled, unbiased sample variance

s2=nn1V(m^)=1n1i=1n(yim^)2,E[s2]=σ2.s^2 = \frac{n}{n-1}\,V(\hat{m}) = \frac{1}{n-1}\sum_{i=1}^{n}(y_i - \hat{m})^2, \qquad \mathbb{E}[s^2] = \sigma^2.

This corrected estimator requires n2n \geq 2. With only one observation, the residual sum of squares is zero and there is no remaining information with which to estimate the population variance.

References

The result itself is fairly well known and appears, usually without attribution, in most statistics textbooks. Two good places to find it:

  • Casella, G. & Berger, R. L. (2002). Statistical Inference (2nd ed.). Duxbury. The unbiasedness of s2s^2 is Theorem 5.2.6; unbiasedness as an evaluation criterion is developed in Chapter 7.
  • Wasserman, L. (2004). All of Statistics. Springer. Point estimation is covered in Chapter 6.