Statistics & Probability Averages, Variance & Dispersion Descriptive statistics (Bessel-corrected sample variance)

Variance Calculator

This calculator returns the sample variance s2 and the population variance sigma2 from the same list of numbers, together with the sum of squares SS that both are built from. It shows the computational shortcut - sum of x squared, minus the square of the sum divided by n - which is how variance is calculated by hand and by most software, and lays out a table of x and x2 so you can check the two running totals separately.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Data valuesSeparate numbers with commas, spaces or line breaks. Negative values and decimals are fine.4, 9, 11, 12, 17, 5, 8, 12, 14
BasisChoose sample when the data are drawn from a larger group, population when they are the entire group.Sample (n - 1)

It returns

  • Variance (chosen basis) — The average squared distance from the mean, in squared data units.
  • Sample variance s squared
  • Population variance sigma squared
  • Sum of squares SS
  • Mean
  • Degrees of freedom
  • Standard deviation (chosen basis)

The formula

s2=i=1n(xix¯)2n1
SS=x2(x)2n

In plain text: SS = sum(x^2) - (sum x)^2 / n; s^2 = SS / (n - 1); sigma^2 = SS / N

  • s^2Sample variance (squared data units)
  • sigma^2Population variance (squared data units)
  • SSSum of squared deviations from the mean (squared data units)
  • nNumber of observations in the sample (count)
  • NSize of the population (count)

The two expressions for SS - the sum of squared deviations and the shortcut sum(x^2) - (sum x)^2/n - are algebraically identical. The shortcut needs only two running totals but loses precision when the spread is tiny relative to the mean.

Updated Category Averages, Variance & Dispersion Verified against published test cases Reading time 9 min

What variance is and why it is squared

The variance is the mean of the squared distances between each observation and the mean. It measures spread, like the standard deviation, but leaves the answer in squared units: a variance of 4 on data measured in millimetres is 4 mm2, which is not a length and cannot be plotted on the same axis as the data.

That awkwardness is the price of a property nothing else has. Variances add. If two quantities are independent, the variance of their sum is the sum of their variances, and the variance of their difference is also the sum of their variances. Standard deviations do not behave that way, because a square root is not linear. Every method that decomposes variation - analysis of variance, regression's R2, portfolio risk, error budgets in metrology - depends on that additivity, which is why variance is the working quantity in theory and the standard deviation is the reporting quantity in practice.

Variance is also what the squaring buys you. Deviations from the mean sum to exactly zero, so their plain average carries no information. Squaring removes the sign, and it weights a deviation of 4 sixteen times as heavily as a deviation of 1. That is a modelling choice: it makes the mean the natural centre, and it makes the variance highly sensitive to extreme values.

The definition, the shortcut, and the degrees of freedom

Start with the definition. Compute the mean, subtract it from every observation, square each difference, and add them. That total is SS, the sum of squares. Divide SS by n - 1 for a sample and by N for a population, and you have the variance.

The computational shortcut gets the same SS from two running totals instead of two passes over the data:

SS = sum(x2) - (sum x)2 / n

Expanding (x - x-bar)2 gives x2 - 2x·x-bar + x-bar2. Summing term by term, the middle term becomes -2 x-bar times the sum of x, which is -2n·x-bar2, and the last becomes n·x-bar2. Together they leave -n·x-bar2, and since x-bar is (sum x)/n, that is exactly -(sum x)2/n. The two forms are the same expression, not an approximation.

The shortcut has one weakness worth knowing. When the values are large and tightly clustered - readings around 1,000,000 that differ in the third decimal - it subtracts two nearly equal enormous numbers, and floating-point arithmetic loses most of the significant digits. This page computes SS from the deviations directly for that reason, and shows the shortcut's intermediate totals so you can follow a textbook that uses it.

The divisor n - 1 is the degrees of freedom. Because SS is measured around the sample mean rather than the unknown population mean, and the sample mean is the value that minimises SS for these particular data, SS is systematically a little too small. Dividing by n - 1 rather than n corrects the bias exactly, on average, which is Bessel's correction. Equivalently, once the mean is known only n - 1 deviations are free to vary, since they must sum to zero.

Worked example: nine service times

Nine measurements: 4, 9, 11, 12, 17, 5, 8, 12, 14 minutes. Treat them as a sample.

  1. Sum the values. 4 + 9 + 11 + 12 + 17 + 5 + 8 + 12 + 14 = 92.
  2. Sum the squares. 16 + 81 + 121 + 144 + 289 + 25 + 64 + 144 + 196 = 1080.
  3. Find the mean. 92 / 9 = 10.222222 minutes.
  4. Compute the correction term. (sum x)2 / n = 922 / 9 = 8464 / 9 = 940.444444.
  5. Get SS. 1080 - 940.444444 = 139.555556.
  6. Divide by the degrees of freedom. n - 1 = 8, so s2 = 139.555556 / 8 = 17.444444 minutes squared.
  7. Check against the population form. sigma2 = 139.555556 / 9 = 15.506173 minutes squared.

The standard deviation is the square root of the sample variance: sqrt(17.444444) = 4.176654 minutes. That is the figure to quote in a report, because it is in minutes and can be compared with the mean of 10.22 minutes directly - a typical service time sits about four minutes either side of the average.

You can verify SS the long way as a check. The deviations are -6.222, -1.222, 0.778, 1.778, 6.778, -5.222, -2.222, 1.778, 3.778; they sum to zero, and their squares sum to 139.5556, matching step 5.

Reading a variance

A variance is hard to interpret directly, and that is not a failure of understanding on your part - the units are squared. For a sense of spread, take the square root and read the standard deviation instead. Reach for the variance when you need to combine, split or compare sources of variation.

