Math glossary

Variance in Statistics: Population and Sample Formulas

Calculate variance for populations, samples, and frequency tables. Learn why sample variance uses n − 1 and check six worked examples.

TL;DR

Variance measures spread by squaring the distances from the mean. Divide their sum by the population size for a complete population, or by one less than the sample size for the usual sample estimate.

Key Points

  • Population variance divides the squared deviations by the population size, while sample variance uses one fewer than the number of observations.
  • A variance of zero means every observed value is identical, and a larger variance can reveal differences hidden by a shared mean.
  • Standard deviation is the square root of variance and expresses spread in the original units rather than in squared units.
  • An equal shift leaves variance unchanged, while multiplying every value by a factor multiplies the variance by that factor squared.

What is variance in statistics?

Variance describes how far values spread around their arithmetic mean. Subtract the mean from each value, square those differences, then combine them using the denominator appropriate to the question. The arithmetic mean locates the centre, while variance measures how far values sit from it.

Simple deviations cancel. For values 9, 10 and 11, the differences from 10 are −1-1, 00 and 11. Squaring keeps each distance in the calculation and makes a value far from the centre count more.

Variance diagram comparing two groups with mean 10 and different distances from the mean
Both groups have the same mean. Squared deviations give Group B the larger variance.

Which variance formula do you use?

Use population variance when the observations represent the entire group you want to describe. Use the usual sample variance when you use a sample to estimate the variance of a wider population. Decide which group the question is about before counting the values.

Purpose Formula Symbols
Describe the whole population σ2=∑i=1N(xi−μ)2N\sigma^2=\frac{\sum_{i=1}^{N}(x_i-\mu)^2}{N} NN is the population count, μ\mu its mean, and xix_i value number ii.
Estimate population variance from a sample s2=∑i=1n(xi−x¯)2n−1s^2=\frac{\sum_{i=1}^{n}(x_i-\bar x)^2}{n-1} nn is the sample count, x¯\bar x its mean, and xix_i sample value number ii.

The symbol ∑\sum means to add the terms for all listed observations. The top of each fraction is the sum of squared deviations. NIST’s measures-of-scale reference explains why this gives nonnegative spread and how the square root returns to the original measurement units.

If all values are equal, every squared deviation is zero. A population of a single observation therefore has variance zero. The sample variance formula needs at least two observations.

Why divide sample variance by one less?

The sample mean comes from the same observations, so their differences from that mean add to zero. Once you know n−1n-1 of those differences, the last is fixed. Maricopa’s statistics text calls the remaining freedom to vary the degrees of freedom.

The correction does more than count free deviations. Across repeated independent samples from a population with finite variance, dividing by nn after fitting the sample mean tends to underestimate that variance. The University of Texas at Austin’s derivation can be written as the difference between two sums.

∑i=1n(xi−x¯)2=∑i=1n(xi−μ)2−n(x¯−μ)2\sum_{i=1}^{n}(x_i-\bar x)^2 = \sum_{i=1}^{n}(x_i-\mu)^2 - n(\bar x-\mu)^2

The average of the first term on the right across repeated independent samples is nσ2n\sigma^2. The average of the second is σ2\sigma^2, since the sample mean has variance σ2n\frac{\sigma^2}{n}. That leaves (n−1)σ2(n-1)\sigma^2, so dividing by n−1n-1 gives an unbiased estimator under those conditions.

How do you calculate variance with frequencies or grouped intervals?

For a frequency table, multiply each squared deviation by the count of that value. This does the same calculation as expanding the table into individual observations.

Let fif_i be the frequency of value xix_i. The total count is ∑ifi\sum_i f_i. For a population, calculate the weighted mean μ\mu first, then use the population sum of squares.

μ=∑ifixi∑ifi\mu=\frac{\sum_i f_i x_i}{\sum_i f_i}
σ2=∑ifi(xi−μ)2∑ifi\sigma^2=\frac{\sum_i f_i(x_i-\mu)^2}{\sum_i f_i}

