Standard deviation is the most widely used measure of how far data spread out from their mean. Yet a calculator or spreadsheet often offers two different values. One divides the sum of squared deviations by n, the other by n−1. This guide explains what each formula means, why samples use n−1, and how to choose between them in practice.
The two formulas
When you have the entire population, the population standard deviation is:
- Population SD:
σ = √(Σ(x−μ)² / N)
When you use a sample to estimate the spread of a larger population, you use:
- Sample SD:
s = √(Σ(x−x̄)² / (n−1))
There are two differences. First, the center is the sample mean x̄ rather than the population mean μ. Second, the divisor is n−1 instead of n. The second change is called Bessel's correction.
Why divide by n−1?
The sample mean x̄ is computed from the very same sample, so it sits as close as possible to those data points. In fact, the sum of squares Σ(x−c)² is smallest when c is the sample mean. Measuring deviations from x̄ instead of the true μ therefore makes the sum of squares systematically too small.
Mathematically, the expected value of the variance divided by n is (n−1)/n × σ². With a sample of 5, for example, the divide-by-n variance averages only 4/5 = 80% of the true variance. Multiplying by n/(n−1) removes this underestimate, which is the same as dividing by n−1. The result, s², is an unbiased estimator of σ².
Another way to see it is through degrees of freedom. The n deviations (x−x̄) must always sum to zero. Once n−1 of them are known, the last one is fixed. Only n−1 pieces of information are free to vary, so we divide by n−1.
Note:
s²is unbiased forσ², but its square rootsis not unbiased forσ. Because the square root is concave,sis slightly smaller thanσon average. The gap becomes negligible as the sample grows, sosis used as is in practice.
Worked example by hand
Take these eight values:
2, 4, 4, 4, 5, 5, 7, 9
Step 1: Mean
x̄ = (2+4+4+4+5+5+7+9) / 8 = 40 / 8 = 5
Step 2: Deviations and squared deviations
| Value x | Deviation x−x̄ | Squared |
|---|---|---|
| 2 | −3 | 9 |
| 4 | −1 | 1 |
| 4 | −1 | 1 |
| 4 | −1 | 1 |
| 5 | 0 | 0 |
| 5 | 0 | 0 |
| 7 | 2 | 4 |
| 9 | 4 | 16 |
The deviations sum to −3−1−1−1+0+0+2+4 = 0, confirming the constraint above. The sum of squares is 9+1+1+1+0+0+4+16 = 32.
Step 3: Two variances and standard deviations
| Basis | Variance | Standard deviation |
|---|---|---|
| Population (÷n) | 32 / 8 = 4 | √4 = 2 |
| Sample (÷(n−1)) | 32 / 7 ≈ 4.5714 | √4.5714 ≈ 2.1381 |
If these eight values are everything you care about, the standard deviation is 2. If they were drawn from a larger group whose spread you want to estimate, report about 2.1381. With n as small as 8 the difference is about 7%. At n = 100 it shrinks to about 0.5%, and at n = 1,000 to about 0.05%.
Which one should you use?
The question is simply whether your data are the whole group of interest or a part of it.
- Population (÷n): describing the spread of test scores for one class of 30 students and only that class, or the salary distribution of every employee in one company.
- Sample (÷(n−1)): estimating national opinion from 500 survey respondents, or estimating the variability of a whole production process from 20 sampled parts.
Most real-world data are samples. Confidence intervals, t-tests and sample size calculations all assume the sample standard deviation s. When in doubt, the sample formula is the conservative choice.
Spreadsheet and programming equivalents
| Tool | Sample (÷(n−1)) | Population (÷n) |
|---|---|---|
| Excel, Google Sheets | STDEV.S, VAR.S (legacy STDEV) | STDEV.P, VAR.P (legacy STDEVP) |
| R | sd(), var() | adjust manually |
| Python pandas | Series.std() default ddof=1 | std(ddof=0) |
| Python NumPy | np.std(x, ddof=1) | np.std(x) default ddof=0 |
NumPy and pandas have opposite defaults, which is a common reason the same data give different results. Check which formula was used before comparing numbers.
Reading a standard deviation
A standard deviation has the same unit as the data: points for test scores, centimeters for heights. Variance is in squared units and harder to read, so reports usually give the standard deviation. If the data are roughly normal, about 68% of values fall within one standard deviation of the mean and about 95% within two. To compare the spread of groups with very different means, the coefficient of variation (CV), the standard deviation divided by the mean, is often shown as well.
Common mistakes
- Not stating which formula was used: with small samples the values differ noticeably, so write
sorσ, or say "sample standard deviation". - Confusing standard deviation with standard error: the standard error
SE = s / √ndescribes the spread of the sample mean, not of individual values. Confidence intervals use the standard error. - Computing a sample SD with n = 1: n−1 becomes 0, so it is undefined. A calculator should return an error.
- Ignoring outliers: because deviations are squared, a single extreme value can move the standard deviation a lot. If outliers are suspected, look at the interquartile range (IQR) too.
Paste your data into this site's descriptive statistics calculator to see the sample and population standard deviations side by side.
Key takeaways
- Divide by n when the data are the whole group, and by n−1 when they are part of a larger group.
- The divide-by-n sample variance has expected value
(n−1)/n × σ²; dividing by n−1 corrects this (Bessel's correction). - For
2, 4, 4, 4, 5, 5, 7, 9, the standard deviation is 2 as a population and about 2.1381 as a sample. - Excel separates
STDEV.S(sample) andSTDEV.P(population); NumPy and pandas have different defaults. - Keep standard deviation (spread of data) and standard error (spread of the mean) apart.