Three situations where the variance is the number you want:

  • Adding independent sources of error. If a measurement has an instrument variance of 0.04 mm2 and an operator variance of 0.09 mm2, the total is 0.13 mm2, so the combined standard deviation is sqrt(0.13) = 0.361 mm - not 0.2 + 0.3 = 0.5 mm. Errors combine in quadrature.
  • Apportioning variation. Analysis of variance splits a total sum of squares into a part explained by group membership and a residual part. The split is only additive on the SS and variance scale.
  • Comparing two spreads formally. The F-test works on the ratio of two variances, so the variance is what you feed it.

An important consequence of squaring: multiplying every observation by a constant c multiplies the variance by c2, while adding a constant to every observation leaves the variance unchanged. Converting a data set from metres to centimetres multiplies the variance by 10,000 and the standard deviation by 100. Shifting a temperature series from Celsius to kelvin changes neither.

Variance and standard deviation for the same data under both bases

Each row is a complete data set. SS is computed from the deviations; the two variances differ only in the divisor.
DatanMeanSSs squaredsigma squareds
1, 2, 3, 4, 553102.521.581139
2, 4, 4, 4, 5, 5, 7, 985324.57142942.138090
10, 202155050257.071068
8, 8, 8, 8480000
4, 9, 11, 12, 17, 5, 8, 12, 14910.222222139.55555617.44444415.5061734.176654
-3, -1, 0, 4, 105210626.521.25.147815

Every row was produced by running this calculator's own formulas on the listed data, then rounded to six decimals. The two-value row shows the correction at its most extreme: s squared is exactly twice sigma squared when n = 2.

Assumptions and traps

  • The variance is not in the data's units. Never plot it on the same axis as the observations or compare it with a mean. Take the square root first.
  • The shortcut formula can lose precision. With large values and small spread, sum(x squared) and (sum x) squared / n are nearly equal and their difference keeps few significant digits. Subtract the mean first, as this page does, or use a compensated algorithm.
  • Variances add only when the quantities are independent. If two measurements are correlated, the variance of their sum also includes twice the covariance, and ignoring that term understates or overstates the total depending on the sign of the correlation.
  • The n - 1 divisor makes the variance unbiased, not the standard deviation. Taking a square root of an unbiased estimator does not give an unbiased estimator, so s underestimates sigma slightly. The effect is small and almost always ignored.
  • A variance computed on grouped or rounded data is biased. If the data have been rounded to a coarse grid, the recorded spread includes the rounding. Sheppard's correction subtracts h squared over 12 for a bin width h.
  • One extreme value can dominate. Because deviations are squared, a single observation far from the mean can supply most of SS. Check the sorted data and the interquartile range before you accept a large variance as real.

Related measures and when to use them

The standard deviation is this page's answer with a square root applied, and it is what you report to a reader. Use variance internally, standard deviation externally.

When the data are skewed or contain values you do not trust, spread is better described by position than by squared distance. The interquartile range is the width of the middle half of the data and is unaffected by how extreme the extremes are. A median with an IQR and a mean with a standard deviation are the two coherent pairings; mixing them invites confusion.

If observations carry different weights - unequal sample sizes behind each figure, or measurements of unequal precision - the plain variance is the wrong tool, and you need a weighted calculation; the weighted average calculator shows how the weighting works on the centre. To convert a mean and a variance into probabilities, take the square root and use the normal distribution calculator, or standardise a single value with the z-score calculator.

Finally, the variance of a theoretical distribution is often known in closed form and does not need to be estimated at all. A binomial count over n trials with success probability p has variance np(1 - p) exactly, as the binomial distribution calculator reports. When a model applies, use its formula rather than estimating from a sample.

Frequently asked questions

What is the difference between variance and standard deviation?

The standard deviation is the square root of the variance. The variance is in squared units and adds across independent sources of variation; the standard deviation is in the data's own units and is what you quote in a report. They contain exactly the same information, so choosing between them is about convenience, not accuracy.

When should I divide by n instead of n - 1?

Only when your data are the whole population you are describing - every machine in the shop, every month in the year, every pupil who sat the paper. If the data are a sample from something larger, divide by n - 1. Excel's VAR.S, R's var() and NumPy's var(ddof=1) all use n - 1; NumPy's plain var() uses n.

Can variance be negative?

No. It is a sum of squares divided by a positive count, so it is zero or positive, and it is zero only when every observation is identical. A negative result from a spreadsheet almost always means the shortcut formula has lost precision on large, tightly clustered numbers.

What is the sum of squares SS?

SS is the total of the squared deviations from the mean, before any division. It is the quantity both variances share, and it is what analysis of variance partitions between groups and within groups. Reporting SS alongside the degrees of freedom lets anyone reconstruct either variance.

Why does the shortcut formula sometimes give a slightly different answer?

Because of floating-point rounding, not because the algebra differs. sum(x squared) and (sum x) squared / n can each be very large while their difference is small, and the subtraction discards most of the significant digits. This page subtracts the mean from each value first, which keeps the intermediate numbers small and the result accurate.

How does variance change if I convert the units?

Multiplying every observation by a constant c multiplies the variance by c squared. Metres to centimetres multiplies the data by 100 and the variance by 10,000. Adding a constant to every observation - a calibration offset, a change of origin - leaves the variance completely unchanged.

What is a typical variance?

There is no typical value, because the number depends on both the units and their scale. Judge spread by taking the square root and comparing the standard deviation with the mean, or against a tolerance, a specification or your own historical figures for the same measurement.

Do I need the data sorted?

No. The variance depends only on the values, not their order, so an unsorted paste gives the same answer. Sorting matters for the median, the quartiles and the percentiles, which are defined by position.

References