Mathematics · Probability & Statistics
Variance Calculator
Calculate population or sample variance from a dataset to measure the spread of values around the mean.
Calculator
Formula
For sample variance (s²): sum the squared differences between each value xᵢ and the sample mean x̄, then divide by (n−1) where n is the count of values. For population variance (σ²): divide the same sum by n instead of n−1. The divisor n−1 is Bessel's correction, used when estimating population variance from a sample.
Source: Kenney, J. F. and Keeping, E. S. (1951). Mathematics of Statistics, Part 2, 2nd ed. Van Nostrand. §7.7; NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.2.
How it works
To compute variance, the calculator first finds the arithmetic mean of all valid numeric values you provide. It then computes the squared deviation of each data point from that mean — squaring ensures that positive and negative deviations do not cancel each other out, and gives extra weight to values that are far from the center. Those squared deviations are summed to produce the sum of squares, which is an intermediate value also shown in the output.
The sum of squares is then divided by a denominator that depends on whether you are working with a full population or a sample. For a population variance (σ²), you divide by n — the total number of values — because you have measured every member of the group and there is no estimation involved. For sample variance (s²), you divide by n−1, not n. This is called Bessel's correction: when you estimate a population's variance from only a subset of its members, dividing by n systematically underestimates the true variance. The subtraction of 1 corrects for this bias by producing an unbiased estimator of the population variance. As a practical rule, use sample variance whenever your dataset is a subset of a larger group you want to draw conclusions about.
The standard deviation shown in the output is simply the positive square root of the variance, restoring the result to the original units of measurement. Variance itself is expressed in squared units (e.g., dollars², kilograms²), which is why standard deviation is often easier to interpret in context. Together, these two statistics describe not just where data is centred, but how reliably that centre represents the entire dataset.
Worked example
Suppose you record the daily high temperatures (°C) for one week: 18, 21, 19, 25, 22, 20, 23 and want the sample variance.
Step 1 — Count: n = 7
Step 2 — Mean: x̄ = (18 + 21 + 19 + 25 + 22 + 20 + 23) / 7 = 148 / 7 ≈ 21.143°C
Step 3 — Squared deviations:
(18 − 21.143)² = (−3.143)² ≈ 9.878
(21 − 21.143)² = (−0.143)² ≈ 0.020
(19 − 21.143)² = (−2.143)² ≈ 4.592
(25 − 21.143)² = (3.857)² ≈ 14.877
(22 − 21.143)² = (0.857)² ≈ 0.734
(20 − 21.143)² = (−1.143)² ≈ 1.306
(23 − 21.143)² = (1.857)² ≈ 3.449
Step 4 — Sum of squares: 9.878 + 0.020 + 4.592 + 14.877 + 0.734 + 1.306 + 3.449 ≈ 34.857
Step 5 — Sample variance: s² = 34.857 / (7 − 1) = 34.857 / 6 ≈ 5.810 °C²
Step 6 — Standard deviation: s = √5.810 ≈ 2.411°C, meaning temperatures typically deviate about 2.4°C from the weekly average.
Limitations & notes
This calculator assumes that all input values are finite real numbers; non-numeric entries, blanks, or text tokens are silently ignored, so always verify the detected count (n) matches your intended dataset size. Variance is sensitive to outliers — a single extreme value can dramatically inflate the result, making median absolute deviation (MAD) a more robust alternative for skewed or contaminated data. For very large datasets with values of vastly different magnitudes, floating-point rounding in the browser can introduce small numerical errors; dedicated statistical software such as R or Python (NumPy) uses compensated summation algorithms to mitigate this. Finally, variance is only a meaningful measure of spread for unimodal, roughly symmetric distributions; for bimodal or heavily skewed data, inspect the full distribution rather than relying solely on variance as a summary statistic.
Frequently asked questions
When should I use sample variance instead of population variance?
Use sample variance (s², divide by n−1) whenever your data is a subset drawn from a larger population and your goal is to estimate that population's true variance. Population variance (σ², divide by n) is appropriate only when your dataset contains every single member of the population you care about, such as all employees in a specific company or all products from a single production batch. In academic research and most real-world data analysis, sample variance is the default choice.
Why is variance squared while standard deviation is not?
Variance is defined as the average of squared deviations, so its unit is the square of the original unit (e.g., cm²). Standard deviation is the square root of variance, which brings the measure back into the original unit (e.g., cm), making it more interpretable alongside the mean. The squaring step is mathematically necessary to prevent positive and negative deviations from cancelling out and to make the resulting statistic differentiable and analytically convenient for further mathematical work.
What does a variance of zero mean?
A variance of zero means every value in the dataset is identical — there is absolutely no spread, and every observation equals the mean. In practice, true zero variance is rare and may indicate a data collection or entry error, a constant being incorrectly treated as a variable, or a perfectly controlled experimental condition. Any non-zero variance, however small, confirms that at least two values in the dataset differ.
How is variance related to standard deviation?
Standard deviation is simply the positive square root of variance: s = √s² for samples and σ = √σ² for populations. They convey the same information about spread, but standard deviation is expressed in the same units as the data, making it more intuitive for reporting. Variance is preferred in mathematical derivations and statistical tests (such as F-tests and ANOVA) because it decomposes additively — the variance of the sum of independent random variables equals the sum of their individual variances.
Can variance be negative?
No. Because variance is computed as a sum of squared terms divided by a positive number, it is always greater than or equal to zero. A negative variance result would indicate a computational error or a programming bug. The minimum possible variance is zero, achieved only when all data values are equal. This non-negativity property is one reason variance is a mathematically well-behaved measure of dispersion.
Last updated: 2025-01-15 · Formula verified against primary sources.