How to Calculate Standard Deviation: Formula and Steps

By Dr. Zubair Khalid, DVM, MS, PhD ·

How to Calculate Standard Deviation: Formula and Steps

To compute the standard deviation, subtract the mean from each value, square the differences, average them, and take the square root. The only real decision is the denominator: use $n$ for a population and $n - 1$ for a sample. This guide gives you both formulas and a full worked example.

Quick Answer

  • The standard deviation measures how far values typically sit from their mean [n:1].
  • Population formula: $\sigma = \sqrt{\frac{\sum (x - \mu)^2}{N}}$.
  • Sample formula: $s = \sqrt{\frac{\sum (x - \bar{x})^2}{n - 1}}$.
  • The steps are identical except for the denominator, so the sample result is always slightly larger [n:2].
  • A small standard deviation means values cluster near the mean, and a large one means they spread out [n:3].

What Is Standard Deviation and How Do You Calculate It?

To calculate standard deviation, find the mean, subtract it from every value, square each difference, average the squared differences, then take the square root. Use the population formula (divide by N) when your data is the whole group, and the sample formula (divide by n - 1) when your data is a subset used to estimate a larger group.

The result is a single number in the same units as your data. If you measured weights in kilograms, the standard deviation is in kilograms. It tells you how far values typically sit from the mean, so a small number means the data cluster tightly and a large number means they spread out.

The formula in one line, ready to copy into a spreadsheet or notes:

SD = √( Σ(x - mean)² / N ) for a population, or SD = √( Σ(x - mean)² / (n - 1) ) for a sample.

Here Σ means "add up all of these," x is each value, and N or n is how many values you have.

The steps, in order:

  1. Count your values (n).
  2. Add them and divide by n to get the mean.
  3. Subtract the mean from each value.
  4. Square each of those differences.
  5. Add the squared differences.
  6. Divide by N (population) or n - 1 (sample).
  7. Take the square root.

Steps 1 through 5 never change. Only step 6 depends on whether you have a population or a sample, and that single choice is where most errors happen. If your five numbers are the entire group you care about, divide by 5. If they are a sample drawn from something bigger, divide by 4.

A quick sanity check: the deviations in step 3 always add to zero, so if they do not, you have made an arithmetic slip. Also, the standard deviation can never be negative, because you square before you take the root.

The Formula

For a population, the standard deviation is:

$$\sigma = \sqrt{\frac{\sum_{i=1}^{N}(x_i - \mu)^2}{N}}$$

For a sample, it is:

$$s = \sqrt{\frac{\sum_{i=1}^{n}(x_i - \bar{x})^2}{n - 1}}$$

Each symbol means the same thing in both:

SymbolMeaning
$x_i$Each individual data value
$\mu$ or $\bar{x}$The mean of the data
$x_i - \mu$The deviation of a value from the mean
$(x_i - \mu)^2$The squared deviation
$\sum$Sum of all the squared deviations
$N$ or $n$The number of values
$\sigma$ or $s$The standard deviation

The numerator, the sum of squared deviations, is often abbreviated SS. The quantity under the square root is the variance, so the standard deviation is simply the square root of the variance [n:2]. If you want to see how that intermediate value is built, the guide on how to calculate variance covers it in detail.

The difference between the two formulas is the denominator. Dividing by $n - 1$ instead of $n$ corrects a bias that appears when you estimate a population spread from a sample. This adjustment is known as Bessel's correction [n:5].

How to Calculate It Step by Step

  1. Count your values. Find $n$, the number of data points.
  2. Find the mean. Add every value and divide by $n$.
  3. Subtract the mean from each value. These are the deviations.
  4. Square each deviation. Squaring removes the signs so positive and negative gaps do not cancel.
  5. Add the squared deviations. This gives SS.
  6. Divide. Use $n$ for a population or $n - 1$ for a sample.
  7. Take the square root. The result is the standard deviation.

Steps 1 through 5 are the same for both formulas. Only step 6 changes [n:2].

Worked Example

Suppose you recorded five reaction time measurements in milliseconds: 210, 225, 198, 240, and 217.

ValueDeviation ($x - \bar{x}$)Squared deviation
210-8.000064.0000
2257.000049.0000
198-20.0000400.0000
24022.0000484.0000
217-1.00001.0000

Step 1. Count the values. $n = 5$.

Step 2. Find the mean.

$$(210 + 225 + 198 + 240 + 217) / 5 = 218.0000$$

Step 3. Subtract the mean from each value. The deviations are -8.0000, 7.0000, -20.0000, 22.0000, and -1.0000. They sum to zero, which is a useful check.

