How to Calculate Standard Deviation Step by
step.
Population and sample standard deviation worked by hand, why the sample formula divides by n − 1, how to read the number you get, and when the 68-95-99.7 rule applies.
Statistics & ProbabilityBy Anil ShahPublished Updated 7 min read
Standard deviation measures how far values typically sit from their mean. Two sets of numbers can share the same average and still behave very differently: a commute that takes 28 minutes every day is not the same as one that averages 28 minutes but swings between 22 and 35. Standard deviation puts a number on that difference. This guide works through the calculation by hand, explains why there are two versions of the formula, and shows how to read the result.
The idea in one sentence
Find how far each value is from the mean, square those distances so negatives do not cancel positives, average the squares, and take the square root to get back to the original units. The average of the squared distances is the variance; its square root is the standard deviation. Variance is in squared units (minutes squared), which is hard to picture, so the standard deviation is the number people usually report.
Population versus sample
There are two formulas, and choosing the right one depends on what your data represents.
Population: σ = √[ Σ(x − μ)² ÷ N ]
Sample: s = √[ Σ(x − x̄)² ÷ (n − 1) ]
Use the population formula when your data contains every member of the group you care about: the final grades of all 30 students in one class, if that class is the only thing you want to describe. Use the sample formula when your data is a subset used to estimate the spread of a larger group: 30 students surveyed to learn about a whole school, or eight days of commute times used to describe a typical day. In practice most real data is a sample, so the sample formula is the usual default.
Why divide by n − 1?
The sample formula measures distances from the sample mean x̄, not from the true population mean μ, which you do not know. The sample mean is, by construction, the point that makes the sum of squared distances as small as possible for that particular sample. So distances measured from it are slightly too small on average, and dividing by n would underestimate the population variance. Dividing by n − 1 instead (Bessel's correction) removes that bias from the variance. Another way to see it: once you know the mean and n − 1 of the deviations, the last deviation is fixed, because deviations always sum to zero. Only n − 1 of them are free to vary, so the sample has n − 1 degrees of freedom.
The correction matters most for small samples. With 5 values, dividing by 4 instead of 5 raises the variance by 25%. With 1,000 values the difference is about 0.1%.
Step by step: a worked example
One commuter records their travel time on 8 working days: 22, 28, 31, 25, 35, 27, 30, 26 minutes. We want the sample standard deviation, because these days stand in for all of their commutes.
Step 1: find the mean
Add the values and divide by the count: 224 ÷ 8 = 28 minutes.
Step 2: find each deviation and square it
| Value x | Deviation x − x̄ | Squared deviation |
|---|---|---|
| 22 | −6 | 36 |
| 28 | 0 | 0 |
| 31 | 3 | 9 |
| 25 | −3 | 9 |
| 35 | 7 | 49 |
| 27 | −1 | 1 |
| 30 | 2 | 4 |
| 26 | −2 | 4 |
| Sum 224 | 0 | 112 |
The deviations add up to zero, as they always do. That is a useful check on your arithmetic, and it is also why we square them: the plain average deviation would always be zero.
Step 3: divide the sum of squares
The sum of squared deviations is 112. For the sample variance, divide by n − 1 = 7: s² = 112 ÷ 7 = 16. For the population variance you would divide by n = 8: σ² = 112 ÷ 8 = 14.
Step 4: take the square root
Sample standard deviation: s = √16 = 4 minutes. Population standard deviation: σ = √14 = 3.742 minutes. The standard deviation calculator shows both results and this full table for any list you paste in, and the variance calculator stops at step 3.
A shortcut formula, and why to be careful with it
The sum of squares can also be computed without finding each deviation:
Σ(x − x̄)² = Σx² − (Σx)² ÷ n
For the commute data, Σx² = 6,384 and (Σx)² ÷ n = 50,176 ÷ 8 = 6,272, so the sum of squares is 112, the same as before. It is quicker on paper, but on a computer it subtracts two large, nearly equal numbers, which loses precision when the values are large and the spread is small. Statistical software uses the two-pass method from the steps above or an updating algorithm such as Welford's for that reason.
When the data comes as a frequency table
Survey results often arrive as counts: how many people gave each answer. Multiply each squared deviation by its frequency f instead of writing every value out. Suppose 40 people reported how many books they read last month:
| Books x | People f | f × x | f × (x − x̄)² |
|---|---|---|---|
| 0 | 6 | 0 | 19.44 |
| 1 | 11 | 11 | 7.04 |
| 2 | 12 | 24 | 0.48 |
| 3 | 7 | 21 | 10.08 |
| 4 | 4 | 16 | 19.36 |
| Total | 40 | 72 | 56.4 |
The mean is Σfx ÷ Σf = 72 ÷ 40 = 1.8 books. The sample variance is 56.4 ÷ (40 − 1) = 1.4462, and the sample standard deviation is 1.203 books. The frequency distribution calculator builds this kind of table from raw data.
Reading the number
The standard deviation is in the same units as the data, so you can read it directly: on a typical day this commute is about 4 minutes away from its 28-minute average. Compare a commuter whose times were 27, 28, 29, 28, 27, 29, 28, 28. The mean is again 28 minutes, but the standard deviation is only 0.76 minutes. The averages match; the reliability does not.
z-scores
A z-score says how many standard deviations a value is from the mean: z = (x − x̄) ÷ s. A 36-minute commute has z = (36 − 28) ÷ 4 = 2, so it is 2 standard deviations slower than average. z-scores let you compare values measured on different scales, such as a test score and a race time. The z-score calculator converts between values, z-scores and percentiles.
Coefficient of variation
To compare spread between data sets with very different means, divide the standard deviation by the mean. For the commute data the coefficient of variation is 4 ÷ 28 = 14.3%. It only makes sense for data measured on a scale with a true zero, such as time, weight or money.
Things standard deviation does not tell you
- Shape. A symmetric set and a heavily skewed set can have the same standard deviation. Plot the data, or look at the median and quartiles with the mean, median and mode calculator and the box plot calculator.
- Robustness. Because deviations are squared, one extreme value can inflate the standard deviation a lot. If the data has outliers, the interquartile range is often a better summary of spread.
- Precision of the mean. The standard deviation describes individual values. The uncertainty of the mean itself is the standard error, s ÷ √n, which shrinks as the sample grows.
The 68-95-99.7 rule
When data follows a normal distribution (the bell curve), the standard deviation tells you what share of values fall within a given distance of the mean. This is the empirical rule:
| Within | Normal distribution | Any distribution (Chebyshev, at least) |
|---|---|---|
| ±1 standard deviation | 68.27% | No guarantee |
| ±2 standard deviations | 95.45% | 75.0% |
| ±3 standard deviations | 99.73% | 88.9% |
So about 68% of values fall within one standard deviation of the mean, about 95% within two, and about 99.7% within three. Only about one value in 370 falls more than three standard deviations from the mean, which is why that distance is a common flag for an unusual observation. The normal distribution calculator gives the exact share between any two values.
The rule holds only for data that is close to normal. Heights of adults of one sex, measurement errors and many test scores are roughly normal; incomes, house prices and waiting times are usually skewed, and the 68-95-99.7 figures can be badly off for them. Chebyshev's inequality, in the last column, gives a floor that holds for any distribution: at least 75% of values lie within two standard deviations and at least 88.9% within three. Eight commute times are too few to judge whether the data is normal, so for the worked example the safe statement is Chebyshev's: at least 75% of commutes should fall within 20 to 36 minutes.
In spreadsheets and code
Software uses both formulas, and the defaults differ, so check which one you are getting.
| Tool | Sample (n − 1) | Population (n) |
|---|---|---|
| Excel | STDEV.S | STDEV.P |
| Google Sheets | STDEV | STDEVP |
| Python statistics module | stdev | pstdev |
| NumPy | np.std(x, ddof=1) | np.std(x) (the default) |
| R | sd(x) | No built-in; rescale sd(x) |
NumPy is the one that catches people out: its default is the population formula. For the commute data it would return 3.742 rather than 4.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods. Section 1.3.5.6, Measures of Scale, and Section 1.3.6.6.1, Normal Distribution. National Institute of Standards and Technology.
- Freedman D, Pisani R, Purves R. Statistics, 4th edition. W. W. Norton, 2007. Chapters 4 and 5 (the standard deviation and the normal approximation).
- Montgomery DC, Runger GC. Applied Statistics and Probability for Engineers, 7th edition. Wiley, 2018. Chapter 6 (sample variance and degrees of freedom).
- Welford BP. Note on a method for calculating corrected sums of squares and products. Technometrics, 1962; 4(3): 419-420.
- Microsoft Support. STDEV.S and STDEV.P function reference. NumPy documentation, numpy.std (ddof parameter). Python documentation, statistics module.