Math Explained

Home › Probability & Statistics

How Standard Deviation Is Calculated, Step by Step

Learn how standard deviation measures spread, why deviations are squared, when to divide by n or n-1, and how to compute it on a small dataset.

2026-10-19 · 5 min read

Standard deviation tells you how far values typically sit from the average of a dataset. A small standard deviation means the values cluster tightly around the mean. A large one means they spread widely. It is the most common measure of spread, and it appears in nearly every report that uses averages, from test scores to laboratory measurements.

This guide builds the formula from the idea up, works one dataset from start to finish, and explains the one choice that confuses most learners: dividing by n or by n minus 1.

Start with deviations from the mean

To measure spread, first find the center. Take the mean, which is the sum of all values divided by the count. Then measure how far each value sits from that mean. The difference between a value and the mean is called its deviation. A value above the mean has a positive deviation, and a value below has a negative one.

If you simply average the deviations, they always cancel to zero. The positive and negative values balance exactly, so that average says nothing about spread. This is why the method needs one more step before averaging.

Square the deviations

Squaring each deviation removes the negative signs, so every deviation contributes positively to the total spread. Squaring also gives large deviations more weight than small ones. A value that sits 4 units from the mean adds 16 to the total, while a value 1 unit away adds only 1. This emphasis on large deviations is a deliberate property, and it connects to the normal distribution and to least-squares fitting.

The average of the squared deviations is called the variance. Variance is useful in theory, but its units are the square of the original units. If the data is in centimeters, the variance is in square centimeters, which is hard to interpret directly.

Take the square root

The standard deviation is the square root of the variance. Taking the square root returns the measure to the original units. A standard deviation of 2 centimeters means a typical value differs from the mean by about 2 centimeters.

A worked example

Consider the dataset 2, 4, 4, 4, 5, 5, 7, 9. It has eight values. The sum is 40, so the mean is 40 divided by 8, which equals 5. The table below shows each step.

Value Deviation from 5 Squared deviation
2 -3 9
4 -1 1
4 -1 1
4 -1 1
5 0 0
5 0 0
7 2 4
9 4 16

The squared deviations sum to 32. If this dataset is the whole population, divide by n, which is 8. The population variance is 32 divided by 8, which equals 4. The population standard deviation is the square root of 4, which equals 2.

Checking the deviations column confirms the mean. The positive deviations (2 + 4 = 6) equal the negative deviations (3 + 1 + 1 + 1 = 6), so they cancel, exactly as expected for a correct mean.

Population versus sample: why n minus 1

Most real data is a sample, not the whole population. A sample tends to sit closer to its own mean than the true population mean, because the sample mean is calculated from the same values. That tendency makes the sum of squared deviations too small on average. The fix is to divide by n minus 1 instead of n. This correction is called Bessel's correction.

Using the same dataset as a sample, the sum of squared deviations is still 32, but now you divide by 7. The sample variance is 32 divided by 7, which is about 4.57. The sample standard deviation is the square root of that, about 2.14.

The table summarizes the two versions for the example dataset.

Version Divide by Variance Standard deviation
Population n = 8 4.00 2.00
Sample n - 1 = 7 4.57 2.14

The sample version is larger because it corrects for the bias. The gap shrinks as n grows. With a sample of 1,000 values, dividing by 999 instead of 1,000 changes almost nothing. With 8 values, the difference is clearly visible.

Reading the result

Standard deviation becomes most useful when you pair it with a shape. For a roughly bell-shaped dataset, about 68 percent of values fall within one standard deviation of the mean, about 95 percent fall within two, and about 99.7 percent fall within three. This is the 68-95-99.7 rule, and it applies to normal distributions.

For skewed data the rule fails. Income and house prices are heavily skewed, so a standard deviation alone can mislead. In those cases, report the median and the interquartile range alongside the mean and standard deviation.

Two values with the same mean

Two classes can both average 70 on a test and still differ sharply. One class might score tightly between 65 and 75, while the other scores anywhere from 30 to 100. The means match, but the standard deviations reveal that the second class is far more varied. The mean says where the center is, and the standard deviation says how much to trust that center as a summary.

Common mistakes

The most frequent error is treating the mean absolute deviation as the standard deviation. Mean absolute deviation takes the absolute value of each deviation instead of squaring it. It is a valid measure of spread, but it is a different number, and it does not connect to the normal distribution in the same clean way.

A second mistake is forgetting the final square root. Reporting the variance as if it were the standard deviation overstates the spread in the units you care about. Always check whether your number is in the original units.

A third mistake is mixing the population and sample formulas inside one report. Choose the version that matches your data, and state which one you used.

Key takeaways

Standard deviation measures how far values typically sit from the mean. You compute it by finding the mean, subtracting it from each value, squaring the differences, averaging them, and taking the square root.

Divide by n when you have the full population and by n minus 1 when you have a sample. Pair the number with the shape of the data, because the usual interpretation only holds when the distribution is roughly symmetric and bell-shaped.

More in Probability & Statistics

Stats

How the Central Limit Theorem Works

Learn why sample averages tend toward a bell curve even when the raw data is skewed, with the logic, the standard error rule, and worked examples.

5 min read