math.wiki
Statistics › Center and spread › Standard deviation › Computing a standard deviation, sample and population
Open on the map
Algebra 1 · S.ID.A.2

Computing a standard deviation, sample and population

The variance measures spread in squared units. How do you get a spread in the data’s own units, and does it matter whether the numbers are the whole group or only a sample of it?

Where you are 3 in Standard deviation

When you reach for it

You have a list of numbers and want one number for how far they typically sit from their mean, in the data’s own unit: pages, years, hours. The variance is the mean of the squared deviations, but it is in squared units. Its square root, the standard deviation (Standard deviation), is back in the data’s unit, and it is the measure of spread used throughout statistics.

There are two versions. When the numbers are the whole group you care about, a population, divide the sum of the squared deviations by the count, as the variance lesson did. When the numbers are a sample standing in for a bigger group, divide by one less than the count. This lesson runs over two days: Day 1 is the population standard deviation, Day 2 the sample one and how to choose between them.

The procedure

Day 1: the population standard deviation

For a whole population of N values, the mean is written \mu (mu) and the standard deviation \sigma (sigma). Greek letters mark numbers that describe a whole population, as Parameters and statistics explains. The standard deviation is the square root of the variance:

\sigma = \sqrt{\frac{\sum (x - \mu)^2}{N}}

Read it from the inside out. x - \mu is one value’s deviation from the mean. Squaring removes its sign. \sum, a capital sigma, means “add this up over every value”. Dividing by N gives the variance \sigma^2, and the square root brings the unit back.

A table with three columns, value, deviation and squared deviation, keeps the work in order, and its middle column carries a free check: the deviations always add to 0. Keep the mean exact and round only the final answer. A rounded mean makes every deviation slightly wrong, and Example 2 shows the answer drifting.

When values repeat, a frequency table lists each different value once with its count f. A value that appears f times contributes its squared deviation f times, so multiply each squared deviation by its count before adding. Then divide by N, the total of the counts, not by the number of rows.

Two facts check that an answer is sensible:

  • \sigma is never larger than the largest distance from the mean. Call that distance D. Every squared deviation is at most D^2, so their mean is at most D^2 and its square root is at most D. It equals D only when every value is exactly D from the mean.
  • \sigma is never negative, and \sigma = 0 exactly when all the values are equal. A sum of squares is 0 only when every square is 0, that is, when every value equals the mean.

Day 2: the sample standard deviation

Often the group of interest is too big to measure, or measuring uses it up: finding a torch’s battery life means running it flat. Then a sample is measured instead. Its mean is written \bar{x}, its standard deviation s, and its size n. The table is the same; only the divisor changes:

s = \sqrt{\frac{\text{sum of squared deviations from } \bar{x}}{n - 1}}

Why one less. The aim is the spread of the whole group, measured from the group’s mean \mu, which nobody knows. The deviations are taken from \bar{x} instead, and \bar{x} is worked out from the sample itself, so it sits right in the middle of the sample: no other number has a smaller sum of squared distances to those values. The true mean \mu is almost always a little off from \bar{x}, and squared distances measured from it would add to more. So deviations from the sample’s own mean come out a little small on average, and dividing by n - 1 instead of n makes the result a little bigger to make up for it. Example 5 shows this in numbers. Why n - 1 is exactly the right amount is taken up later, in Bias and variability of an estimator.

For the same numbers, then, s is a little larger than the figure from dividing by n. Dividing the same sum by n - 1 instead of n multiplies the variance by \displaystyle \frac{n}{n - 1}, so s is \displaystyle \sqrt{\frac{n}{n - 1}} times the divide-by-n figure. For n = 2 that factor is \displaystyle \sqrt{2} \approx 1.41, for n = 10 about 1.05, and for n = 100 about 1.005. The gap shrinks as the sample grows.

Which one to use depends on the question, not on the numbers. If the values are every member of the group you want to describe, they are a population: use \sigma and divide by N. If they stand in for a bigger group you want to learn about, they are a sample: use s and divide by n - 1. The same five numbers can be either (Example 6).

Calculators and spreadsheets have both. A calculator in statistics mode usually shows a population standard deviation (often labeled \sigma_x) and a sample one (often s_x). A spreadsheet has STDEV.P for a population and STDEV.S for a sample. They are the two formulas above, so a hand computation and the machine agree once the right one is picked.

Worked examples

Example 1

