Skip to content
Hands-on Mentor
ENTR
Back to blog

Standard deviation explained: how to calculate it step by step

Standard deviation shows how far values typically sit from the mean. Learn the formula, a worked example by hand, and when to divide by n or n - 1.

5 min read

Standard deviation is a number that tells you how far the values in a data set typically sit from the mean. A small standard deviation means the values are packed close to the mean. A large one means they are spread out. The mean answers "where is the center?" and the standard deviation answers "how far do values wander from it?"

Why is the mean not enough?

Bazaar, a fictional online store, ships parcels on two routes. Here are the delivery times in days for five parcels on each route:

ParcelRoute ARoute B
131
225
332
444
533
Mean33

Both routes average 3 days. Route A is steady. Route B can take 1 day or 5 days, so a customer on Route B has no idea what to expect. The mean cannot see this difference. The standard deviation can.

How do you calculate standard deviation?

Follow four steps. Here they are for Route A:

1. Find the mean: (3 + 2 + 3 + 4 + 3) / 5 = 3.

2. Subtract the mean from each value, then square the result.

3. Add the squares and divide by n - 1 (this is the variance).

4. Take the square root.

ValueDifference from meanSquared
300
2-11
300
411
300
Sum2

The variance is 2 / 4 = 0.5, and the square root is about 0.71. For Route B the squares add up to 10, the variance is 10 / 4 = 2.5, and the standard deviation is about 1.58. Route B is more than twice as spread out.

You square the differences because plain differences cancel out: the plus and minus values always add up to zero. You take the square root at the end to return to the original unit. The variance is in "days squared", which is hard to picture. The standard deviation is in days.

What is the standard deviation formula?

For a sample of n values with mean x̄:

s = √( Σ(x - x̄)² / (n - 1) )

The symbol Σ means "add up". This is exactly the four steps above in one line.

Population vs sample standard deviation: n or n - 1?

Use n - 1 when your data is a sample, which means a part of a larger group. Use n when you have every value you care about (the population).

The reason is that you measure differences from the sample's own mean, and values always sit a little closer to their own mean than to the true one. Dividing by n - 1 corrects that small bias. With large data sets the two results get close.

How do you check it in Python?

import numpy as np
import pandas as pd

route_a = [3, 2, 3, 4, 3]
route_b = [1, 5, 2, 4, 3]
print(np.mean(route_a), np.mean(route_b))
print(round(pd.Series(route_a).std(), 2), round(pd.Series(route_b).std(), 2))
print(round(np.std(route_a), 2), round(np.std(route_a, ddof=1), 2))
3.0 3.0
0.71 1.58
0.63 0.71

Line 2 matches the hand calculation. Line 3 shows a trap: NumPy divides by n by default (ddof=0) and pandas divides by n - 1 (ddof=1). The same data gives 0.63 or 0.71 depending on the library. If two tools disagree, check this first.

How do you read a standard deviation?

Here is a real check on the Bazaar data. The store completed 787 orders between January and June 2026. Their delivery times:

import numpy as np
import pandas as pd

counts = {1: 75, 2: 199, 3: 253, 4: 186, 5: 64, 6: 9, 7: 1}
days = pd.Series(np.repeat(list(counts), list(counts.values())))
print(len(days), round(days.mean(), 2), round(days.std(), 2))
within_1 = ((days - days.mean()).abs() <= days.std()).mean()
within_2 = ((days - days.mean()).abs() <= 2 * days.std()).mean()
print(round(within_1 * 100, 1), round(within_2 * 100, 1))
787 2.99 1.15
81.1 98.7

A typical order arrives about 1.15 days away from the 2.99-day average. Some practical points:

  • The unit is the unit of the data. "The standard deviation is 1.15 days" makes sense.
  • Size depends on the mean. A standard deviation of 1.15 is large for an average of 3 days and tiny for an average of 300 days. Divide by the mean to compare: Route A gives 0.71 / 3, about 24%.
  • Outliers push it up. Squaring makes one extreme value count a lot. For data with extreme values, the [IQR method](/blog/outliers-iqr-method) is more robust.
  • For bell-shaped data, about 68% of values fall within 1 standard deviation and about 95% within 2. Here 81.1% fall within 1 because delivery times are whole days, so the counts jump in big steps. The full rule is in [normal distribution and the 68-95-99.7 rule](/blog/normal-distribution).

Common mistakes

  • Forgetting to square the differences. The result is always zero.
  • Mixing up variance and standard deviation. The variance has not had the square root taken, so its unit is different.
  • Ignoring the ddof difference. NumPy and pandas use different defaults.
  • Reporting a standard deviation without the mean. Spread only makes sense next to the center.

What to read next

Practice spread measures on the Bazaar orders in the lesson [Range and standard deviation](/learn/statistics-data-analysis/range-standard-deviation). Start with the center in [mean, median, mode](/blog/mean-median-mode), or see the whole course on the [Statistics and Data Analysis page](/courses/statistics-data-analysis) (44 lessons, free).

  • #statistics
  • #standard deviation
  • #spread
  • #variance
All posts