What variance is and why it is squared
The variance is the mean of the squared distances between each observation and the mean. It measures spread, like the standard deviation, but leaves the answer in squared units: a variance of 4 on data measured in millimetres is 4 mm2, which is not a length and cannot be plotted on the same axis as the data.
That awkwardness is the price of a property nothing else has. Variances add. If two quantities are independent, the variance of their sum is the sum of their variances, and the variance of their difference is also the sum of their variances. Standard deviations do not behave that way, because a square root is not linear. Every method that decomposes variation - analysis of variance, regression's R2, portfolio risk, error budgets in metrology - depends on that additivity, which is why variance is the working quantity in theory and the standard deviation is the reporting quantity in practice.
Variance is also what the squaring buys you. Deviations from the mean sum to exactly zero, so their plain average carries no information. Squaring removes the sign, and it weights a deviation of 4 sixteen times as heavily as a deviation of 1. That is a modelling choice: it makes the mean the natural centre, and it makes the variance highly sensitive to extreme values.
The definition, the shortcut, and the degrees of freedom
Start with the definition. Compute the mean, subtract it from every observation, square each difference, and add them. That total is SS, the sum of squares. Divide SS by n - 1 for a sample and by N for a population, and you have the variance.
The computational shortcut gets the same SS from two running totals instead of two passes over the data:
SS = sum(x2) - (sum x)2 / n
Expanding (x - x-bar)2 gives x2 - 2x·x-bar + x-bar2. Summing term by term, the middle term becomes -2 x-bar times the sum of x, which is -2n·x-bar2, and the last becomes n·x-bar2. Together they leave -n·x-bar2, and since x-bar is (sum x)/n, that is exactly -(sum x)2/n. The two forms are the same expression, not an approximation.
The shortcut has one weakness worth knowing. When the values are large and tightly clustered - readings around 1,000,000 that differ in the third decimal - it subtracts two nearly equal enormous numbers, and floating-point arithmetic loses most of the significant digits. This page computes SS from the deviations directly for that reason, and shows the shortcut's intermediate totals so you can follow a textbook that uses it.
The divisor n - 1 is the degrees of freedom. Because SS is measured around the sample mean rather than the unknown population mean, and the sample mean is the value that minimises SS for these particular data, SS is systematically a little too small. Dividing by n - 1 rather than n corrects the bias exactly, on average, which is Bessel's correction. Equivalently, once the mean is known only n - 1 deviations are free to vary, since they must sum to zero.
Worked example: nine service times
Nine measurements: 4, 9, 11, 12, 17, 5, 8, 12, 14 minutes. Treat them as a sample.
- Sum the values. 4 + 9 + 11 + 12 + 17 + 5 + 8 + 12 + 14 = 92.
- Sum the squares. 16 + 81 + 121 + 144 + 289 + 25 + 64 + 144 + 196 = 1080.
- Find the mean. 92 / 9 = 10.222222 minutes.
- Compute the correction term. (sum x)2 / n = 922 / 9 = 8464 / 9 = 940.444444.
- Get SS. 1080 - 940.444444 = 139.555556.
- Divide by the degrees of freedom. n - 1 = 8, so s2 = 139.555556 / 8 = 17.444444 minutes squared.
- Check against the population form. sigma2 = 139.555556 / 9 = 15.506173 minutes squared.
The standard deviation is the square root of the sample variance: sqrt(17.444444) = 4.176654 minutes. That is the figure to quote in a report, because it is in minutes and can be compared with the mean of 10.22 minutes directly - a typical service time sits about four minutes either side of the average.
You can verify SS the long way as a check. The deviations are -6.222, -1.222, 0.778, 1.778, 6.778, -5.222, -2.222, 1.778, 3.778; they sum to zero, and their squares sum to 139.5556, matching step 5.
Reading a variance
A variance is hard to interpret directly, and that is not a failure of understanding on your part - the units are squared. For a sense of spread, take the square root and read the standard deviation instead. Reach for the variance when you need to combine, split or compare sources of variation.
Three situations where the variance is the number you want:
- Adding independent sources of error. If a measurement has an instrument variance of 0.04 mm2 and an operator variance of 0.09 mm2, the total is 0.13 mm2, so the combined standard deviation is sqrt(0.13) = 0.361 mm - not 0.2 + 0.3 = 0.5 mm. Errors combine in quadrature.
- Apportioning variation. Analysis of variance splits a total sum of squares into a part explained by group membership and a residual part. The split is only additive on the SS and variance scale.
- Comparing two spreads formally. The F-test works on the ratio of two variances, so the variance is what you feed it.
An important consequence of squaring: multiplying every observation by a constant c multiplies the variance by c2, while adding a constant to every observation leaves the variance unchanged. Converting a data set from metres to centimetres multiplies the variance by 10,000 and the standard deviation by 100. Shifting a temperature series from Celsius to kelvin changes neither.
Variance and standard deviation for the same data under both bases
| Data | n | Mean | SS | s squared | sigma squared | s |
|---|---|---|---|---|---|---|
| 1, 2, 3, 4, 5 | 5 | 3 | 10 | 2.5 | 2 | 1.581139 |
| 2, 4, 4, 4, 5, 5, 7, 9 | 8 | 5 | 32 | 4.571429 | 4 | 2.138090 |
| 10, 20 | 2 | 15 | 50 | 50 | 25 | 7.071068 |
| 8, 8, 8, 8 | 4 | 8 | 0 | 0 | 0 | 0 |
| 4, 9, 11, 12, 17, 5, 8, 12, 14 | 9 | 10.222222 | 139.555556 | 17.444444 | 15.506173 | 4.176654 |
| -3, -1, 0, 4, 10 | 5 | 2 | 106 | 26.5 | 21.2 | 5.147815 |
Every row was produced by running this calculator's own formulas on the listed data, then rounded to six decimals. The two-value row shows the correction at its most extreme: s squared is exactly twice sigma squared when n = 2.
Assumptions and traps
- The variance is not in the data's units. Never plot it on the same axis as the observations or compare it with a mean. Take the square root first.
- The shortcut formula can lose precision. With large values and small spread, sum(x squared) and (sum x) squared / n are nearly equal and their difference keeps few significant digits. Subtract the mean first, as this page does, or use a compensated algorithm.
- Variances add only when the quantities are independent. If two measurements are correlated, the variance of their sum also includes twice the covariance, and ignoring that term understates or overstates the total depending on the sign of the correlation.
- The n - 1 divisor makes the variance unbiased, not the standard deviation. Taking a square root of an unbiased estimator does not give an unbiased estimator, so s underestimates sigma slightly. The effect is small and almost always ignored.
- A variance computed on grouped or rounded data is biased. If the data have been rounded to a coarse grid, the recorded spread includes the rounding. Sheppard's correction subtracts h squared over 12 for a bin width h.
- One extreme value can dominate. Because deviations are squared, a single observation far from the mean can supply most of SS. Check the sorted data and the interquartile range before you accept a large variance as real.
Related measures and when to use them
The standard deviation is this page's answer with a square root applied, and it is what you report to a reader. Use variance internally, standard deviation externally.
When the data are skewed or contain values you do not trust, spread is better described by position than by squared distance. The interquartile range is the width of the middle half of the data and is unaffected by how extreme the extremes are. A median with an IQR and a mean with a standard deviation are the two coherent pairings; mixing them invites confusion.
If observations carry different weights - unequal sample sizes behind each figure, or measurements of unequal precision - the plain variance is the wrong tool, and you need a weighted calculation; the weighted average calculator shows how the weighting works on the centre. To convert a mean and a variance into probabilities, take the square root and use the normal distribution calculator, or standardise a single value with the z-score calculator.
Finally, the variance of a theoretical distribution is often known in closed form and does not need to be estimated at all. A binomial count over n trials with success probability p has variance np(1 - p) exactly, as the binomial distribution calculator reports. When a model applies, use its formula rather than estimating from a sample.
