Standard deviation calculator

Standard deviation and variance, with both denominators given rather than one picked silently — and the shortcut formula everybody is taught checked against the right answer, because on some data it is out by hundreds of per cent. Nothing you type here leaves your browser — it is worked out on your own device, so there is nothing to send and nothing to log.

n or n − 1, and nobody tells you which they used

Divide the sum of squared deviations by n and you have the standard deviation of the numbers you have. Divide by n − 1 and you have an estimate of the standard deviation of the population they were drawn from.

Both are correct answers to different questions, and the difference is not small on small datasets: at n = 5 the sample variance is twenty-five per cent larger than the population one. Both are given above, labelled.

The rule of thumb: if your numbers are the whole thing you care about, use n. If they are a sample standing in for something bigger, use n − 1. If you are matching somebody else's figure, ask which they used, because they probably did not say.

The formula everybody is taught, and the numbers it cannot do

Textbooks give a shortcut: Σx² − (Σx)²/n. It is algebraically identical to summing the squared deviations, needs only one pass, and it is what nearly every implementation written in a hurry uses.

It falls apart on large numbers that are close together, because it subtracts two enormous nearly-equal quantities and keeps whatever few significant figures survive. On the four values 1000000004, 1000000007, 1000000013, 1000000016 the correct sample variance is exactly 30. The shortcut formula is out by 669 per cent.

Paste those four numbers in and watch. The figure above is computed by summing squared deviations, which does not have this problem, and the page checks the shortcut against it on every dataset and says when they part.

Welford's online algorithm gets it right in a single pass and is what a library ought to use. This site's does.

Where to go next