For a sample, use the weighted sample mean in the numerator and divide the result by ∑ifi−1\sum_i f_i-1. When the table gives intervals, use class midpoints for an estimate of variance. The midpoint stands in for every reading in the bin, so the result depends on how the observations are actually distributed within each class. OpenStax explains that loss of detail in its treatment of grouped frequency tables.

What is the difference between variance and standard deviation?

Variance uses squared units. Standard deviation is σ2\sqrt{\sigma^2} for a population or s2\sqrt{s^2} for a sample. If arrival times are in minutes, the variance uses minutes squared and the standard deviation uses minutes.

Because distances are squared, both measures respond strongly to an extreme value. For a dataset with a long tail or potential outliers, also look at the median and range and consider the interquartile range. OpenStax’s measurements of variation separate these ideas because they describe different parts of the distribution.

What happens if you change the scale or add a constant?

Adding bb to each observation shifts the mean by the same amount. The deviations stay unchanged. Multiplying each observation by aa multiplies its deviation by aa and its squared deviation by a2a^2.

Var(aX+b)=a2Var(X)\operatorname{Var}(aX+b)=a^2\operatorname{Var}(X)

Here XX is the original variable and Var\operatorname{Var} denotes its variance. To compare relative spread across measurements with positive, meaningful means, the coefficient of variation uses standard deviation divided by the mean. A mean near zero can make that ratio unstable.

How is variance used for probability distributions?

For a random variable XX with mean μ\mu and finite variance, take the expected value of its squared distance from that mean. Expanding the square also gives a useful computational identity.

Var(X)=E[(X−μ)2]=E[X2]−μ2\operatorname{Var}(X)=E[(X-\mu)^2]=E[X^2]-\mu^2

Here EE denotes the expectation, or probability-weighted average, and μ=E[X]\mu=E[X]. The NIST handbook’s distribution gallery gives the mean and spread for several common cases.

Distribution What its parameters mean Variance
Binomial nn trials with independent outcomes and success probability pp per trial np(1−p)np(1-p)
Poisson λ\lambda is the expected count over the interval λ\lambda
Continuous uniform aa and bb are the lower and upper limits, with a<ba<b (b−a)212\frac{(b-a)^2}{12}

Covariance describes how two variables vary together. Expanding the squared deviation for a sum gives

Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y).\operatorname{Var}(X+Y)=\operatorname{Var}(X)+\operatorname{Var}(Y)+2\operatorname{Cov}(X,Y).

Here Cov(X,Y)\operatorname{Cov}(X,Y) is the covariance of XX and YY. If the variables are independent and both variances are finite, the covariance is zero and their variances add. If the variables move together, leaving out the covariance can change the result.

Examples of Variance

Work through a complete population, a sample, exact frequency counts, grouped estimates, and a change of reporting units.

Example 1

Find the population variance of 2, 4, 6 and 8.

  1. The mean is 2+4+6+84=5\frac{2+4+6+8}{4}=5.
  2. The deviations are −3-3, −1-1, 11 and 33. Their squares add to 9+1+1+9=209+1+1+9=20.
  3. Divide by four to get σ2=5\sigma^2=5.

Example 2

Find the sample variance of 10, 12 and 14.

  1. The mean is 12 and the squared deviations sum to 4+0+4=84+0+4=8.
  2. Dividing by three gives 83\frac83, the variance when you describe these three readings as the entire population.
  3. This question uses the readings to estimate variance from a sample. Divide by 3−13-1 to get s2=4s^2=4. The sample standard deviation is 2.

Example 3

Groups A and B contain 9, 10, 11 and 6, 10, 14 respectively. Which complete group has more spread?

  1. Both means are 10. Group A gives squared deviations 11, 00 and 11.
  2. Group B gives 1616, 00 and 1616.
  3. Dividing each sum by three gives variances 23\frac23 and 323\frac{32}{3}. Group B has sixteen times the variance even though both centres match.

Example 4

A population has one zero, two ones and one two. Find the variance from the counts.

  1. The mean is 1×0+2×1+1×24=1\frac{1\times0+2\times1+1\times2}{4}=1.
  2. The frequency-weighted squared deviations total 1×1+2×0+1×1=21\times1+2\times0+1\times1=2.
  3. Divide by four to get population variance 0.50.5.

