Standard Deviation and Variance Calculator: Sample and Population

Heading to the field? Install this site from your browser menu and this tool works with no signal. See how

Standard Deviation and Variance Calculator

Paste your numbers and the tool shows the working, not just the answer. Sample and population are calculated side by side, because picking the wrong one is the mistake that costs marks and misstates real results.

s = 2.13809

s = square root of ( sum of squared deviations / (n minus 1) )

Try a worked example

Distribution, with the mean and one, two and three standard deviations

The working, value by value

Three panels about standard deviation. Squares drawn on a baseline show each value in the set 2, 4, 4, 4, 5, 5, 7, 9 with a square whose side equals its distance from the mean of 5, the areas totalling 32. Two boxes show the same 32 divided by 8 giving a population sigma of 2, and divided by 7 giving a sample s of 2.138090. A curve plots how much larger the sample figure is than the population one against sample size, falling from 41.4 percent at n equals 2 to 0.5 percent at n equals 100.
The bottom panel is the part that gets skipped in teaching. Bessel correction is not a small technicality on small samples: at n equals 2 the sample figure is over 40 percent larger than the population one. By n equals 100 it barely matters.

How to use this tool

Paste your numbers into the box. Commas, spaces, tabs or line breaks all work, so a column copied straight out of a spreadsheet goes in without any tidying up. Anything that is not a number gets skipped and the tool tells you how many it dropped, so a stray header row will not silently corrupt your answer.

Then pick sample or population, and this is the only decision that really matters. Get it wrong and every figure below it is wrong too. The table underneath shows the working for each value, so you can hand it in, check it against a textbook, or paste it into a report and have someone follow what you did.

Sample or population, and why it changes the answer

Population means your numbers are the whole group you care about, with nothing missing. Every pupil in one class when the class is the entire subject of the question. Every cylinder cast from one pour when that pour is all you are describing. You divide the sum of squared deviations by the count.

Sample means your numbers are a subset drawn from something larger, and you want to use them to estimate the spread of that larger thing. Twenty concrete cylinders standing in for a season of production. Thirty households standing in for a town. Here you divide by the count minus one.

That minus one is Bessel correction and it is not a fudge. Your sample mean is calculated from your own data, so by construction it sits closer to your numbers than the true population mean does. Measuring spread from a centre that has been pulled toward you makes the spread look smaller than it really is. Dividing by a smaller number pushes the answer back up by the right amount, and the correction is largest when the sample is small, which is exactly when the bias is worst.

At n equals 5 the sample figure is about 12 percent larger than the population one. At n equals 100 the gap is about half a percent. This is why the distinction feels academic on big datasets and matters enormously on small ones, which is where most real engineering samples live.

What the calculation is doing

Find the mean. Subtract it from every value to get a deviation. Those deviations always sum to zero, which the totals row in the table shows, so you cannot just average them and call it spread. Square each one to make them all positive, add the squares together, and that total is the sum of squares.

Divide the sum of squares by n or by n minus one and you have the variance. Take the square root and you have the standard deviation. The square root is what brings the answer back into the same units as your data, which is why standard deviation is the figure people quote and variance is mostly a step along the way. If your numbers are in psi, the variance is in psi squared and means very little to anyone. The standard deviation is in psi and can sit next to a strength value in a report.

A worked check you can repeat on paper

Use the default set: 2, 4, 4, 4, 5, 5, 7, 9. There are eight values and they add to 40, so the mean is 5.

Now the deviations: minus 3, minus 1, minus 1, minus 1, zero, zero, 2 and 4. Add those and you get zero, which is the check that your mean is right. Square them and you get 9, 1, 1, 1, 0, 0, 4 and 16, which total 32. That 32 is the sum of squares.

Treat it as a population and divide 32 by 8, giving a variance of 4 and a standard deviation of exactly 2. Treat it as a sample and divide 32 by 7, giving a variance of 4.571429 and a standard deviation of 2.138090. Same data, two answers, and the only difference is which question you asked.