Step 4. Square each deviation. You get 64.0000, 49.0000, 400.0000, 484.0000, and 1.0000.

Step 5. Add the squared deviations.

$$64.0000 + 49.0000 + 400.0000 + 484.0000 + 1.0000 = 998.0000$$

Step 6a. Population variance. Divide by $n = 5$.

$$998.0000 / 5 = 199.6000$$

Step 7a. Population standard deviation.

$$\sqrt{199.6000} = 14.1280$$

Step 6b. Sample variance. Divide by $n - 1 = 4$.

$$998.0000 / 4 = 249.5000$$

Step 7b. Sample standard deviation.

$$\sqrt{249.5000} = 15.7956$$

So the population standard deviation is 14.1280 ms and the sample standard deviation is 15.7956 ms. The sample value is larger because dividing by 4 instead of 5 produces a bigger variance before the square root.

How to Interpret the Result

The standard deviation is expressed in the same units as your data, so 14.1280 ms is a time, not a squared time. That makes it easier to read than variance, which is in squared units.

A value of 14.1280 ms means a typical reaction time in this set sits roughly 14 ms away from the 218 ms mean. A small standard deviation means the values cluster tightly around the mean, and a large one means they are spread over a wider range [n:3].

If the data follow a normal distribution, about 68% of values fall within one standard deviation of the mean, about 95% within two, and about 99.7% within three [n:3]. For the reaction times, that would put roughly two thirds of measurements between about 204 ms and 232 ms.

One caution: the standard deviation of your data is not the same as the standard error of the mean. The standard error describes how much a sample mean would vary across repeated samples, and it equals the population standard deviation divided by the square root of the sample size [n:1]. The comparison in standard deviation vs variance vs standard error explains when to report each one.

Doing It in Software

Spreadsheets and programming languages handle the arithmetic for you, but you still have to pick the right function. In Excel, STDEV.P returns the population standard deviation and STDEV.S returns the sample standard deviation. The walkthrough in how to calculate standard deviation in Excel shows both with a real sheet.

In Python, the statistics module gives you the same split.

import statistics
data = [210, 225, 198, 240, 217]
mean = statistics.mean(data)
pop_sd = statistics.pstdev(data)
samp_sd = statistics.stdev(data)
print(f"pop_sd = {pop_sd:.4f}, samp_sd = {samp_sd:.4f}")
Output:
pop_sd = 14.1280, samp_sd = 15.7956

The two functions match the hand calculation exactly. If you would rather skip the code, the Standard Deviation Calculator takes a list of values and returns both figures.

Common Mistakes

  • Using $n$ when you have a sample. This understates the spread. Use $n - 1$ whenever your data is a sample drawn from a larger group [n:2].
  • Forgetting to square the deviations. Unsquared deviations sum to zero, so the calculation collapses. Square each one before adding.
  • Taking the square root too early. The square root comes last, after dividing by $n$ or $n - 1$.
  • Mixing up variance and standard deviation. Variance is the value under the square root. Standard deviation is its square root, in the original units.
  • Confusing standard deviation with standard error. They measure different things, and the standard error shrinks as sample size grows [n:1].
  • Applying it to the wrong data type. Standard deviation is meaningless for nominal data such as country or biological sex, and it should not be used with ordinal data [n:4].

Limitations

The standard deviation assumes your data have a meaningful numeric scale and a center worth measuring. For skewed data or data with extreme outliers, a single value can be misleading because one large observation inflates the result. In those cases the interquartile range often describes the spread better [n:4].

It also says nothing about the shape of the distribution. Two datasets can share the same mean and standard deviation while looking completely different. Treat it as one summary of spread, not a full description of your data.

Worked Examples You Can Follow Line by Line

A small sample by hand

Suppose a veterinarian records the resting heart rates, in beats per minute, of six dogs in a clinic: 90, 104, 98, 112, 86, 110. These six are a sample from the clinic's wider patient population, so use n - 1.

The mean is (90 + 104 + 98 + 112 + 86 + 110) / 6 = 600 / 6 = 100.

Now subtract 100 from each value: -10, 4, -2, 12, -14, 10. They sum to zero, which confirms the mean is right.

Square each: 100, 16, 4, 144, 196, 100. The sum is 560.

Divide by n - 1 = 5: 560 / 5 = 112. That is the sample variance.

Take the square root: √112 ≈ 10.58 beats per minute.

