How to Calculate Variance

|
math statistics

Variance measures how far a set of values spreads out from the mean. It is the average of the squared differences between each value and the mean. The two formulas are:

\[\sigma^2 = \frac{\sum (x_i - \mu)^2}{N}\] \[s^2 = \frac{\sum (x_i - \bar{x})^2}{N - 1}\]

The first is population variance, used when you have data for every member of the group. The second is sample variance, used when your data is a subset of a larger population. The only difference between them is the denominator: N vs. N - 1.

Worked example: seven quiz scores

A class of seven students scored the following on a quiz: 12, 15, 18, 22, 14, 20, 11. Here is how to find the variance step by step.

Start by calculating the mean. Add all values and divide by the count.

\[\bar{x} = \frac{12 + 15 + 18 + 22 + 14 + 20 + 11}{7} = \frac{112}{7} = 16\]

If means and other averages are unfamiliar, how to calculate mean, median, and mode walks through each measure.

Next, subtract the mean from every value to get the deviation, then square each deviation.

Value (x) Deviation (x - mean) Squared deviation
12 12 - 16 = -4 16
15 15 - 16 = -1 1
18 18 - 16 = 2 4
22 22 - 16 = 6 36
14 14 - 16 = -2 4
20 20 - 16 = 4 16
11 11 - 16 = -5 25

The deviations sum to zero, which always happens. That is why squaring is necessary. Without it, the negatives cancel the positives and you learn nothing about spread.

Now sum the squared deviations.

\[\sum (x_i - \bar{x})^2 = 16 + 1 + 4 + 36 + 4 + 16 + 25 = 102\]

For population variance, divide by N:

\[\sigma^2 = \frac{102}{7} = \textbf{14.57}\]

For sample variance, divide by N - 1:

\[s^2 = \frac{102}{6} = \textbf{17.00}\]

The variance calculator handles this arithmetic instantly for data sets of any size.

Why we square the deviations

Squaring serves two purposes. First, it removes negative signs so that deviations below the mean do not cancel out deviations above it. Second, squaring gives extra weight to values that are far from the mean. A deviation of 6 becomes 36 when squared, while a deviation of 1 becomes just 1. This means a single outlier has a large effect on variance, which is a feature rather than a flaw: variance is specifically designed to be sensitive to spread.

An alternative approach would be to take the absolute value of each deviation instead of squaring. That calculation exists and is called the mean absolute deviation. Variance is preferred in most of statistics because squared values have useful mathematical properties, particularly when combining variances from independent sources or working with the normal distribution.

Bessel’s correction: why N - 1 for samples

When you work with a sample rather than a full population, the sample mean is itself an estimate. Values in a sample tend to cluster closer to their own mean than to the true population mean. Dividing by N would systematically underestimate the population variance.

Bessel’s correction fixes this by dividing by N - 1 instead of N. The smaller denominator produces a slightly larger variance, which on average matches the true population variance more accurately.

The correction matters most when N is small. With 5 values, the difference between dividing by 5 and dividing by 4 is 20%. With 500 values, the difference between dividing by 500 and dividing by 499 is 0.2%. For large data sets, the two formulas converge. For small samples, always use N - 1.

To see the effect concretely, look at the worked example above. The population variance was 14.57, while the sample variance was 17.00. That gap of 2.43 reflects the correction. If this data set represents a sample of seven students from a much larger class, 17.00 is the better estimate of how the full class’s scores spread out.

Population vs. sample: when to use each

The distinction depends on whether your data covers the entire group you care about.

Scenario Type Divide by
Test scores for every student in a class Population N
Heights of 50 people sampled from a city Sample N - 1
Revenue for all 12 months of a fiscal year Population N
Customer ratings from 300 out of 10,000 users Sample N - 1

If you measured every member of the group, you have a population. If you measured some members and want to generalize to the whole group, you have a sample. When in doubt, default to sample variance. It is the safer choice because it avoids underestimating, and with large data sets it produces nearly the same result as population variance anyway.

Variance vs. standard deviation

Variance and standard deviation measure the same thing. Standard deviation is simply the square root of variance.

\[\sigma = \sqrt{\sigma^2} \qquad s = \sqrt{s^2}\]

From the worked example, the population standard deviation is the square root of 14.57, which is approximately 3.82. The sample standard deviation is the square root of 17.00, which is approximately 4.12. The standard deviation post covers the full calculation and the 68-95-99.7 rule.

The reason standard deviation gets reported more often is units. If the data is measured in points, variance is in “squared points,” which is not a meaningful unit. Taking the square root brings the measurement back to points, making it directly comparable to the original values. Variance is more convenient in formulas and proofs, while standard deviation is more convenient for interpretation.

Common mistakes

Forgetting to square the deviations before summing is the most frequent error. If your sum of deviations comes out to zero and the data values are not all identical, you skipped the squaring step.

Another common mistake is confusing variance with standard deviation. If a problem asks for variance and you take the square root at the end, you have computed standard deviation instead. Read the question carefully.

Finally, applying the wrong denominator is easy to overlook. If the problem specifies a sample or describes data collected from a subset, use N - 1. If it says population or includes all members, use N. The variance calculator returns both values side by side, so you can always compare.