Statistics
How To Calculate Variance
Variance measures the average squared deviation from the mean, giving a single number that describes how widely a set of values is scattered. Whether you divide by N or by N minus one decides whether you are describing the data you have or estimating the spread of a larger population.
Last updated
Quick Answer
Population: sigma^2 = Sum(xi - mu)^2 / N | Sample: s^2 = Sum(xi - x-bar)^2 / (n - 1)
- xi
- Each individual observation in the data set
- mu or x-bar
- The mean (average) of the observations
- N or n
- The number of observations
- sigma^2 or s^2
- The variance: population or sample version
Find the mean, subtract it from each value, square those deviations, add them up, then divide. For the values 2, 4, 6, 8 and 10 the mean is 6.0 and the squared deviations total 40, giving a population variance of 8.0 when divided by five and a sample variance of 10.0 when divided by four. The square root of the variance returns the result to the original units: the population standard deviation here is 2.8284271247461903.
What Is Variance?
Variance is a single number that describes how spread out a set of values is around their average. Two groups of numbers can share exactly the same mean yet behave completely differently — one tightly clustered, the other widely scattered — and the mean alone cannot tell them apart. Variance fills that gap by measuring the average squared distance from the centre. Because it squares each distance before averaging, values far from the mean count much more heavily than values that sit close to it, which is precisely what makes it useful for detecting variability. In short, a small variance means most values hover near the average, while a large one means they are scattered far and wide.
The construction starts by finding the mean, then subtracting it from every observation to obtain signed deviations. Those deviations always sum to zero, because the mean is the balance point of the data, so averaging them directly would tell you nothing at all. Squaring removes the signs and makes every contribution positive, so a value two units below the mean and one two units above it contribute identically. The total is then divided by a count, turning a sum of squared distances into a typical squared distance per observation.
That averaging step is where population and sample variance part company. If your numbers are the entire group you care about — every student in a class, every item in a production batch — you divide by N, the number of observations. If they are a sample drawn from something larger, you divide by N minus one. That small change is Bessel's correction, named after the astronomer who studied the measurement errors that motivated it, and it exists to compensate for a subtle statistical bias. Without it, a sample would consistently appear tidier than the population it was drawn from.
The bias runs like this. A sample mean is calculated from the very same observations you are trying to describe, so it sits a little closer to them than the true population mean would. Squared deviations measured around that fitted centre therefore come out systematically too small. Dividing by N minus one instead of N inflates the answer just enough, on average, to remove that underestimate. For the five numbers used on this page the correction turns a population variance of 8.0 into a sample variance of 10.0 — fully a quarter larger, which is far too big to dismiss as rounding.
The five worked values make the mechanics concrete. They are 2, 4, 6, 8 and 10, with a mean of 6.0. Their deviations from that mean are minus 4, minus 2, zero, 2 and 4, which do indeed sum to zero as promised. Squaring them gives 16, 4, 0, 4 and 16, for a total sum of squared deviations of 40. Divide that 40 by five for the population variance of 8.0, or by four for the sample variance of 10.0. Every later quantity follows from those three numbers: the mean, the sum of squares and the chosen divisor.
Variance is measured in squared units, and that is its main practical weakness. If the original data are minutes, the variance is expressed in minutes squared — a quantity nobody can picture or compare to a stopwatch. Taking the square root returns everything to the original scale and produces the standard deviation. For the population here that is the square root of 8.0, namely 2.8284271247461903, while the corresponding sample figure is the square root of 10.0, about 3.1622776601683795. Both can be read directly as typical distances from the mean of 6.0.
Because it stays in squared units, variance is mostly a working quantity rather than a headline one. Its great virtue is algebraic: the variances of independent quantities add together, which is why the analysis of variance and a great many statistical tests are built directly upon it. Standard deviation is the version you quote to a person; variance is the version you feed into further calculations. Knowing which one a report is showing prevents a great many misreadings, especially when a squared figure is quoted as if it were measured in the original units. The two answers on this page, 8.0 and 10.0, differ only by that one divisor, yet they lead to noticeably different standard deviations.
The size of the Bessel correction depends sharply on how many observations you have. At five values the difference between dividing by five and dividing by four is substantial — 8.0 versus 10.0, a relative gap of twenty-five percent. By the time you reach a hundred observations the two answers differ by only about one percent, and with very large samples the choice is nearly irrelevant. It is with small samples, where estimates are already fragile, that using the correct divisor matters most, and it is exactly there that people most often skip the correction.
A final caution is that variance says nothing on its own about the shape of a distribution. Two quite different data sets can produce the same variance, and a single extreme value can dominate the result because squaring amplifies outliers. It also assumes the mean is a meaningful centre, which is questionable for heavily skewed data. Read it alongside the mean, a simple plot of the values and, where it helps, the standard deviation. Used that way it is one of the most informative summary numbers available, and the calculations on this page give you all three. That habit of reading the number in context is the difference between merely computing variance and actually understanding it.
Formula
sigma^2 = Sum(xi - mu)^2 / N
Formula page →Use when the observations are the entire population of interest. Subtract the population mean from each value, square the deviations, sum them and divide by the total count N.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| sigma^2 | Population variance | squared units | The average squared deviation; here it equals 8.0 for the five worked values. |
| mu | Population mean | same as data | The true average of all N observations, which is 6.0 in the worked example. |
| N | Population size | count | The count of observations; five here, so the sum of squares of 40 is divided by 5. |
s^2 = Sum(xi - x-bar)^2 / (n - 1)
Formula page →Use when the data is a sample drawn from a larger population. Dividing by n - 1 corrects the downward bias caused by measuring deviations around an estimated mean.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| s^2 | Sample variance | squared units | An unbiased estimate of the population variance; 10.0 for the worked values. |
| x-bar | Sample mean | same as data | The average of the sampled observations, computed from those same values. |
| n | Sample size | count | The number of observations; four is used as the divisor when n is five. |
sigma = sqrt(sigma^2)
Formula page →The square root undoes the squaring and returns the spread to the original units of measurement, making it directly comparable with the mean.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| sigma | Population standard deviation | same as data | The square root of the variance; 2.8284271247461903 from a variance of 8.0. |
| sigma^2 | Variance | squared units | The squared spread used as the intermediate quantity before the root is taken. |
How To Calculate Variance
- 1
Compute the mean
Add every observation and divide by the count: (2 + 4 + 6 + 8 + 10) / 5 = 30 / 5 = 6.0. Everything downstream rests on this number, and a quick check is that the mean must lie between the smallest and largest values.
- 2
Find each deviation from the mean
Subtract the mean from every value: 2 - 6 = -4, 4 - 6 = -2, 6 - 6 = 0, 8 - 6 = 2 and 10 - 6 = 4. These signed distances should sum to zero, which is a convenient way to confirm the subtraction was done correctly before moving on.
- 3
Square the deviations and add them
Squaring gives 16, 4, 0, 4 and 16, which sum to 40. This total of squared deviations is the numerator for both variance formulas. Squaring removes the negative signs and makes large departures from the mean weigh much more heavily than small ones.
- 4
Choose the divisor and divide
For the whole population divide 40 by N = 5 to get 8.0; for a sample divide by n - 1 = 4 to get 10.0. This is the only difference between the two versions, but on five observations the sample answer is a quarter larger, so the choice must be made deliberately.
- 5
Take the square root if you want the original units
The variance is in squared units, so take the square root to recover the scale of the data. The population standard deviation is sqrt(8.0) = 2.8284271247461903; treating the values as a sample gives sqrt(10.0), about 3.1622776601683795. Each sits roughly three units from the mean of 6.0.
Examples
Example 1: The five values treated as a complete population
- x1
- 2
- x2
- 4
- x3
- 6
- x4
- 8
- x5
- 10
| Step | Calculation | Result |
|---|---|---|
| Mean | (2 + 4 + 6 + 8 + 10) / 5 | 6.0 |
| Deviations from the mean | -4, -2, 0, 2, 4 | sum of zero |
| Sum of squared deviations | 16 + 4 + 0 + 4 + 16 | 40 |
| Population variance | 40 / 5 | 8.0 |
| Population standard deviation | sqrt(8.0) | 2.8284271247461903 |
Result: For the complete population the mean is 6.0, the variance is 8.0 and the population standard deviation is 2.8284271247461903 in the original units.
Example 2: The same five values treated as a sample
- x1
- 2
- x2
- 4
- x3
- 6
- x4
- 8
- x5
- 10
| Step | Calculation | Result |
|---|---|---|
| Mean | (2 + 4 + 6 + 8 + 10) / 5 | 6.0 |
| Sum of squared deviations | 16 + 4 + 0 + 4 + 16 | 40 |
| Divide by n minus one | 40 / (5 - 1) | 10.0 |
| Sample standard deviation | sqrt(10.0) | 3.1622776601683795 |
Result: As a sample the variance is 10.0 and the sample standard deviation is 3.1622776601683795, about 11.80% larger than the corresponding population figures.
Example 3: What the divisor choice costs
- x1
- 2
- x2
- 4
- x3
- 6
- x4
- 8
- x5
- 10
| Step | Calculation | Result |
|---|---|---|
| Sum of squared deviations | (2-6)^2 + (4-6)^2 + (6-6)^2 + (8-6)^2 + (10-6)^2 | 40 |
| Population variance | 40 / 5 | 8.0 |
| Sample variance | 40 / 4 | 10.0 |
| Difference between the two variances | 10.0 - 8.0 | 2.0 |
| Relative gap as a percentage | 2.0 / 8.0 | 25.00% |
Result: The sample variance of 10.0 exceeds the population variance of 8.0 by 2.0, a relative gap of 25.00% for these five observations.
Calculator
Population variance
8
- Mean
- 6
- Sample variance
- 10
- Population standard deviation
- 2.8284
Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.
Prefer a full-width tool? Open the Variance calculator page.
Common Mistakes
Dividing by n when the data is only a sample
This systematically understates the population variance, because the deviations were measured around a mean fitted to those same points. Use n - 1 unless the observations genuinely are the entire population of interest.
Forgetting to square the deviations
The signed deviations from the mean always add to zero, so summing them directly gives a meaningless answer of 0. Squaring removes the signs and is what makes the measure of spread possible in the first place.
Confusing variance with standard deviation
Variance is in squared units, so a value of 8.0 is not directly comparable with data around 6.0. Take the square root to obtain 2.8284271247461903 when you need a figure in the original units.
Using n - 1 for a full population
Applying Bessel's correction when you already have every member of the group inflates the answer for no reason. If the five numbers are all the items in the batch, divide by five and report a variance of 8.0, not 10.0.
Assuming the divisor choice is a rounding detail
With only five observations, dividing by four rather than five changes the variance by a full quarter. The correction shrinks as the sample grows, but at small counts it is one of the largest decisions in the whole calculation.
Letting an extreme value dominate unnoticed
Squaring amplifies outliers, so one anomalous reading can drive most of the variance. Always inspect the data or a plot alongside the number, and consider whether the outlier is genuine before reporting the figure.
FAQ
What is variance in simple terms?
It is the typical squared distance of the observations from their mean. You subtract the mean from each value, square the result, and average those squares. A larger variance means the values are more widely scattered around the centre.
Why do we divide by n - 1 for a sample?
Because the sample mean is itself estimated from the data and sits closer to those points than the true population mean would. Squared deviations around it are therefore too small on average. Dividing by n - 1, known as Bessel's correction, removes that bias.
Which variance should I use, population or sample?
Use the population formula when your data is the whole group you care about, such as every pupil in one class. Use the sample formula whenever the values are a subset drawn from a larger group, which is the usual situation in research and surveys.
What units is variance measured in?
The square of the original units, because the deviations were squared. For data in metres the variance is in metres squared. Taking the square root gives the standard deviation, which returns to metres and is usually easier to interpret.
Can variance ever be negative?
No. Every squared deviation is zero or positive, so their sum and the averaged result cannot be negative. A negative figure means a calculation error, most often forgetting to square or misreading a signed deviation.
Why square the deviations rather than take absolute values?
Absolute values give the mean absolute deviation, a valid but different statistic. Squares are smooth and have useful algebraic properties, most importantly that variances of independent quantities add, which underlies much of statistical theory.
References
- [1], Variance — https://en.wikipedia.org/wiki/Variance
- [2], Standard deviation — https://en.wikipedia.org/wiki/Standard_deviation
- [3], Bessel's correction — https://en.wikipedia.org/wiki/Bessel%27s_correction