So a typical dog in this group sits about 10.6 beats per minute from the 100 bpm mean. If you had treated the six dogs as a full population and divided by 6, you would get 560 / 6 ≈ 93.33, and √93.33 ≈ 9.66, a smaller figure. That gap is the whole point of Bessel's correction.

Working backward from a summary

Sometimes you are handed the sum of squared deviations rather than the raw values. If a dataset of 25 measurements has a sum of squared deviations of 600 and is a sample, the variance is 600 / 24 = 25, and the standard deviation is √25 = 5. You never need the individual values once you have that sum and the count.

A frequency table

When values repeat, weight each squared deviation by how often it occurs. Take scores of 2, 2, 4, 5, 5, 5. The mean is (2+2+4+5+5+5)/6 = 23/6 ≈ 3.833. The squared deviations are about 3.361 (for each 2), 0.028 (for the 4), and 1.361 (for each 5). Weighted: 2 × 3.361 + 1 × 0.028 + 3 × 1.361 ≈ 6.722 + 0.028 + 4.083 = 10.833. Divide by n - 1 = 5 to get about 2.167, and the square root is about 1.47.

Reading the Formula Without Getting Lost

What each symbol is doing

The subtraction inside the parentheses measures a gap. The squaring makes every gap positive and gives bigger gaps more weight. The summation collects all those weighted gaps. The division turns the total into an average gap, and the square root returns the answer to the original units. Read it in that order and the formula stops looking like a wall of symbols.

Why squaring instead of absolute values

You could average the absolute gaps instead, and that gives a real measure called mean absolute deviation. Standard deviation is preferred in most statistics because squared deviations behave well in algebra and connect directly to variance, which underpins tests, confidence intervals, and regression. The trade-off is that squaring makes outliers count heavily, so one extreme value can pull the standard deviation up sharply.

Population versus sample, in plain terms

Picture a jar of marbles. If you tip out every marble and measure them all, that is a population and you divide by N. If you scoop a handful and use it to guess about the whole jar, that is a sample and you divide by n - 1. The correction exists because a handful tends to miss the extremes of the jar, so its spread runs slightly low. Dividing by a smaller number nudges the estimate back up.

Mistakes, Misconceptions, and Edge Cases

The denominator is not a style choice

The most common error is dividing by n out of habit when the data are a sample. This systematically understates spread. Ask one question before you start: does this data include every member of the group I am describing? If yes, use N. If no, use n - 1.

Standard deviation is not a range

A standard deviation of 10 does not mean the values span 10 units. It describes a typical distance from the mean. The full range can be much wider, and with skewed data a few values may sit many standard deviations out.

Zero and near-zero results

A standard deviation of exactly zero means every value is identical. This is not an error. A very small value means the data barely vary, which is legitimate for tightly controlled measurements but suspicious if you expected real variation.

Units and scale

Because the result carries the original units, you can compare standard deviations only when the units match. To compare spread across different scales, such as weight in kilograms against height in centimetres, use the coefficient of variation, which is the standard deviation divided by the mean.

Small samples are unstable

With only two or three values, the standard deviation swings wildly and is a poor guide to spread. It becomes more reliable as the count grows. Report the count alongside the figure so readers can judge how much to trust it.

When spread is better described another way

For heavily skewed data or data with outliers, the interquartile range often tells a truer story because it ignores the extreme tails. Standard deviation remains the right summary when the data are roughly symmetric and you want a measure that uses every value.

Frequently Asked Questions

How can I find standard deviation if I only have the mean and one value?

You cannot. The standard deviation depends on how far every value sits from the mean, so you need the full set of observations or a summary that already includes the spread, such as the sum of squared deviations.

Should I use the population or sample formula?

Use the population formula when your data include every member of the group you care about. Use the sample formula when your data are a subset used to estimate a larger population [n:2]. In practice, most research data are samples.

Why is the sample standard deviation always larger?

Dividing by $n - 1$ instead of $n$ makes the denominator smaller, so the variance is larger before you take the square root. This correction accounts for the fact that a sample tends to underestimate the true spread of the population [n:5].

Can the standard deviation be zero?

Yes. If every value in the dataset is identical, each deviation is zero, the sum of squared deviations is zero, and the standard deviation is zero. A value close to zero means the data points sit very close to the mean [n:3].

How do I figure out standard deviation from a frequency table?

Multiply each squared deviation by its frequency, add those products to get the sum of squared deviations, then divide by the total count and take the square root. The steps are the same, but each deviation is weighted by how often it occurs.

References

This article draws on the standard references listed under Further Reading.

Further Reading

Related Articles

Related articles