Standard deviation measures how spread out a set of numbers is: roughly, the typical distance of a value from the mean. A small standard deviation means the values cluster tightly; a large one means they're scattered. It's in the same units as the data, which is what makes it more useful day to day than variance.
The formula
Sample: s = √( Σ(x − x̄)² / (n − 1) )
Population: σ = √( Σ(x − μ)² / n )
Σ means "add up", x is each value, x̄ (or μ) is the mean and n is how many values there are. The two versions differ only in the bottom line, and that matters more than it looks. More on that below.
Worked example
Ten measurements: 12, 15, 18, 22, 25, 28, 30, 32, 35, 40.
Step 1: find the mean
Σx = 12 + 15 + 18 + 22 + 25 + 28 + 30 + 32 + 35 + 40 = 257
x̄ = 257 / 10 = 25.7
Step 2: subtract the mean from each value, and square the result
| x | x − x̄ | (x − x̄)² |
|---|---|---|
| 12 | −13.7 | 187.69 |
| 15 | −10.7 | 114.49 |
| 18 | −7.7 | 59.29 |
| 22 | −3.7 | 13.69 |
| 25 | −0.7 | 0.49 |
| 28 | 2.3 | 5.29 |
| 30 | 4.3 | 18.49 |
| 32 | 6.3 | 39.69 |
| 35 | 9.3 | 86.49 |
| 40 | 14.3 | 204.49 |
| Total | 0 | 730.1 |
The middle column always adds up to zero. That's a good check that you've got the mean right. If it doesn't, stop and fix the mean before going on.
The squared deviations are there because the raw deviations cancel out. Squaring makes them all positive, and it weights big deviations more heavily than small ones.
Step 3: divide by n − 1 (or n)
Sample variance: s² = 730.1 / 9 = 81.122
Population variance: σ² = 730.1 / 10 = 73.01
Step 4: take the square root
Sample standard deviation: s = √81.122 = 9.007
Population standard deviation: σ = √73.01 = 8.545
Check these with the statistics calculator. It shows both versions, plus the variance, quartiles and standard error.
Open with this datan or n − 1? How to choose
Ask yourself: is this all the data I care about, or a sample from something bigger?
- A sample (use n − 1): ten resistors tested from a batch of thousands; a survey of 200 people; five repeat measurements of the same length. You want to estimate the spread of the whole population, so you need s.
- The whole population (use n): the exam marks of everyone in one class, when you only want to describe that class; the heights of all 11 players in a team. There's nothing beyond the data, so use σ.
In practice, nearly everything in science and engineering is a sample, so s is the right default. It's what Excel's STDEV.S and the older STDEV return.
Why dividing by n − 1 makes sense
You measure deviations from the sample mean x̄, but x̄ is calculated from the same data, so it always sits right in the middle of your particular values. The true population mean is almost certainly a bit further away. That means Σ(x − x̄)² comes out slightly too small on average, and dividing by n − 1 instead of n corrects for it exactly. This is called Bessel's correction.
Another way to see it: once you know the mean and nine of the ten deviations, the tenth is fixed (they must add to zero). Only n − 1 of the deviations carry independent information, which is what statisticians mean by "n − 1 degrees of freedom".
The difference shrinks as n grows. With 10 values, s is 5.4% bigger than σ. With 100 values it's 0.5%; with 1,000, 0.05%.
A quicker formula for hand calculation
Subtracting the mean from every value is tedious if the mean is an awkward decimal. This version only needs the sum and the sum of squares:
Σ(x − x̄)² = Σx² − (Σx)² / n
For our data, Σx² = 12² + 15² + … + 40² = 7,335, so Σ(x − x̄)² = 7,335 − 257²/10 = 7,335 − 6,604.9 = 730.1. Same answer.
It subtracts two large numbers that are nearly equal, so it's prone to rounding error when the values are large and close together, for example readings like 1,000,001, 1,000,003 and 1,000,002. Round Σx² and you can get a negative "variance". Keep every digit, or use the two-step method. Kalkuli always uses the two-step method for this reason; the precision guide explains why.
What the number tells you
For data that's roughly bell-shaped (normally distributed), about 68% of values lie within one standard deviation of the mean and about 95% within two. For our example that's 25.7 ± 9.0, i.e. 16.7 to 34.7, which contains 6 of the 10 values. That's about right for such a small, fairly flat set.
Don't confuse the standard deviation with the standard error, SE = s / √n = 9.007 / √10 = 2.85. The standard deviation describes the spread of individual values. The standard error describes how precisely you know the mean. It gets smaller as you collect more data; the standard deviation doesn't.
Common mistakes
- Forgetting to square the deviations, or forgetting to square-root at the end (then you've got the variance).
- Using n when the data is a sample, or n − 1 when your textbook wants population.
- Rounding the mean too early. Rounding 25.7 to 26 here would change the answer.
- Leaving out a value, or including a total row by accident when pasting from a spreadsheet.