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
Population standard deviation
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
| Symbol | Meaning |
|---|---|
| s | Sample standard deviation |
| σ (sigma) | Population standard deviation |
| Σ (capital sigma) | Add up the values that follow |
| x | Each value in the data |
| x̄ (x-bar) | Sample mean |
| μ (mu) | Population mean |
| n | Number of values in the sample |
| N | Number of values in the population |
| s², σ² | Sample and population variance (the value before the square root) |
How to use the formula, step by step
Find the mean
Subtract the mean from each value
Square each deviation
Add the squares
Divide and take the square root
Worked example
Eight illustrative delivery times, in minutes:
10, 12, 23, 23, 16, 23, 21, 16Deviations and squares
| Value x | x − x̄ | (x − x̄)² |
|---|---|---|
| 10 | -8 | 64 |
| 12 | -6 | 36 |
| 23 | 5 | 25 |
| 23 | 5 | 25 |
| 16 | -2 | 4 |
| 23 | 5 | 25 |
| 21 | 3 | 9 |
| 16 | -2 | 4 |
| x̄ = 18 | Sum = 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.
| Formula | Divide Σ(x − x̄)² by | Variance | Standard deviation |
|---|---|---|---|
Sample (s)Open in Sample (n-1) mode | Divide Σ(x − x̄)² byn − 1 = 7 | Variances² ≈ 27.428571 | Standard deviations ≈ 5.237229 |
Population (σ)Open in Population (N) mode | Divide Σ(x − x̄)² byN = 8 | Varianceσ² = 24 | Standard 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
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
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)
When values repeat, multiply each squared deviation by its frequency f instead of writing every value out. Illustrative table:
| Value x | Frequency f | f · x | f · (x − x̄)² |
|---|---|---|---|
| 1 | 2 | 2 | 2.420000 |
| 2 | 5 | 10 | 0.050000 |
| 3 | 3 | 9 | 2.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.
1, 1, 2, 2, 2, 2, 2, 3, 3, 3 in Sample (n-1) mode: s ≈ 0.737865.
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:
| Class | Midpoint m | Frequency f | f · (m − x̄)² |
|---|---|---|---|
| 0 to under 10 | 5 | 3 | 243 |
| 10 to under 20 | 15 | 5 | 5 |
| 20 to under 30 | 25 | 2 | 242 |
| 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
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
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
| Tool | Sample (n − 1) | Population (N) |
|---|---|---|
| Excel / Google Sheets | =STDEV.S(range) | =STDEV.P(range) |
| Python statistics | statistics.stdev(data) | statistics.pstdev(data) |
| NumPy | np.std(data, ddof=1) | np.std(data) |
| R | sd(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.3.5.6. Measures of Scale — NIST/SEMATECH e-Handbook of Statistical Methods — NIST
- STDEV.S function — Microsoft
- statistics — Mathematical statistics functions — Python Software Foundation
- Bessel's correction — Wikipedia
- Google Sheets function list — Google
- numpy.std — NumPy
- sd: Standard Deviation — R Core Team