Day 1: the page counts of a whole series

A fantasy series has seven books. Their page counts, sorted from shortest, are 320, 352, 368, 400, 416, 448, 496 (made-up data). Find the standard deviation of the page counts.

Solution

The seven books are the whole series, so they are a population. The mean is \displaystyle \mu = \frac{2800}{7} = 400 pages.

pages xdeviation x - 400squared deviation
320-806400
352-482304
368-321024
40000
41616256
448482304
496969216
sum021504

The deviations add to 0, which checks the mean. The variance is \displaystyle \sigma^2 = \frac{21504}{7} = 3072 square pages, and the standard deviation is

\sigma = \sqrt{3072} \approx 55.4 \text{ pages}

Figure 1 shows it is sensible. The distances from the mean run from 0 to 96 pages, and 55.4 is no larger than 96. The two books furthest out, 320 and 496, supply 15616 of the 21504, because squaring weighs large distances heavily.

mean 400 deviation −80 −48 −32 0 16 48 96 σ ≈ 55.4 300 350 400 450 500 pages in a book
Figure 1Each segment is one book’s distance from the mean. The standard deviation, about 55.4 pages, is a typical distance, never longer than the longest segment, 96.
Example 2

Day 1: a mean that is not a whole number

Anatol has five cats, aged 2, 5, 6, 8 and 11 years (made-up data). Find the standard deviation of their ages, then see what happens if the mean is rounded first.

Solution

The five cats are all of Anatol’s cats, the whole group being described, so they are a population. The mean is \displaystyle \mu = \frac{32}{5} = 6.4 years, kept exact.

age xdeviation x - 6.4squared deviation
2-4.419.36
5-1.41.96
6-0.40.16
81.62.56
114.621.16
sum045.2

The variance is \displaystyle \sigma^2 = \frac{45.2}{5} = 9.04, so \displaystyle \sigma = \sqrt{9.04} \approx 3.01 years. Only this last step is rounded.

Suppose instead the mean had been rounded to 6 to make the table easier. The deviations become -4, -1, 0, 2, 5, which add to 2, not 0: a warning that something is off. Their squares 16, 1, 0, 4, 25 add to 46, giving \displaystyle \frac{46}{5} = 9.2 and \displaystyle \sqrt{9.2} \approx 3.03. The answer has drifted in the second decimal place. Squared distances measured from any number other than the mean add to more, so a rounded mean always pushes the answer up.

Example 3

Day 1: a frequency table

Every one of the 20 households on Alfhild’s street was asked how many people live in it (made-up data). Find the standard deviation of household size on the street.

people x12345
households f36542
Solution

All 20 households on the street were counted, so this is a population with N = 20. The total number of people is 1 \cdot 3 + 2 \cdot 6 + 3 \cdot 5 + 4 \cdot 4 + 5 \cdot 2 = 56, so \displaystyle \mu = \frac{56}{20} = 2.8. To keep the table narrow, write d = x - \mu for each value’s deviation.

xfdd^2f d^2
13-1.83.249.72
26-0.80.643.84
350.20.040.2
441.21.445.76
522.24.849.68
sum2029.2

The columns are each value, its count, its deviation d, the square of that, and the square times the count. Each row stands for f households with the same squared deviation, so multiplying by f counts it f times. Dividing by the 20 households, not the 5 rows, gives \displaystyle \sigma^2 = \frac{29.2}{20} = 1.46 and \displaystyle \sigma = \sqrt{1.46} \approx 1.21 people. It is sensible: the largest distance from the mean is 2.2, for the five-person households, and 1.21 is below it.

Example 4

Day 1: is the answer sensible?

Could 4.67 be the standard deviation of the population 3, 7, 8? (a) Answer without computing \sigma. (b) Find \sigma, and find which number in the working is about 4.67. (c) Find \sigma for the population 7, 7, 7.

Solution

(a) No. The mean is \displaystyle \frac{18}{3} = 6, and the distances from it are 3, 1 and 2. A standard deviation is never larger than the largest distance from the mean, here 3, so it cannot be 4.67.

(b) The squared deviations are 9, 1, 4, adding to 14, so \displaystyle \sigma^2 = \frac{14}{3} \approx 4.67. So 4.67 is the variance, in squared units. The standard deviation is \displaystyle \sigma = \sqrt{\frac{14}{3}} \approx 2.16, below the largest distance, 3, as it must be.

