Skip to content
7 min read

How to Calculate Standard Deviation: 5 Steps with a Worked Example

Standard deviation tells you how far the values in a set typically sit from their mean. A small standard deviation means the values bunch together; a large one means they are spread out.

The short version

  1. Find the mean.
  2. Subtract the mean from each value.
  3. Square each of those differences and add them up.
  4. Divide by n−1n - 1 for a sample, or by NN if you have the whole population. This is the variance.
  5. Take the square root. That is the standard deviation.

The calculator above is loaded with the example worked through below. Replace the numbers with your own, or switch between sample and population.

Worked example: eight days of temperatures

Suppose you recorded the midday temperature, in °C, on 8 days:

23,  25,  28,  22,  26,  24,  27,  2123, \; 25, \; 28, \; 22, \; 26, \; 24, \; 27, \; 21
20212223242526272829mean 24.5±1 s°C
Each dot is one day. The dashed line is the mean (24.5 °C) and the shaded band runs one standard deviation (2.45 °C) either side of it.

Step 1: Find the mean

Add the values and divide by how many there are:

∑xi=23+25+28+22+26+24+27+21=196xˉ=1968=24.5\begin{aligned} \textstyle\sum x_i &= 23 + 25 + 28 + 22 \\ &\quad + 26 + 24 + 27 + 21 = 196 \\ \bar{x} &= \frac{196}{8} = 24.5 \end{aligned}

Step 2: Subtract the mean from each value

Values below the mean give a negative difference, values above it a positive one. The differences always add up to zero, which is why the next step squares them.

valuebelow mean ← → above mean23-1.525+0.528+3.522-2.526+1.524-0.527+2.521-3.5
Each day's difference from the mean of 24.5 °C.

Step 3: Square the differences and add them

xix_ixi−xˉx_i - \bar{x}(xi−xˉ)2(x_i - \bar{x})^2
23-1.52.25
250.50.25
283.512.25
22-2.56.25
261.52.25
24-0.50.25
272.56.25
21-3.512.25
Sum42

Step 4: Divide by n − 1 to get the variance

These 8 days are a sample of the weather, not every day there will ever be, so divide by n−1=7n - 1 = 7:

s2=427=6s^2 = \frac{42}{7} = 6

Step 5: Take the square root

s=6≈2.449s = \sqrt{6} \approx 2.449

The sample standard deviation is about 2.45 °C.

What the answer means

A standard deviation of 2.45 °C says a typical day was a couple of degrees away from the mean of 24.5 °C. It is not exactly the average distance from the mean (that would be the mean absolute deviation), because squaring gives the far-out days more weight.

For data that roughly follows a bell curve, about 68% of values fall within one standard deviation of the mean and about 95% within two. In this small set, 4 of the 8 days fall between 22.05 and 26.95 °C; a handful of values rarely matches the rule closely. To see where one value sits, turn it into a z-score: how many standard deviations it is from the mean.

17181920212223242526272829303132mean 24.5Set A: s = 1.0517181920212223242526272829303132mean 24.5Set B: s = 4.68
Both sets have a mean of 24.5. Set A's values sit close to it, so its standard deviation is 1.05; set B's are spread out, so its standard deviation is 4.68.

Sample or population: which formula?

Both formulas follow the same five steps. The only difference is what you divide by in step 4.

s=∑(xi−xˉ)2n−1s = \sqrt{\frac{\sum (x_i - \bar{x})^2}{n - 1}}σ=∑(xi−μ)2N\sigma = \sqrt{\frac{\sum (x_i - \mu)^2}{N}}
  • Sample (ss), divide by n−1n - 1: your data is part of a bigger group, such as 100 customers out of 10,000, or a week of readings. This is the usual case in coursework and research.
  • Population (σ\sigma), divide by NN: your data is the entire group you care about, such as the marks of every student in one class.

Dividing by n−1n - 1 (Bessel's correction) makes up for the fact that a sample's values sit closer to their own mean than to the true population mean. If the eight temperatures above were the whole population:

σ=428=5.25≈2.291\sigma = \sqrt{\frac{42}{8}} = \sqrt{5.25} \approx 2.291

For the same numbers the population figure (2.29) is always a little smaller than the sample figure (2.45), unless every value is identical and both are zero. The gap shrinks as the data set grows.

On a calculator or in a spreadsheet

  • Excel and Google Sheets: =STDEV.S(A1:A8) for a sample, =STDEV.P(A1:A8) for a population. The older STDEV is the sample version.
  • Scientific and graphing calculators: in statistics mode, sxs_x (shown as Sx on some models) is the sample standard deviation and σx\sigma_x is the population one.

Common mistakes

  1. Dividing by the wrong number. Use n−1n - 1 for a sample and NN for a whole population.
  2. Stopping at the variance. The variance (6 here) is in squared units, °C². Take the square root to get back to °C.
  3. Rounding the mean too early. Keep full precision until the last step; a rounded mean throws every difference off.
  4. Mixing it up with the standard error. The standard error, s/ns / \sqrt{n}, measures how precisely you know the mean, not how spread out the data is.

Related calculators and guides

Related Articles