This particular set is worth keeping in your head because the population answer comes out as a whole number. If a calculator gives you 2 for this data it is using the population formula, and if it gives 2.14 it is using the sample formula. That is a five second way to check what any tool is actually doing before you trust it with real numbers.

Where this matters in concrete testing

Standard deviation is not just a statistics exercise in construction, it sets the mix you have to supply. ACI 214 uses the standard deviation of a producer past results to work out the required average strength, the figure the mix must actually be designed for, which sits above the specified strength on the drawings.

For specified strength up to 5000 psi the required average is the larger of two expressions: the specified strength plus 1.34 times the standard deviation, or the specified strength plus 2.33 times the standard deviation minus 500. Take a 4000 psi specification and a producer with a standard deviation of 400 psi. The first gives 4536, the second gives 4432, so the required average is 4536 psi. Now take a producer running at 600 psi standard deviation on the same specification. The first gives 4804, the second gives 4898, so they must target 4898 psi.

That is a 362 psi penalty for being less consistent, on the same specified strength, and it is paid in cement every single cubic yard. A producer with tight control supplies a leaner, cheaper mix and still passes. This is the clearest example there is of why variability costs money rather than being an abstract statistical property, and it is why consistency is worth investing in even when the average is already fine.

Mistakes that catch people out

Using population when you have a sample. The most common error and the one with the most consequences, because it always understates the spread. In any context where you are estimating from a subset, and that is nearly every real measurement programme, you want the sample setting.

Assuming the 68, 95, 99.7 rule applies to your data. Those percentages come from the normal distribution and hold only if your data is roughly normal. The chart shows what fraction of your values actually fall within one standard deviation, so you can see whether the assumption is reasonable. Skewed data, or data with a hard floor at zero, will not match.

Letting one outlier drive the answer. Squaring the deviations means a single distant value dominates everything. Load the outlier example above and watch the standard deviation more than quadruple from one changed number. That is not a flaw in the maths, it is the maths working as designed, but it means you should look at the distribution before quoting a figure.

Comparing standard deviations across different units or scales. A standard deviation of 50 means something completely different on values averaging 100 than on values averaging 10,000. That is what the coefficient of variation is for, expressing the spread as a percentage of the mean so two datasets can be compared honestly.

Assuming every tool uses the same quartile convention. There are several accepted methods and they disagree on small datasets. This tool uses linear interpolation, which matches Excel QUARTILE.INC and the NumPy default. If your figures differ slightly from another source, this is usually why, and neither of you is wrong.

How this was checked

The engine was written twice and the two versions compared on the same datasets. The standard textbook set of 2, 4, 4, 4, 5, 5, 7, 9 returns a mean of 5, a sum of squares of 32, a population standard deviation of exactly 2 and a sample standard deviation of 2.138090. The set 1 to 5 returns a population variance of 2 and a sample variance of 2.5. Quartiles were checked against a published eleven value example and return 25.5 and 42.5.

Degenerate cases were tested deliberately. A single value returns a population standard deviation of zero and correctly reports the sample figure as undefined rather than showing zero, since dividing by n minus one is dividing by nothing. A set of identical values returns zero rather than a rounding artefact. The ACI 214 figures above were computed rather than transcribed.

Numerical stability was checked with values near one billion that differ by only a few units, a case where a naive one pass formula loses precision badly. The two pass method used here returns the sample variance as exactly 30. That example is loaded in the buttons above if you want to see it.

Worked examples

Each link opens the tool with that dataset loaded, showing the full working. They are chosen to make a point rather than to pad a list.

Open the classic textbook set · the numbers one to five · a small eight value sample · eight concrete cylinder breaks in psi · ten exam scores · five identical values · the same set with one wild outlier · four large numbers with a tiny spread.

The last three are the interesting ones. Identical values should give exactly zero and not a rounding artefact. The outlier set shares seven of its eight numbers with the classic set and lands nowhere near it. The large number set is the one that breaks calculators using a single pass formula, and it should come back as a sample variance of exactly 30.

Related Calculators and Reference