(c) Every value equals the mean 7, so every deviation is 0 and \sigma = 0. A population has \sigma = 0 only when all its values are equal.

Example 5

Day 2: battery life from a sample of torches

A factory makes a batch of 2{,}000 torches. Alessio tests 6 of them by running each battery flat. Their battery lives, in hours, are 18, 20, 21, 23, 24, 26 (made-up data). Find the standard deviation, and compare it with dividing by 6.

Solution

The six torches stand in for all 2{,}000, so they are a sample, with n = 6. The mean is \displaystyle \bar{x} = \frac{132}{6} = 22 hours.

hours xdeviation x - 22squared deviation
18-416
20-24
21-11
2311
2424
26416
sum042

Dividing by n - 1 = 5 gives \displaystyle s^2 = \frac{42}{5} = 8.4 and \displaystyle s = \sqrt{8.4} \approx 2.90 hours. Dividing by 6 would give \displaystyle \sqrt{7} \approx 2.65 hours, smaller by the factor \displaystyle \sqrt{\frac{6}{5}} \approx 1.10.

To see which way the smaller figure leans, suppose, only for illustration, that the mean of all 2{,}000 torches were 23 hours. Measured from 23, the deviations are -5, -3, -2, 0, 1, 3, and their squares add to 25 + 9 + 4 + 0 + 1 + 9 = 48, more than 42. That is no accident: the sum from the sample’s own mean is the smallest possible, so it can fall short of the sum from the true mean but never exceed it. In this made-up case \displaystyle \frac{42}{5} = 8.4 lands nearer the \displaystyle \frac{48}{6} = 8 that the true mean would give than \displaystyle \frac{42}{6} = 7 does. One case shows the direction of the correction, not that its size is right.

Example 6

Day 2: the same numbers, two questions

Amadeo runs a café. On the five days of one week he sold 11, 14, 17, 19, 24 cakes (made-up data). (a) He wants the spread of daily sales in that week, for a report on that week. (b) He wants to use the week to estimate the spread of daily sales across the whole year. Find the right standard deviation for each.

Solution

The mean is \displaystyle \frac{85}{5} = 17 cakes. The deviations -6, -3, 0, 2, 7 add to 0, and their squares 36, 9, 0, 4, 49 add to 98.

(a) The five days are the whole group being described, a population: \displaystyle \sigma = \sqrt{\frac{98}{5}} = \sqrt{19.6} \approx 4.43 cakes.

(b) The five days stand in for a year of days, a sample: \displaystyle s = \sqrt{\frac{98}{4}} = \sqrt{24.5} \approx 4.95 cakes.

The table was the same; only the question changed the divisor. Whether one week represents a year well is a separate matter: a week in a holiday season would not.

Example 7

Day 2: a frequency table from a sample

A seed company sends out 5{,}000 packets. Almira opens a sample of 10 and counts the seeds in each that fail to sprout (made-up data). Find the standard deviation.

failed seeds x0123
packets f3421
Solution

The ten packets stand in for all 5{,}000, so this is a sample with n = 10. The total of failed seeds is 0 \cdot 3 + 1 \cdot 4 + 2 \cdot 2 + 3 \cdot 1 = 11, so \displaystyle \bar{x} = \frac{11}{10} = 1.1. This time the deviation is d = x - \bar{x}.

xfdd^2f d^2
03-1.11.213.63
14-0.10.010.04
220.90.811.62
311.93.613.61
sum108.9

Here n - 1 = 9, one less than the number of packets, not the number of rows. So \displaystyle s^2 = \frac{8.9}{9} \approx 0.989 and \displaystyle s = \sqrt{\frac{8.9}{9}} \approx 0.99 seeds. Entered as ten separate values into a spreadsheet, the sample function gives the same 0.99, and the population function gives \displaystyle \sqrt{0.89} \approx 0.94, which is not the one wanted here.

Boundaries

  • A standard deviation needs quantitative data, numbers whose differences mean something.
  • The sample formula needs at least two values. With n = 1 the divisor n - 1 is 0, and a single value shows no spread to measure.
  • Dividing by n - 1 corrects for measuring from \bar{x}; it cannot fix a sample chosen badly. The sample has to be a fair, random choice from the bigger group.
  • Data grouped into bins, as for a histogram, have lost their exact values. Using each bin’s middle in a frequency table then gives only an approximate standard deviation.
  • Values far from the rest pull the standard deviation up, as the two outer books did in Example 1. When a Box plots that show outliers flags outliers, read the standard deviation with care.
  • Round only the final answer; a rounded mean drifts the result (Example 2).

