Variance Calculator
The variance of 2, 4, 4, 4, 5, 5, 7 and 9 is 4.0000 treated as a population and 4.5714 as a sample. The mean is 5 and the squared deviations add to 32, so the only difference between the two answers is the divisor: 8 against 7.
| Population variance | |
| Sample variance | |
| Count | |
| Mean | |
| Sum of squared deviations | |
| Population standard deviation | |
| Sample standard deviation | |
| Minimum and maximum | |
| Range | |
Both variances come from the same sum of squares, so the two answers differ only by the divisor. In frequency mode every value counts as many times as its count says. The maths runs in your browser and nothing you paste is uploaded or stored.
Paste a list of numbers and get both variances, the sum of squares and the standard deviation, with the divisor printed so you can see which formula produced each answer.
Key takeaways
- Population variance divides the sum of squares by N, sample variance divides it by n minus 1
- For 2, 4, 4, 4, 5, 5, 7 and 9 the sum of squares is 32, so the population variance is 4.0000 and the sample variance is 4.5714
- Variance is reported in squared units, so a spread of 5 cm is a variance of 25 square centimetres
- Variances add for independent variables only: two bus legs with variances 4 and 9 give a total variance of 13 and a standard deviation of 3.6056
- One value of 100 in that eight number set pushes the sample variance from 4.5714 to 1006.7778
On this page
What variance measures
Variance is the average squared distance between each value and the mean of the data. The NIST/SEMATECH e-Handbook of Statistical Methods puts it among the measures of scale and points out the reason for squaring: a point 2 units from the mean adds 4 to the total, while a point 10 units away adds 100. Distance gets counted twice over in the tail, which is what makes variance sensitive to outliers.
The price of squaring is the unit. A set of heights in centimetres has a variance in square centimetres, a set of salaries in dollars has a variance in dollars squared, and neither number can be read off a chart directly. Standard deviation fixes that by taking the square root, which is why most reports quote the standard deviation and most formulas use the variance. OpenStax Introductory Statistics makes the same split between the two measures.
Variance is also what makes the arithmetic of random variables work. Sums and differences of independent quantities add their variances rather than their standard deviations, and the whole machinery of regression, analysis of variance and portfolio risk is built on that one property.
Two numbers describe the same spread and answer different questions. The variance is the input to further maths; the standard deviation is the number to put in front of a person.
Sample or population: the divisor question
The formula has one free choice, and it is the divisor. Population variance, written sigma squared, divides the sum of squared deviations by N, the number of values. Sample variance, written s squared, divides by n minus 1.
| Case | Divisor | Symbol | When it applies |
|---|---|---|---|
| Population variance | N | sigma squared | Every member of the group was measured |
| Sample variance | n minus 1 | s squared | A subset stands in for a larger group |
The n minus 1 exists because a sample mean sits closer to its own data than the true mean does, so dividing by n understates the spread. The correction is called Bessel's correction, and it makes the sample variance unbiased: across repeated samples the average of s squared lands on the population value.
The size of the gap depends on n and nothing else. With 8 values the sample variance is 14.29 percent larger than the population variance, 4.5714 against 4.0000. With 100 values the gap is about 1 percent, and with 1,000 values it is about 0.1 percent. Small samples are where the choice changes a report, which is exactly where most student work and most pilot studies sit.
Decide with one question: did the data include every case you care about? Monthly returns for all twelve months of one year are a population of that year. The same twelve months used to describe the next decade are a sample, and the divisor should be 11.
A worked example you can check by hand
Take the eight values 2, 4, 4, 4, 5, 5, 7 and 9. The mean is 40 / 8 = 5.0000. Subtract the mean from each value, square the result, and add:
| Value | Value minus mean | Squared deviation |
|---|---|---|
| 2 | -3 | 9 |
| 4 | -1 | 1 |
| 4 | -1 | 1 |
| 4 | -1 | 1 |
| 5 | 0 | 0 |
| 5 | 0 | 0 |
| 7 | 2 | 4 |
| 9 | 4 | 16 |
| Total | 0 | 32 |
The deviations sum to zero, which is always true and is a free check on the mean. The squared deviations sum to 9 + 1 + 1 + 1 + 0 + 0 + 4 + 16 = 32. That figure is the sum of squares, and both variances come out of it: 32 / 8 = 4.0000 for the population and 32 / 7 = 4.5714 for the sample.
The standard deviations are the square roots, 2.0000 and 2.1381. Read those back in the original units: a typical value sits about 2 units from the mean of 5. Neither variance of 4 nor 4.5714 can be read that way, which is the point of keeping both numbers around.
The shortcut formula and its rounding trap
Subtracting the mean from every value is tedious by hand and slow on a large file, so textbooks offer a shortcut: the sum of squares equals the sum of the squared values minus the square of the sum divided by n. For the same eight values, the squared values add to 4 + 16 + 16 + 16 + 25 + 25 + 49 + 81 = 232, the sum is 40, and 40 x 40 / 8 = 200. Then 232 - 200 = 32, matching the long way.
The shortcut is mathematically identical and numerically worse. Both terms on the left are large and close, so their difference loses significant digits. Store 1,000,001 and 1,000,003 in a spreadsheet and the squared values are around 1,000,002,000,000 each, a sum near two trillion, while the variance is 2. A float with 15 or 16 significant digits has already rounded away the digit that mattered.
The fix costs one line: subtract a constant near the middle before squaring. Shift those two values down by 1,000,000 and they become 1 and 3, with a mean of 2, a sum of squares of 2, and a sample variance of 2. Variance ignores shifts, so the answer is exact and the arithmetic is trivial.
The same trick matters in code. Computing variance as the mean of the squares minus the square of the mean is the classic source of a negative variance on a data set that is nearly constant, which then breaks the square root.
Grouped data and frequency tables
When the data arrive as counts, each value carries a weight. The mean becomes the sum of value times frequency divided by the total count, and the sum of squares sums frequency times the squared deviation. The calculator has a frequency mode for exactly this layout.
| Value | Frequency | Value x frequency | Deviation from 2.4 | Frequency x squared deviation |
|---|---|---|---|---|
| 1 | 2 | 2 | -1.4 | 3.92 |
| 2 | 3 | 6 | -0.4 | 0.48 |
| 3 | 4 | 12 | 0.6 | 1.44 |
| 4 | 1 | 4 | 1.6 | 2.56 |
| Total | 10 | 24 | 8.40 |
The mean is 24 / 10 = 2.4. The weighted sum of squares is 3.92 + 0.48 + 1.44 + 2.56 = 8.40, so the population variance is 8.40 / 10 = 0.8400 and the sample variance is 8.40 / 9 = 0.9333. The standard deviation is 0.9165.
Grouped data has one honest limitation. Every value inside a class is treated as if it sat at the class midpoint, so spread within a class disappears. Wide classes therefore understate the variance, and a frequency table built from ranges rather than exact values will always report a slightly smaller spread than the raw data would.
Adding variables: when variances do and do not add
For two random variables, the variance of the sum is the sum of the variances plus twice the covariance. When the two are independent the covariance is zero and the variances add directly, which is the rule people remember and misapply.
Take a commute with two legs. The first leg takes 20 minutes with a variance of 4, the second takes 15 minutes with a variance of 9, and the legs are independent because a delay on the bus says nothing about the train. Total variance is 4 + 9 = 13, and the standard deviation is 3.6056 rather than 2 + 3. Adding standard deviations overstates the uncertainty of the trip.
| Correlation | Variance of a 50/50 mix of two assets with variance 100 | Standard deviation |
|---|---|---|
| +1.0 | 100.0 | 10.00 |
| 0.0 | 50.0 | 7.07 |
| -1.0 | 0.0 | 0.00 |
The finance version uses the same algebra with covariance left in. Two assets with variance 100 each, held 50/50, give a portfolio variance of 0.25 x 100 + 0.25 x 100 plus a cross term that depends on correlation. At a correlation of zero the variance is 50 and the standard deviation 7.07, which is why diversification lowers risk without lowering the average return. At a correlation of 1 the cross term cancels the benefit and the portfolio behaves like one asset.
The subtraction case is the one that surprises people: the variance of a difference is the sum of the variances when the variables are independent, not the difference. Comparing two group means adds uncertainty from both groups.
Squared units and rescaling
Variance carries the square of the unit, and that shows up the moment a data set changes scale. Multiply every value by a constant k and the variance multiplies by k squared; the standard deviation multiplies by k. Shifting every value by a constant changes nothing at all, because deviations from the mean do not move.
| Change to the data | Effect on variance | Effect on standard deviation |
|---|---|---|
| Add 100 to every value | None | None |
| Measure in millimetres instead of centimetres | Multiplied by 100 | Multiplied by 10 |
| Convert Celsius to Fahrenheit | Multiplied by 3.24 | Multiplied by 1.8 |
| Convert a variance in square centimetres to square metres | Divided by 10,000 | Standard deviation divided by 100 |
A set of lengths with a standard deviation of 5 cm has a variance of 25 square centimetres. In metres that is 0.0025 square metres and a standard deviation of 0.05 m. Both statements describe the same spread, and mixing the two units in one report is a common way to make a result look 10,000 times better or worse than it is.
Temperature is the case that trips people up, because the conversion has an offset. Fahrenheit equals 1.8 times Celsius plus 32, and the offset drops out of every deviation, so a standard deviation of 5 Celsius degrees is 9 Fahrenheit degrees and a variance of 25 becomes 81. The offset never enters a variance, only the scale factor does.
When variance misleads
Variance is a good summary of a symmetric, well behaved data set and a poor summary of almost anything else.
Add one value of 100 to the eight numbers used above. The sum becomes 140, the mean 15.5556, and the sample variance jumps from 4.5714 to 1006.7778, a standard deviation of 31.7298. One entry out of nine moved the number by a factor of 220 while the other eight values never changed.
That sensitivity is a feature when large deviations are the thing you care about, such as manufacturing tolerances or trading losses. It is a bug when a single typo or a single unusual customer sits in the file. Two alternatives handle the second case: the median absolute deviation and the interquartile range, both of which the NIST handbook lists next to the variance. Neither squares the distance, so no single point can dominate.
Comparing spread across data sets with different units needs the coefficient of variation, which is the standard deviation divided by the mean. Heights with a standard deviation of 3 in around a mean of 66 in give 3 / 66 x 100 = 4.55 percent. Weights with a standard deviation of 15 lb around 170 lb give 15 / 170 x 100 = 8.82 percent, so the weights are the more variable measurement even though 15 is the larger number.
Variance also assumes a meaningful mean. For income, house prices and other skewed quantities the mean sits above most of the data, and a variance around it describes a typical value that few cases reach.
Frequently asked questions
What is variance in simple terms?
The average squared distance from the mean. For 2, 4, 4, 4, 5, 5, 7 and 9 the mean is 5, the squared deviations add to 32, and the population variance is 4.0000.
What is the difference between sample and population variance?
Population variance divides the sum of squares by N, sample variance divides by n minus 1. With 8 values and a sum of squares of 32, the answers are 4.0000 and 4.5714.
Why divide by n minus 1?
Because a sample mean sits closer to its own data than the true mean does. Dividing by n minus 1 corrects that bias, and the correction matters most in small samples: at n = 8 it changes the answer by 14.29 percent.
How do I calculate variance by hand?
Find the mean, subtract it from each value, square each result, add them, then divide. For 2, 4, 4, 4, 5, 5, 7 and 9 the squares are 9, 1, 1, 1, 0, 0, 4 and 16, which total 32.
What are the units of variance?
The square of the original unit. A data set in centimetres has a variance in square centimetres, so a standard deviation of 5 cm is a variance of 25 square centimetres.
Can variance be negative?
No, because it is a sum of squares. A negative result from software means the shortcut formula lost precision, which happens when the values are large and nearly equal.
How do I find variance from a frequency table?
Multiply each squared deviation by its frequency, add those products, and divide by the total count. For values 1, 2, 3 and 4 with frequencies 2, 3, 4 and 1, the weighted sum is 8.40 and the population variance is 0.8400.
Do variances add?
They add for independent variables. A commute of two independent legs with variances 4 and 9 has a total variance of 13, so the standard deviation is 3.6056 rather than 2 plus 3.
Why is my variance so much larger than my standard deviation?
Because the variance is in squared units. A standard deviation of 2 becomes a variance of 4, and a standard deviation of 30 becomes a variance of 900.
What happens to variance if I add 10 to every value?
Nothing. Adding a constant shifts the mean by the same amount and leaves every deviation unchanged, so the variance stays exactly the same.
What happens to variance if I double every value?
It multiplies by 4, because the scale factor is squared. Doubling also doubles the standard deviation, and converting Celsius to Fahrenheit multiplies the variance by 3.24.
Is variance affected by outliers?
Heavily, because deviations are squared. One value of 100 among eight small numbers pushes the sample variance from 4.5714 to 1006.7778. The median absolute deviation and the interquartile range resist that.
What is the coefficient of variation?
The standard deviation divided by the mean, usually written as a percentage. Heights with a standard deviation of 3 in around a mean of 66 in give 4.55 percent, which lets you compare spread across different units.
How is variance used in finance?
As a measure of risk. Two assets with variance 100 each, held 50/50 and uncorrelated, give a portfolio variance of 50 because the covariance term is zero, so the standard deviation falls from 10 to 7.07.
Spotted a wrong number or a broken result?
More Math tools
Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.