Variance Calculator
Find the variance of any list of numbers — population or sample. Enter your values below, and see the formula, a worked example, and ready-to-use Python code underneath.
Enter your data
Separate values with commas, spaces, or new lines — e.g. 12, 15, 9, 21, 14
Not sure which to pick? Sample is the more common choice — see the FAQ below.
Please enter at least one valid number.
What variance tells you
Variance measures how spread out a data set's values are around its mean, by averaging the squared distance of every value from the mean. A larger variance means the data is more spread out; a variance near zero means the values are clustered tightly around the mean.
Because the deviations are squared, variance is expressed in squared units — if your data is in dollars, variance is in dollars². That's why the standard deviation (the square root of variance) is usually reported alongside it, or instead of it, when you want a number in the same units as the original data.
Variance formula
Sample: s² = Σ(xᵢ − x̄)² / (n − 1)
Python code
You can compute variance manually, or with Python's statistics or NumPy:
# Method 1 — manual calculation (sample) data = [12, 15, 9, 21, 14] mean_value = sum(data) / len(data) squared_diffs = [(x - mean_value) ** 2 for x in data] sample_variance = sum(squared_diffs) / (len(data) - 1) print(sample_variance) # 19.7 # Method 2 — statistics module import statistics statistics.pvariance(data) # population variance statistics.variance(data) # sample variance # Method 3 — NumPy (ddof=1 for sample, ddof=0 for population) import numpy as np np.var(data, ddof=1) # sample variance np.var(data, ddof=0) # population variance
Worked example
Using the same five quiz scores as the mean calculator example — 12, 15, 9, 21, and 14 — which have a mean of 14.2.
| xᵢ | xᵢ − mean | (xᵢ − mean)² |
|---|---|---|
| 12 | −2.2 | 4.84 |
| 15 | 0.8 | 0.64 |
| 9 | −5.2 | 27.04 |
| 21 | 6.8 | 46.24 |
| 14 | −0.2 | 0.04 |
- 1Find the mean.
(12 + 15 + 9 + 21 + 14) / 5 = 14.2 - 2Subtract the mean from each value and square the result.
See the table above — the squared deviations sum to 78.8. - 3Divide by n (population) or n − 1 (sample).
Population: 78.8 / 5 = 15.76 | Sample: 78.8 / 4 = 19.7
If these five scores are the entire class, the population variance is 15.76. If they're a sample from a larger class, the sample variance is 19.7.
Frequently asked questions
What is the difference between variance and standard deviation?
Variance is the average of the squared deviations from the mean. Standard deviation is the square root of the variance. Because variance is in squared units (for example, dollars squared), standard deviation is usually easier to interpret since it's back in the original units.
Should I use population or sample variance?
Use the population formula (divide by N) only when your data represents every member of the group you care about. Use the sample formula (divide by n − 1) when your data is a subset drawn from a larger population, which is the more common situation in practice.
Can variance be negative?
No. Variance is an average of squared deviations, and a square is never negative, so variance is always zero or positive. A variance of zero means every value in the data set is identical.
Why are the deviations squared instead of just added up?
Deviations from the mean always sum to exactly zero, since positive and negative differences cancel out. Squaring each deviation before averaging makes every difference positive, so the spread doesn't cancel itself out, and it also weights larger deviations more heavily.