Where this goes next

Interpreting a standard deviation reads the number in the setting’s own units and says what it does and does not tell you. What adding a constant to every value, or multiplying every value, does to \sigma is the subject of Shifting and rescaling a data set. The Mean absolute deviation stays a simpler measure of spread. Where a single value stands can be said by rank, as a percentile, or by how many standard deviations it sits from the mean, which is where the standard deviation goes next.

Exercises

Day 1: population standard deviation

All data are made up. Treat each set as a whole population, and give \sigma to two decimal places unless it is exact.

  1. 3, 4, 8, 10, 15
  2. The page counts of every book in a five-book series: 210, 250, 270, 290, 330.
  3. 2, 3, 7, 8, 9, 10
  4. The bedrooms in each of the 20 flats in a building: 4 flats have 1, 8 have 2, 6 have 3 and 2 have 4.
  5. The goals scored in a season by each of the 10 players in a team: 2 players scored 0, 3 scored 1, 3 scored 2 and 2 scored 3.
  6. For the population 1, 2, 4, 6, find \sigma with the exact mean. Then redo it with the mean rounded to the nearest whole number, and compare.
  7. Could the population 10, 12, 20 have \sigma = 18.7? Explain without computing \sigma. Then find \sigma, and say which number in the working is about 18.7.
  8. Find \sigma for each population. A: 5, 5, 5, 5. B: 4, 5, 5, 6. C: 2, 5, 5, 8.

Day 2: sample standard deviation

Treat each set as a sample, and give s to two decimal places unless it is exact.

  1. 4, 6, 7, 9, 14
  2. The masses of 5 apples picked from an orchard’s harvest: 148, 150, 153, 155, 159 grams.
  3. For the numbers in Exercise 9, find the divide-by-n figure too, and the ratio of s to it.
  4. The masses of 4 parcels taken from the 300 sent one day: 1.2, 1.5, 1.6, 2.1 kg.
  5. A sample of 12 households in a town is asked how many cars each owns: 2 have 0, 4 have 1, 4 have 2 and 2 have 3.
  6. Say whether \sigma (divide by N) or s (divide by n - 1) fits, and why. (a) The heights of every player in a basketball team, to describe that team. (b) The ages of 40 people chosen at random in a city, to learn about the city. (c) 8 bolts measured from a run of 10{,}000. (d) The rainfall on every day of last March, to describe last March.
  7. A spreadsheet holding 10 values reports a population standard deviation of 4.0. What will its sample standard deviation be?
  8. Find the factor \displaystyle \sqrt{\frac{n}{n - 1}} by which s exceeds the divide-by-n figure, to three decimal places, for n = 2, n = 5 and n = 100.

Reasoning

  1. Explain why a population’s \sigma is never larger than the largest distance of a value from the mean. When is it equal to it?
  2. Explain why, for the same numbers (not all equal), s is always larger than the divide-by-n figure, and why the gap shrinks as n grows.
  3. Alessio tests a sample of one torch, and his calculator shows no sample standard deviation. Explain why the formula breaks, and why that makes sense.
