MathsStatistics & Probability

Variance
calculator.

Variance measures how far your numbers spread around their mean, in squared units.

How it's worked out

Take each value's distance from the mean, square it, and add the squares. That total is the sum of squares, SS. NIST defines the sample variance as SS over n − 1. When your data are the whole group, you divide by n instead.

s2\displaystyle s^2=∑(x−x‾)2n−1\displaystyle {}= \frac{\sum (x - \bar{x})^2}{n - 1}
σ2\displaystyle \sigma^2=∑(x−μ)2n\displaystyle {}= \frac{\sum (x - \mu)^2}{n}

Here x is each value, x‾\bar{x} or μ\mu is the mean, and n is how many values you have. Squaring makes every distance positive and gives far values extra weight. It also squares the unit, so scores in points give a variance in square points.

Why a sample divides by n − 1

This is Bessel's correction. Distances from a sample's own mean run a little small, because that mean sits right in the middle of those values. On average the n version comes out at n−1n\frac{n - 1}{n} of the true variance, and dividing by n − 1 removes that gap. With just 4 and 8, SS is 8, so σ² is 4 and s² is 8. With 100 values, s² is only 1.01 times σ².

From a frequency table

When you have counts instead of a list, multiply each squared distance by its count. Then n is the total of the counts, and the answer is the same as typing out every repeat.

s2\displaystyle s^2=∑f(x−x‾)2(∑f)−1\displaystyle {}= \frac{\sum f (x - \bar{x})^2}{\left( \sum f \right) - 1}

The shortcut formula

Older textbooks use this version, which saves working out each distance by hand.

SS\displaystyle \text{SS}=∑x2−(∑x)2n\displaystyle {}= \sum x^2 - \frac{\left( \sum x \right)^2}{n}

It is exact on paper. On a computer it subtracts two nearly equal totals and can lose its digits. Take 4, 7, 13 and 16, each with 1,000,000,000 added. The true SS is 90, yet the shortcut returns 0 here. So this tool works from the distances, and uses the shortcut only as a check. Its engine is tested against NIST's certified results for values this close together.

Worked examples

Ten exam scores, as a sample

A teacher takes ten scores from a large year group. They add up to 805, so the mean is 80.5. The squared distances total SS = 806.5. Dividing by 9 gives s² = 89.61 square points, and the square root gives s = 9.47 points.

Two scores carry over half of that. The 65 makes up 29.8% of SS and the 95 makes up 26.1%. Drop the 65 and s² falls to 67.44. The 95% interval for the true variance runs from 42.4 to 298.66, which is wide for ten values.

Open this example in the tool

30 survey ratings in a frequency table

A survey asks 30 people to rate a product from 1 to 5, and the counts are 3, 7, 12, 6 and 2. Weighting by count gives a mean of 2.9 and SS = 32.7. Dividing by 29 gives s² = 1.128, and the square root gives s = 1.062.

The same 30 ratings typed as a list give the same result, because a count is only a short way to write repeats. A rating scale has no real unit, so read this variance as a measure of how much people disagreed.

Open this example in the tool

Five commutes, as a whole population

A five-person team compares one-way commutes of 12, 25, 18, 40 and 15 minutes. These five people are the whole group of interest, so divide by n. The mean is 22 minutes and σ² = 99.6 square minutes, or σ = 9.98 minutes.

The 40-minute trip alone makes up 65.1% of SS. Without it, σ² is 23.25, less than a quarter of the figure with it. A far value counts more than its share because its distance is squared.

Open this example in the tool

Reading your result

Read it with its square root. The variance is in squared units, so the standard deviation brings the spread back to the units of your data. An s² of 89.61 square points means s = 9.47 points, and that is the number to compare with the scores.

Look at which value carries it. A value twice as far from the mean adds four times as much to SS, so one far value can dominate. NIST warns that variance can be greatly affected by the tails of the data. Check the shares and the drop-one list before you trust a large figure.

Use it where it adds up. Spread in squared units has one property the standard deviation lacks: the variance of a sum of uncorrelated quantities is the sum of their variances. Multiplying a quantity by a constant multiplies its variance by that constant squared, and adding a constant changes nothing.

How far a sample pins down the true variance

With data from a normal distribution, a chi-square interval gives a range for σ². Each bound divides SS by a chi-square value with n − 1 degrees of freedom, one from each tail.

lower\displaystyle \text{lower}=(n−1)s2χ1−α/22\displaystyle {}= \frac{(n - 1) s^2}{\chi^2_{1 - \alpha / 2}}
upper\displaystyle \text{upper}=(n−1)s2χα/22\displaystyle {}= \frac{(n - 1) s^2}{\chi^2_{\alpha / 2}}
The 95% interval as a multiple of s²
Sample size nLowerUpper
50.3598.257
100.4733.333
200.5782.133
500.6981.553
1000.7711.349
5000.8871.137

Variances are hard to estimate from small samples. With five values, the true variance could plausibly run from 0.36 times s² to 8.26 times it.

The other figures

  • Standard error of the mean is s divided by the square root of n. It measures how precisely you know the mean, not how spread out the data are.
  • Coefficient of variation is s divided by the size of the mean. It compares spread across different scales, and it only makes sense for data with a meaningful zero, such as weights or prices.
  • [Skewness](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm) is the third moment about the mean divided by σ cubed. A positive value means a longer right tail, and a negative one means a longer left tail.

Common mistakes

  • Using the population formula on a sample. It always comes out smaller, and with five values s² is 1.25 times σ². Most real data sets are samples. Excel keeps the two apart as VAR.S and VAR.P.
  • Comparing the variance with the data. Squared units do not line up with the original ones. Daily returns averaging 0.93% have s² = 2.12, and 0.2, 0.3, 0.4 and 0.5 have s² = 0.0167, far below every value in the list. Compare s with the data instead.
  • Rounding the mean too soon. Squaring a rounded distance carries the error into every row. If you work by hand, keep extra digits until the last step.
  • Trusting the interval on skewed data. The chi-square method is extremely sensitive to departures from normality. Treat the interval as a rough guide unless the data look bell-shaped.

Questions people ask

The sample's own mean is closer to its values than the true mean is, so the squared distances run small. Dividing by n − 1 makes the estimate right on average, though the same fix does not make s an exact estimate of σ. The gap fades as data grow: at 100 values the factor is only 1.01.

Sources