Σ
SDCalc
IntermediateFundamentals·8 min

Standard Deviation Formula: Sample vs Population, Worked Example

The standard deviation formula is s = √[Σ(x − x̄)² / (n − 1)] for a sample and σ = √[Σ(x − μ)² / N] for a population. Symbols, steps, a worked example, plus shortcut, frequency-table and probability versions.

By Hommer Zhao·Published ·Updated

The standard deviation formula

Sample standard deviation: s = √[ Σ(x − x̄)² / (n − 1) ]. Population standard deviation: σ = √[ Σ(x − μ)² / N ]. Both measure how far values typically sit from the mean; the only difference is the divisor. Use n − 1 when your numbers are a sample from a larger group, and N when they are the entire group.

Sample standard deviation

s = √[ Σ(x − x̄)² / (n − 1) ]

Population standard deviation

σ = √[ Σ(x − μ)² / N ]
Try the formula on 8 example values

Sample (n-1) mode: s ≈ 5.237229 for 10, 12, 23, 23, 16, 23, 21, 16. Replace them with your own numbers.

What each symbol means

SymbolMeaning
sSample standard deviation
σ (sigma)Population standard deviation
Σ (capital sigma)Add up the values that follow
xEach value in the data
x̄ (x-bar)Sample mean
μ (mu)Population mean
nNumber of values in the sample
NNumber of values in the population
s², σ²Sample and population variance (the value before the square root)

How to use the formula, step by step

1

Find the mean

Add all values and divide by how many there are.
2

Subtract the mean from each value

These are the deviations, x − x̄. They always add up to 0.
3

Square each deviation

Squaring makes every term zero or positive, so values below and above the mean both count.
4

Add the squares

This total, Σ(x − x̄)², is the sum of squares.
5

Divide and take the square root

Divide by n − 1 for a sample (you need at least two values) or N for a population to get the variance, then take the square root to get the standard deviation.

Worked example

Eight illustrative delivery times, in minutes:

Eight delivery times (minutes)
10, 12, 23, 23, 16, 23, 21, 16

Deviations and squares

Value xx − x̄(x − x̄)²
10-864
12-636
23525
23525
16-24
23525
2139
16-24
x̄ = 18Sum = 0Σ(x − x̄)² = 192

Sample and population results

Sample: s = √(192 ÷ 7) ≈ √27.428571 ≈ 5.237229 minutes. Population: σ = √(192 ÷ 8) = √24 ≈ 4.898979 minutes.

Computed with this site's calculator on 2026-11-02. Each button opens the same eight values in the calculator with that mode selected.

Divide Σ(x − x̄)² byn − 1 = 7Variances² ≈ 27.428571Standard deviations ≈ 5.237229
Divide Σ(x − x̄)² byN = 8Varianceσ² = 24Standard deviationσ ≈ 4.898979

Sample vs population formula

The two formulas share every step except the divisor. A sample formula answers "how spread out is the larger group these values came from?", while the population formula describes only the values you have. For the eight delivery times above the sample result is larger because it divides by 7 instead of 8. The sample vs population guide shows how that gap shrinks as n grows.

Check which one your software uses

Spreadsheet and programming functions differ in their default divisor. NumPy's std() divides by N unless you set ddof=1, while Excel's STDEV.S and Python's statistics.stdev divide by n − 1.

Why the sample formula divides by n − 1

