Article

Variance: How to Calculate Variance, Formula and Examples

Variance measures how far the numbers in a data set spread out from their mean. It is calculated as the average of the squared deviations from the mean. This article gives the formula, the calculation step by step, the difference between population variance and sample variance, the link to standard deviation, some properties and four worked examples. You can check your own numbers in the variance calculator. For the numbers 2, 4, 4, 4, 5, 5, 7, 9 the population variance is 4.

Last updated:

Find the variance in the variance calculator. Find the standard deviation of the same numbers in the standard deviation calculator.

The variance formula

Variance is the average of the squared deviations from the arithmetic mean. Squaring keeps deviations below and above the mean from cancelling out, and it gives large deviations more weight.

σ² = Σ(xᵢ − x̄)² ÷ n (population)
s² = Σ(xᵢ − x̄)² ÷ (n − 1) (sample)
example 2, 4, 4, 4, 5, 5, 7, 9: x̄ = 5, Σ = 32, σ² = 4

DataMeanSum of squaresPopulation varianceSample variance
1, 2, 3, 4, 531022.5
2, 4, 4, 4, 5, 5, 7, 953244.57
3, 5, 8, 10, 1487414.818.5
0, 105502550
2, 2, 22000

Variance has the unit of the data squared. For data in feet it is in square feet, so spread is easier to describe with the standard deviation.

Eight numbers on a line with the mean markedA number line from 1 to 10 with eight dots at 2, 4, 4, 4, 5, 5, 7, 9. A dashed line shows the mean 5. The population variance of these numbers is 4.12345678910x̄ = 5σ² = 32 ÷ 8 = 4
The mean of 2, 4, 4, 4, 5, 5, 7, 9 is 5. The distances from the mean are −3, −1, −1, −1, 0, 0, 2, 4, and their squares add up to 32, which gives a variance of 4.

Try it with an example

Example: the numbers 2, 4, 4, 4, 5, 5, 7, 9. The whole list is already stored in the link to the calculator.

Numbers
2, 4, 4, 4, 5, 5, 7, 9
Result
population variance 4, sample variance 4.571429

Open the calculator with these numbers

The calculator reads the values from the page address and shows the result right away. You can change them freely.

How the calculator works

The calculator separates the numbers by commas, spaces or semicolons and needs at least two. It finds the mean, the sum of squared deviations and the population variance, which is the sum of squared deviations divided by n. It also shows the population standard deviation and, for comparison, the sample variance with the divisor n − 1. The main result is always the population variance. The calculator skips entries that are not numbers and says so.

How to calculate variance step by step

For the numbers 2, 4, 4, 4, 5, 5, 7, 9 the mean is 5. The deviations from the mean are −3, −1, −1, −1, 0, 0, 2, 4, and their squares are 9, 1, 1, 1, 0, 0, 4, 16. The sum of the squares is 32. Dividing by n = 8 gives a population variance of 4.

Work out the mean in the mean calculator and a typical value that resists extreme numbers in the median calculator. The mean is described in Arithmetic Mean, and the median is explained in Median.

Population variance versus sample variance

You use population variance when you have data for every member of the set. You use sample variance when the data is only a sample of a larger population, and the formula then divides by n − 1. This correction makes up for the fact that the sample mean lies closer to the data than the true mean does. For 2, 4, 4, 4, 5, 5, 7, 9 the population variance is 4 and the sample variance 4.5714.

The calculator on the page divides by n and gives the population variance as the main result. It shows the sample variance in a separate row, so you do not have to work it out by hand. For large sets the difference between the two is small, and for very small samples it is clear. For the two numbers 0 and 10 the population variance is 25 and the sample variance 50, twice as much.

Variance and standard deviation

The standard deviation is the square root of the variance, so it has the same unit as the data. For a variance of 4 the population standard deviation is 2. For the numbers 3, 5, 8, 10, 14 the population variance is 14.8 and the standard deviation 3.8471. The standard deviation is in the standard deviation calculator and the three-number deviation calculator, and a square root in the square root calculator. It is covered in more detail in Standard Deviation.

Shifting all the numbers by a constant does not change the variance: for 12, 14, 14, 14, 15, 15, 17, 19 it is still 4. Multiplying all the numbers by k multiplies the variance by k², so for numbers twice as large the variance grows to 16. When all the numbers are equal, the variance is zero, and a simple measure of spread is also given by the range calculator.

Four worked examples

You can repeat each example in the variance calculator.

1. Variance of 2, 4, 4, 4, 5, 5, 7, 9

A classic data set.

  1. Find the mean: 40 ÷ 8 = 5.
  2. Find the squared deviations: 9, 1, 1, 1, 0, 0, 4, 16.
  3. Add them: 32.
  4. Divide by 8: the population variance is 4 and the sample variance 4.5714.

2. Variance of 1, 2, 3, 4, 5

Five consecutive numbers.

  1. The mean is 3.
  2. The squared deviations are 4, 1, 0, 1, 4.
  3. The sum of squares is 10.
  4. The population variance is 2 and the sample variance 2.5.

3. Variance of 0 and 10

Two numbers.

  1. The mean is 5.
  2. The squared deviations are 25 and 25.
  3. The sum of squares is 50.
  4. The population variance is 25 and the sample variance 50.

4. Variance of 3, 5, 8, 10, 14

A non-integer result.

  1. The mean is 8.
  2. The squared deviations are 25, 9, 0, 4, 36, and the sum is 74.
  3. Divide by 5: the population variance is 14.8.
  4. The standard deviation is 3.8471.

Common mistakes when calculating variance

  • Skipping the squaring of deviations — the plain deviations from the mean add up to zero, so they have to be squared.
  • Mixing up the divisor n and n − 1 — for a population you divide by n, and for a sample by n − 1.
  • Confusing variance with standard deviation — the standard deviation is the square root of the variance.
  • Taking deviations from the wrong mean — deviations are measured from the mean of the same data.
  • Giving variance in the unit of the data — variance has the unit of the data squared.
  • Rounding the mean before computing the deviations — round only the final result.
  • Entering decimals in a list separated only by commas — if the numbers have a decimal comma, separate them with spaces or semicolons, for example 3,5; 4,25; 6.

Frequently asked questions

How do you calculate variance?

Find the mean, square the deviations from the mean, add them and divide by the number of values. For 2, 4, 4, 4, 5, 5, 7, 9 the population variance is 4.

What is the variance formula?

Population variance is σ² = Σ(xᵢ − x̄)² ÷ n, and sample variance is s² = Σ(xᵢ − x̄)² ÷ (n − 1).

What is the difference between population variance and sample variance?

Population variance divides by n and sample variance by n − 1. For 2, 4, 4, 4, 5, 5, 7, 9 it is 4 against 4.5714.

What is the variance of 1, 2, 3, 4, 5?

The mean is 3 and the sum of squared deviations is 10, so the population variance is 2 and the sample variance 2.5.

What is the difference between variance and standard deviation?

The standard deviation is the square root of the variance. For a variance of 4 the standard deviation is 2.

Can variance be negative?

No. Variance is an average of squares, so it is never negative. It is zero only when all the numbers are equal.

What is the unit of variance?

The unit of the data squared. For data in feet, variance is in square feet.

Does the variance calculator divide by n or by n − 1?

The main result is the population variance, which divides by n. The calculator shows the sample variance with the divisor n − 1 separately for comparison.

Find the variance of your own data

Enter the numbers in the variance calculator and read the population variance, the sample variance, the mean and the standard deviation.

The spread of data is also described by the standard deviation calculator and the range calculator.