Example 5

Estimate the sample variance for intervals 0 to under 10, 10 to under 20 and 20 to under 30, with counts 1, 2 and 1.

  1. The midpoints are 5, 15 and 25. Their frequency-weighted mean is 15.
  2. The squared deviations weighted by their counts total 100+0+100=200100+0+100=200.
  3. With four sampled observations, the estimated sample variance is 2003≈66.67\frac{200}{3}\approx66.67.

Example 6

A collection of lengths has sample variance 0.04m20.04\,\mathrm{m}^2. What are its variance and standard deviation in centimetre units?

  1. Multiply every length by 100 to convert to centimetres.
  2. Multiply the variance by 1002100^2 to get 400cm2400\,\mathrm{cm}^2.
  3. The standard deviation is 400=20cm\sqrt{400}=20\,\mathrm{cm}, which also equals 0.20m0.20\,\mathrm{m}.

Where do variance calculations lose their meaning?

Check the target population, the measurement unit, and whether the input gives individual values or groups before choosing the equation.

Mistake 1. Choosing the denominator by the size of the dataset

Where it slips in

A large survey can feel like a population because it contains many responses.

The tempting calculation

Dividing by the number of survey responses describes their realized spread. It does not use the standard sample estimator if the question asks about the wider population.

The correction

Name the group you want to describe. Use NN for a complete grouping and n−1n-1 for the usual sample estimate from a subset.

Mistake 2. Comparing raw variances across measurement scales

Where it slips in

You see two variances on the same page and rank the numbers before checking their units.

The tempting calculation

A variance of 400cm2400\,\mathrm{cm}^2 appears far larger than 0.04m20.04\,\mathrm{m}^2.

The correction

Convert the scales before comparing. The two values describe the same spread.

Practice with answers

  1. Treat 3, 5 and 7 as the population. Calculate the variance and standard deviation.
  2. A measurement sample has variance 9. Add 12 to every observation, then double every resulting observation. What is the new variance?
  3. A sample contains two observations, 4 and 10. Find the sample variance.

Check your solutions

  1. The mean is 5, so the squared deviations add to 8. The variance is 83\frac83 and the standard deviation is 83≈1.63\sqrt{\frac83}\approx1.63.
  2. Adding 12 leaves the variance at 9. Doubling multiplies it by four, so the new variance is 36.
  3. The sample mean is 7 and the squared deviations add to 18. Divide by 2−12-1 to get 18.

Frequently Asked Questions

Can variance be negative?

A variance built from squared deviations and a positive denominator is nonnegative. A tiny negative result from the shortcut with large floating-point values can mean the two large terms lost precision when subtracted.

Does sample variance require a normal distribution?

The formula can be used without a normal distribution. Its unbiasedness for the population variance holds for independent draws from the same distribution with finite variance. Specific tests or confidence intervals may add distribution assumptions.

What is the easiest way to check a variance calculation?

Check that the deviations from the mean add to zero, then verify the squared deviations and the denominator. For repeated values, a frequency table reduces the amount of arithmetic without changing the result.

What to Remember About Variance

  • Match the denominator to a complete population or a sample estimate.
  • Square deviations so spread cannot cancel, then take the square root if you need the original units.
  • Multiply variance by the square of a scale factor when converting measurements.
  • Treat variance from grouped interval midpoints as an estimate.

Read More

Research Behind This Article

  1. OpenStax, Introductory Statistics, Measures of the Spread of the Data. OpenStax.
  2. National Institute of Standards and Technology, Measures of Scale. NIST Engineering Statistics Handbook.
  3. Maricopa Open Digital Press, Why Are the Variance Formulas Different? Introductory Statistics.
  4. University of Texas at Austin, Population and Sample Variance: A Derivation. UT Austin statistics notes.
  5. OpenStax, Principles of Data Science, Measures of Variation. OpenStax.
  6. National Institute of Standards and Technology, Gallery of Distributions. NIST Engineering Statistics Handbook.