The sample mean x̄ is the point that makes the sum of squared deviations Σ(x − x̄)² as small as possible for that sample, so measuring from x̄ instead of the unknown population mean makes the sum slightly too small on average. Dividing by n − 1 instead of n (Bessel's correction) makes the sample variance s² an unbiased estimate of the population variance. The square root s is still slightly biased low as an estimate of σ, but n − 1 is the standard convention. The n − 1 is also called the degrees of freedom: once the mean is fixed, only n − 1 deviations can vary freely.

Shortcut (computational) formula

Sample variance, shortcut form

s² = [ Σx² − (Σx)² / n ] / (n − 1)

With the same eight values: Σx = 144 and Σx² = 2784, so Σx² − (Σx)²/n = 2784 − 144² ÷ 8 = 192, the same sum of squares as the table above. Dividing by n − 1 = 7 gives s² ≈ 27.428571 and s ≈ 5.237229.

The shortcut is handy by hand or on a basic calculator. See the shortcut formula guide for when it can lose precision.

Formula for a frequency table

Frequency table (mean x̄ = Σfx / Σf)

σ = √[ Σf(x − x̄)² / Σf ] s = √[ Σf(x − x̄)² / (Σf − 1) ]

When values repeat, multiply each squared deviation by its frequency f instead of writing every value out. Illustrative table:

Value xFrequency ff · xf · (x − x̄)²
1222.420000
25100.050000
3392.430000
TotalΣf = 10Σfx = 21Σf(x − x̄)² = 4.900000

Mean x̄ = Σfx ÷ Σf = 21 ÷ 10 = 2.100000. Population: σ = √(4.900000 ÷ 10) = 0.700000. Sample: s = √(4.900000 ÷ (10 − 1)) ≈ 0.737865. The calculator gives the same results for the 10 values written out.

Open the 10 values as a sample

1, 1, 2, 2, 2, 2, 2, 3, 3, 3 in Sample (n-1) mode: s ≈ 0.737865.

Open the 10 values as a population

Population (N) mode: σ = 0.700000.

Grouped data: class intervals

For class intervals, use each class midpoint m as x in the same formulas. The result is an approximation, because every value in a class is treated as if it sat at the midpoint. Illustrative example:

ClassMidpoint mFrequency ff · (m − x̄)²
0 to under 1053243
10 to under 201555
20 to under 30252242
TotalΣf = 10Σf(m − x̄)² = 490

x̄ = Σfm ÷ Σf = 14, so σ ≈ √(490 ÷ 10) = 7 and s ≈ √(490 ÷ 9) ≈ 7.378648. These are estimates: the raw values inside each class are unknown.

The frequency table guide covers grouped data in more detail. Sheppard's correction can reduce the grouping error for equal-width classes of a smooth, continuous distribution.

Assumed mean and step-deviation methods

Assumed mean A, with d = x − A

Σ(x − x̄)² = Σd² − (Σd)² / n

Textbooks often subtract a convenient assumed mean A first to keep the numbers small. It changes nothing in the answer.

With A = 16 for the delivery times: d = -6, -4, 7, 7, 0, 7, 5, 0, Σd = 16, Σd² = 224. Then Σd² − (Σd)²/n = 224 − 16² ÷ 8 = 192, the same sum of squares, so σ = √(192 ÷ 8) ≈ 4.898979 and s = √(192 ÷ 7) ≈ 5.237229.

Step-deviation method: also divide by a common step h > 0, u = (x − A) / h. With h = 2: Σu = 8, Σu² = 56, so Σu² − (Σu)²/n = 48. Multiply by h² = 4: the sum of squares becomes 48 × 4 = 192, the population variance 6 × 4 = 24. A standard deviation computed from the u values is multiplied by h.

Formula for a probability distribution

Discrete random variable

σ = √[ Σ(x − μ)² · P(x) ], μ = Σ x · P(x)

Example: a fair six-sided die, P(x) = 1/6 for x = 1 to 6. μ = Σx·P(x) = 3.500000, σ² = Σ(x − μ)²·P(x) = 35/12 ≈ 2.916667, so σ = √(35/12) ≈ 1.707825. There is no n − 1 here: the probabilities describe the whole distribution.

The formula in Excel, Google Sheets, Python and R

ToolSample (n − 1)Population (N)
Excel / Google Sheets=STDEV.S(range)=STDEV.P(range)
Python statisticsstatistics.stdev(data)statistics.pstdev(data)
NumPynp.std(data, ddof=1)np.std(data)
Rsd(x)sqrt(mean((x - mean(x))^2))

Function names are from the official documentation for Excel, Google Sheets, Python, NumPy and R. The sample functions need at least two values. The Excel guide and Excel and Python guide go further.

Further Reading

Sources

References and further authoritative reading used in preparing this article.

  1. 1.3.5.6. Measures of Scale — NIST/SEMATECH e-Handbook of Statistical Methods — NIST
  2. STDEV.S function — Microsoft
  3. statistics — Mathematical statistics functions — Python Software Foundation
  4. Bessel's correction — Wikipedia
  5. Google Sheets function list — Google
  6. numpy.std — NumPy
  7. sd: Standard Deviation — R Core Team

Frequently Asked Questions

What is the formula for standard deviation?

For a sample, s = √[Σ(x − x̄)² / (n − 1)]: subtract the mean from each value, square the differences, add them up, divide by n − 1 and take the square root. For a whole population, σ = √[Σ(x − μ)² / N], which divides by N instead.

Which standard deviation formula should I use?

Use the sample formula (n − 1) when your values are part of a larger group you want to describe, which is the usual case. Use the population formula (N) only when you have every value in the group, such as all students in one class.

Why is the standard deviation the square root of the variance?

Variance averages squared deviations, so its units are squared (minutes², for example). Taking the square root brings the measure back to the original units, which makes the standard deviation easier to compare with the data.

Is the shortcut formula the same as the definition formula?

Yes. Σx² − (Σx)²/n equals Σ(x − x̄)² exactly, so both give the same standard deviation. The shortcut avoids computing every deviation, but with very large or very precise numbers it can lose accuracy to rounding, which is why software uses more stable methods.

What is the standard deviation formula in Excel?

=STDEV.S(range) uses the sample formula (n − 1) and =STDEV.P(range) uses the population formula (N). Google Sheets uses the same function names.