Answers
  1. Mean \displaystyle \frac{40}{5} = 8. Deviations -5, -4, 0, 2, 7; squares 25, 16, 0, 4, 49, sum 94. \displaystyle \sigma^2 = \frac{94}{5} = 18.8, \displaystyle \sigma = \sqrt{18.8} \approx 4.34.
  2. Mean \displaystyle \frac{1350}{5} = 270 pages. Deviations -60, -20, 0, 20, 60; squares sum 8000. \displaystyle \sigma^2 = \frac{8000}{5} = 1600, \sigma = 40 pages exactly.
  3. Mean \displaystyle \frac{39}{6} = 6.5. Deviations -4.5, -3.5, 0.5, 1.5, 2.5, 3.5; squares 20.25, 12.25, 0.25, 2.25, 6.25, 12.25, sum 53.5. \displaystyle \sigma^2 = \frac{53.5}{6} \approx 8.92, \sigma \approx 2.99.
  4. Mean \displaystyle \frac{46}{20} = 2.3. Squared deviations 1.69, 0.09, 0.49, 2.89, times counts 6.76, 0.72, 2.94, 5.78, sum 16.2. \displaystyle \sigma^2 = \frac{16.2}{20} = 0.81, \sigma = 0.9 bedrooms exactly.
  5. Mean \displaystyle \frac{15}{10} = 1.5. Squared deviations 2.25, 0.25, 0.25, 2.25, times counts 4.5, 0.75, 0.75, 4.5, sum 10.5. \displaystyle \sigma^2 = \frac{10.5}{10} = 1.05, \sigma \approx 1.02 goals.
  6. Exact mean 3.25: squares 5.0625, 1.5625, 0.5625, 7.5625, sum 14.75, \sigma^2 = 3.6875, \sigma \approx 1.92. Mean rounded to 3: deviations -2, -1, 1, 3 add to 1, squares sum 15, \displaystyle \frac{15}{4} = 3.75, \displaystyle \sqrt{3.75} \approx 1.94. Rounding early pushed the answer up.
  7. The mean is 14 and the distances are 4, 2, 6, so \sigma is at most 6. Squares 16, 4, 36 sum 56; \displaystyle \sigma^2 = \frac{56}{3} \approx 18.67 and \sigma \approx 4.32. The 18.7 is the variance \sigma^2, rounded; \sigma is its square root.
  8. A: every deviation is 0, \sigma = 0. B: mean 5, squares 1, 0, 0, 1, \displaystyle \sigma^2 = \frac{2}{4} = 0.5, \sigma \approx 0.71. C: mean 5, squares 9, 0, 0, 9, \displaystyle \sigma^2 = \frac{18}{4} = 4.5, \sigma \approx 2.12.
  9. Mean 8. Deviations -4, -2, -1, 1, 6; squares sum 58. \displaystyle s^2 = \frac{58}{4} = 14.5, s \approx 3.81.
  10. Mean \displaystyle \frac{765}{5} = 153 g. Deviations -5, -3, 0, 2, 6; squares sum 74. \displaystyle s^2 = \frac{74}{4} = 18.5, s \approx 4.30 g.
  11. \displaystyle \sqrt{\frac{58}{5}} = \sqrt{11.6} \approx 3.41. The ratio is \displaystyle \sqrt{\frac{5}{4}} \approx 1.12, and indeed \displaystyle \frac{3.81}{3.41} \approx 1.12.
  12. Mean \displaystyle \frac{6.4}{4} = 1.6 kg. Deviations -0.4, -0.1, 0, 0.5; squares sum 0.42. \displaystyle s^2 = \frac{0.42}{3} = 0.14, s \approx 0.37 kg.
  13. n = 12, total cars 18, mean 1.5. Squared deviations 2.25, 0.25, 0.25, 2.25, times counts 4.5, 1, 1, 4.5, sum 11. \displaystyle s^2 = \frac{11}{11} = 1, s = 1 car exactly.
  14. (a) \sigma: the team is the whole group described. (b) s: the 40 stand in for the city. (c) s: the bolts stand in for the run. (d) \sigma: every day of the month is measured, and the month itself is the subject.
  15. \displaystyle 4.0 \times \sqrt{\frac{10}{9}} \approx 4.22.
  16. n = 2: \displaystyle \sqrt{2} \approx 1.414. n = 5: \displaystyle \sqrt{1.25} \approx 1.118. n = 100: \displaystyle \sqrt{\frac{100}{99}} \approx 1.005.
  17. Let D be the largest distance. Every squared deviation is at most D^2, so their sum is at most ND^2 and the variance at most D^2; the square root keeps the order, so \sigma \le D. It is equal only when every squared deviation is exactly D^2, that is, when every value is exactly D from the mean, as in 3, 7 (mean 5, \sigma = 2).
  18. Both use the same sum of squared deviations, which is positive because the numbers are not all equal. Dividing a positive number by the smaller n - 1 gives a larger result, and square roots keep the order. The ratio is \displaystyle \sqrt{\frac{n}{n - 1}} = \sqrt{1 + \frac{1}{n - 1}}, and \displaystyle \frac{1}{n - 1} shrinks toward 0 as n grows, so the ratio shrinks toward 1.
  19. With n = 1, n - 1 = 0 and the formula divides by zero. That makes sense: one value has deviation 0 from its own mean, so a sample of one shows nothing about how much the batch varies.
kg1128 · updated 2026-10-10 · CC-BY-SA-4.0