Standard Deviation Calculator
Get the sample and population standard deviation side by side, so you never pick the wrong one by accident. Works from raw data, grouped frequencies, or summary statistics, and reports variance, standard error, coefficient of variation, a confidence interval and a robust MAD comparison.
⚡ 0. Quick Answer
The standard deviation is the average distance of your values from their mean. A small SD means the data cluster tightly; a large one means they are spread out. It is in the same units as your data, which is what makes it more useful than the variance.
STDEV.S, R sd().STDEV.P, NumPy default.Key takeaways
- The n − 1 is called Bessel's correction. Dividing by n would systematically underestimate the spread, because the sample mean sits closer to your own data than the true population mean does.
- The two versions converge quickly. At n = 5 the sample SD is 12% larger than the population SD; at n = 30 it is 1.7%; at n = 100 it is 0.5%. The choice matters most on small samples.
- Standard deviation is not standard error. SD measures the spread of individual values; SE measures the precision of the mean and equals SD divided by the square root of n. Confusing them is the single most common error in reporting.
- One extreme value can dominate it. Both formulas square the deviations, so an outlier has an outsized effect. The calculator reports the median absolute deviation alongside so you can see when this is happening.
- The old "computational formula" can fail badly. On large values it loses so much precision that it can return a variance of zero when the true answer is one. This tool uses a numerically stable method instead.
- The SD itself is an estimate with its own uncertainty. From 12 observations, a standard deviation of 5.67 has a 95% confidence interval running from 4.02 to 9.63. That is far wider than most people expect.
📚 1. What Is Standard Deviation?
1.1 The idea, built up from scratch
You want a single number describing how spread out your data are. The obvious first attempt is the average distance from the mean, but that fails immediately: deviations above the mean and below it cancel exactly, and the answer is always zero.
So you square each deviation first, which makes everything positive, then average those squares. That gives the variance. The problem with variance is its units: if you measured heights in centimetres, the variance is in square centimetres, which is meaningless. Take the square root and you are back in centimetres. That is the standard deviation.
SD = √variance · variance = SD²So the standard deviation is best read as a typical distance from the mean, expressed in the same units as your measurements. If a set of exam marks has a mean of 53 and an SD of 5.7, most marks sit within about 6 points of 53.
1.2 Why divide by n minus 1?
This is the question everyone asks and most pages answer badly. Here is the honest version.
To measure spread you need a centre to measure from. When you only have a sample, you do not know the true population mean, so you use the sample mean instead. But the sample mean is calculated from those very numbers, so it sits closer to them than the true population mean would. The sum of squared deviations comes out too small, every single time, and dividing by n would carry that bias straight through.
Dividing by n − 1 corrects for it exactly. The reason it is exactly one, rather than some other adjustment, is that computing the mean uses up one degree of freedom: once you know the mean and any n − 1 of your values, the last one is determined. Only n − 1 of the deviations are genuinely free to vary.
1.3 How much difference does it actually make?
| n | Sample SD relative to population SD | Difference |
|---|---|---|
| 2 | √(2/1) = 1.414 | 41.4% larger |
| 5 | √(5/4) = 1.118 | 11.8% larger |
| 10 | √(10/9) = 1.054 | 5.4% larger |
| 30 | √(30/29) = 1.017 | 1.7% larger |
| 100 | √(100/99) = 1.005 | 0.5% larger |
| 1,000 | √(1000/999) = 1.0005 | 0.05% larger |
The choice matters enormously on tiny samples and hardly at all on large ones. That is a useful thing to know, because it tells you where to spend your attention: if two people disagree about an SD computed from n = 8, the divisor is very likely the reason.
1.4 What the standard deviation tells you about your data
If the data are roughly bell-shaped, the empirical rule gives you quick landmarks: about 68% of values fall within one SD of the mean, about 95% within two, and about 99.7% within three. So an SD of 5.7 around a mean of 53 says most values live between 47 and 59, and almost all between 42 and 64.
If the data are not bell-shaped, those percentages do not hold, but Chebyshev's inequality still guarantees a weaker version for any distribution: at least 75% of values lie within two SDs of the mean and at least 89% within three. That guarantee is loose, but it is unconditional.
1.5 Standard deviation versus its relatives
| Measure | What it describes | Formula | Units |
|---|---|---|---|
| Standard deviation | Spread of individual values around the mean | √variance | Same as the data |
| Variance | The same thing, before taking the root | SD² | Squared |
| Standard error | Precision of the mean, not of the data | SD / √n | Same as the data |
| Coefficient of variation | Spread relative to the size of the mean | SD / mean | Unitless, often a % |
| Range | Distance from smallest to largest | max − min | Same as the data |
| Interquartile range | Spread of the middle half | Q3 − Q1 | Same as the data |
| MAD | Robust spread, immune to outliers | median of |x − median| | Same as the data |
🧮 2. Set Up Your Calculation
Paste your numbers and the calculator returns both standard deviations, the variance, the standard error, the coefficient of variation, a confidence interval and a robust MAD comparison.
📁 Or upload a CSV / Excel file
For data already summarised into classes or repeated values. Enter either class midpoints or the values themselves, with a frequency for each.
If you only have summary figures, enter what you have. This is common when checking a published result or working from a textbook exercise.
Two different questions here, and they have different answers. Pooled SD estimates a shared within-group spread and is what a t-test uses. Combined SD is the spread you would get by merging all the data into one pile, which is larger because it includes the gap between the group means.
Move between the four quantities that all describe the same spread. Give any one plus the sample size and the calculator fills in the rest.
📊 3. Results
🧠 4. Interpretation of Results, In Detail
4.1 Reading the number itself
The standard deviation is a typical distance from the mean, in your original units. If exam marks have a mean of 53 and an SD of 5.7, a typical mark sits about 6 points away from 53 in one direction or the other. If component lengths have a mean of 12.1 mm and an SD of 0.29 mm, parts typically deviate by about three tenths of a millimetre.
It is not the average absolute deviation, which would be a slightly smaller number, because squaring gives extra weight to the larger deviations. That is a real property, not a flaw: it is why the SD is sensitive to outliers, and why it is the right measure when large deviations matter more than small ones.
4.2 Sample or population, decided properly
The question is not how many values you have. It is whether those values are the entire group you want to describe.
If you weighed every one of the 40 penguins in a colony and only want to describe that colony, you have a population: divide by N. If you weighed 40 penguins in order to say something about penguins in general, you have a sample: divide by n − 1. The same 40 numbers, two different answers, because the question changed.
When in doubt use the sample version. It is slightly larger, which makes it the conservative choice, and it is what every statistical procedure downstream expects.
4.3 Standard deviation is not standard error
This is the most damaging confusion in applied statistics, and it appears constantly in published figures.
The standard deviation describes your data. It tells you how spread out individual observations are. Collecting more data does not shrink it: if heights vary by 8 cm, they vary by 8 cm whether you measure 30 people or 3,000.
The standard error describes your estimate. It tells you how precisely you know the mean, and it equals the SD divided by the square root of n. Collecting more data does shrink it, because averages of larger samples are more stable.
So "mean 53 ± 5.67" and "mean 53 ± 1.64" can describe exactly the same dataset of 12 values. The first uses the SD and describes the spread of marks; the second uses the SE and describes how well the average is pinned down. Error bars on a chart are ambiguous unless the caption says which they are, and readers who assume the wrong one will draw wrong conclusions about variability.
4.4 When one value is doing all the work
Because deviations are squared, a single extreme observation can dominate the standard deviation completely. The results table shows each value's share of the total sum of squares, and on clean data no value contributes much more than its fair share of 1/n. When one contributes 40% or more, the SD is largely describing that one point.
The calculator reports a robust alternative alongside: 1.4826 times the median absolute deviation, scaled so that it matches the standard deviation for normally distributed data. When the classical SD is much larger than this robust estimate, you have a strong signal that outliers are inflating it. A ratio above about 1.6 is worth investigating.
That does not automatically mean the outlier should go. It means you should look at it, decide deliberately, and say what you decided.
4.5 The standard deviation is itself an estimate
People treat the SD as a fact about the data, but when your data are a sample it is an estimate of an unknown population value, and it carries real uncertainty.
From 12 observations, a standard deviation of 5.67 has a 95% confidence interval running from about 4.02 to 9.63. The upper limit is more than twice the lower one. That is far wider than most people expect, and it has a practical consequence: comparing two standard deviations from small samples almost never establishes anything.
The interval narrows slowly. You need roughly 200 observations before the 95% interval for an SD is within about 10% of the estimate. Note also that this particular interval assumes normality more strongly than most procedures do, so treat it as indicative rather than exact.
4.6 What the SD tells you about shape, which is nothing
Two datasets can share a mean and a standard deviation while looking entirely different. One might be symmetric and bell-shaped; the other might be strongly skewed with a long tail; a third might be bimodal with nothing at all near the mean.
The empirical rule (about 68% within one SD, 95% within two, 99.7% within three) only holds for roughly bell-shaped data. On skewed data the actual coverage can be quite different, which is why the calculator reports your observed coverage next to what a normal distribution would predict. If those two disagree markedly, the mean and SD are a poor summary and you should report the median and interquartile range as well.
Chebyshev's inequality gives a guarantee that holds for any distribution: at least 75% of values within two SDs, at least 89% within three. It is much weaker than the empirical rule, but it is unconditional.
4.7 The old computational formula, and why this tool does not use it
Textbooks often teach a shortcut for the sum of squares: Σx² − (Σx)²/n. It is algebraically identical to the definition and it needs only one pass through the data, which mattered enormously when calculations were done by hand or on early machines.
On a computer it is dangerous. Both terms can be enormous while their difference is tiny, so nearly all the significant digits cancel away. Take the three values 100000001, 100000002 and 100000003. The true sum of squared deviations is 2. The shortcut formula, evaluated in standard double precision, returns 0, implying a standard deviation of zero for three clearly different numbers.
This calculator uses Welford's method, which updates the mean and the sum of squares one observation at a time and never forms those huge intermediate values. It is exact to within rounding on any data you are likely to have. The calculator also runs the shortcut formula in the background purely to check, and warns you when the two disagree, which is a warning no other standard deviation page will give you.
4.8 Grouped data is an approximation
When you only have a frequency table, every observation in a class has to be treated as sitting exactly at the class midpoint. That discards the variation inside each class, so the result is close but not exact.
The error is usually small when classes are narrow and roughly symmetric within themselves, and it grows with wider classes. Open-ended classes such as "60 and over" are the worst case, because you have to invent a midpoint and your choice directly changes the answer. If the raw values still exist anywhere, use them instead.
4.9 Reading the four charts
Chart 1 plots your observations with the mean and the one and two standard deviation bands drawn across them, which is the fastest way to see whether the SD is describing the bulk of your data. Chart 2 shows each value's squared deviation, so a single dominant bar tells you immediately that one observation is driving the result. Chart 3 shows how the sample and population versions converge as n grows, with your own sample size marked. Chart 4 compares the SD against the range, the interquartile range, the robust MAD estimate and the standard error, all in your original units.
Chart 2 is the one to look at first when something seems wrong. On well-behaved data the bars are of broadly similar height; when one towers over the rest, the standard deviation is telling you about that point rather than about your data.
4.10 A quick sanity check you can do in your head
The range rule of thumb says the standard deviation is roughly the range divided by four, because most data span about four standard deviations. For a dataset running from 45 to 63, that gives 18/4 = 4.5 against an actual SD of 5.67. Close enough to confirm you have not misplaced a decimal point.
The rule is crude and it breaks down badly on skewed data or with outliers, where the range inflates and the estimate becomes too high. But if your computed SD differs from range/4 by a factor of five or more, check your arithmetic before you check your data.
✍ 5. How to Write Your Results in Research
▶ Run the analysis above to auto-fill all five examples with your results.
📌 Key conventions for this style
- Italicise M, SD and n in APA style.
- Always give the sample size. An SD without n cannot be judged.
- State whether it is a sample or population SD if there is any chance of ambiguity.
- Report the SD to one more decimal place than the raw data, no more.
📌 Key conventions for this style
- For tables, figure captions and parenthetical use.
- The convention M = 53.17, SD = 5.67 is understood everywhere.
- Never write 53.17 ± 5.67 without saying what the ± represents.
📌 Key conventions for this style
- Never write "standard deviation" for a general audience.
- "Most values fall between X and Y" is understood by everyone.
- Give the range in original units, which is what people actually picture.
- Do not imply the interval is exact when the data may be skewed.
📌 Key conventions for this style
- State explicitly whether you used n or n − 1.
- State whether error bars show SD, SE or a confidence interval. Journals increasingly require this.
- If the data were grouped, say so and note that the figure is an approximation.
- If you excluded outliers, say which, how many and on what rule.
📌 Key conventions for this style
- Reviewers increasingly ask what a dispersion estimate is sensitive to.
- Report the robust MAD-based figure alongside when outliers are present.
- Give the confidence interval for the SD when comparing dispersion between groups.
- Avoid claiming one group is "more variable" than another from small samples without a formal test.
∑ 6. Formulas Used
📝 7. How to Use This Calculator
- Paste your numbers into the data column. From my data opens first with one column ready. Enter values comma-separated exactly as the placeholder shows, and the calculator returns both standard deviations, the variance, the standard error, the coefficient of variation and a robust comparison.
- Read both standard deviations, then pick one. They are shown side by side deliberately, because choosing the wrong divisor is the most common mistake on this topic. Use the sample version unless the numbers you entered are the entire group you care about.
- Load a sample dataset to see the edge cases. Nine are built in, including one with a single dominant outlier, one that is strongly skewed, one where every value is identical, and one with values large enough to break the old textbook shortcut formula.
- Add clusters to compare groups. Each gets its own mean, SD, variance, SE and CV in a comparison table. Every column has its own Clear and Remove button, and Remove is disabled on the last remaining column. You can also upload a CSV or Excel file and click the columns you want.
- For a frequency table, use the grouped tab. Enter class midpoints or class limits with a frequency for each. Remember the result is an approximation, because every observation is treated as sitting at its class midpoint.
- If you only have summary figures, use the third tab. It accepts n with Σx and Σx², or n with the sum of squared deviations, or a variance you want converted back to a standard deviation.
- To combine groups, use the pooled tab. It reports both the pooled SD, which describes within-group spread and is what a t-test uses, and the combined SD, which describes the merged dataset. They answer different questions and the tab shows both so you cannot quote the wrong one by accident.
- To move between measures, use the convert tab. Give it any one of the standard deviation, variance, standard error or coefficient of variation plus the sample size, and it fills in the others.
- Press Calculate Standard Deviation. Nothing is computed until you do, and changing any input clears the results so you never read stale numbers.
- Check the warnings and the robust comparison before reporting. If the classical SD is much larger than the MAD-based estimate, one or two values are inflating it, and the per-value contribution table will show you which.
📊 8. How to Calculate Standard Deviation in Excel
Excel gives you one function for each version, and choosing between them is the whole difficulty. Below is the complete workflow in ten steps, each with a picture of what your sheet should look like.
STDEV.S divides by n − 1 and is what you want almost always. STDEV.P divides by N and is only correct when your data are the entire population. Everything else on this page is built from those two.Step 1. Put your data in one column with a header, and set aside a block for the statistics. Twelve values are in A2:A13 here, only the first eight are visible.
Step 2. AVERAGE gives the mean, 53.1667. The standard deviation measures distance from this value.
Step 3. STDEV.S divides by n minus 1 and gives 5.6702. This is the SAMPLE standard deviation and the one you want in almost every situation.
Step 4. STDEV.P divides by N and gives 5.4288, about 4.4% smaller. Only use it when your data are the complete population.
Step 5. VAR.S is the variance, which is simply the SD squared. Note it is in squared units, so it is not directly comparable to your data.
Step 6. The standard error, s divided by the square root of n. This describes the precision of the MEAN, not the spread of the data. Do not confuse the two.
Step 7. The coefficient of variation as a percentage. Useful for comparing spread across different scales, but only meaningful on a ratio scale.
Step 8. The long way, if you want to see the working. Column B is each deviation, column C squares it, and the sum of column C is the sum of squares, 353.6667.
Step 9. Divide the sum of squares by n minus 1 to get the variance, then take the square root for the standard deviation. This reproduces STDEV.S exactly.
Step 10. Grouped data has no single-function shortcut. Build the columns yourself: mean = SUM(C)/SUM(B) = 24.0, then SD = SQRT(SUM(D)/(SUM(B)-1)) = 10.6188.
The complete function reference
| What you want | Excel formula | Result on the example |
|---|---|---|
| Sample SD | =STDEV.S(A2:A13) | 5.6702 |
| Population SD | =STDEV.P(A2:A13) | 5.4288 |
| Sample variance | =VAR.S(A2:A13) | 32.1515 |
| Population variance | =VAR.P(A2:A13) | 29.4722 |
| Mean | =AVERAGE(A2:A13) | 53.1667 |
| Count | =COUNT(A2:A13) | 12 |
| Sum of squared deviations | =DEVSQ(A2:A13) | 353.6667 |
| Standard error of the mean | =STDEV.S(A2:A13)/SQRT(COUNT(A2:A13)) | 1.6369 |
| Coefficient of variation | =STDEV.S(A2:A13)/AVERAGE(A2:A13) | 0.1067, or 10.67% |
| Median absolute deviation | =MEDIAN(ABS(A2:A13-MEDIAN(A2:A13))) | 4.5 (array formula) |
| Robust SD estimate | =1.4826*MAD | 6.6717 |
| SD ignoring text and logicals | =STDEV.S(range) | the default behaviour |
| SD including text as zero | =STDEVA(range) | rarely what you want |
| SD with a condition | =STDEV.S(IF(B2:B13="A",A2:A13)) | array formula, Ctrl+Shift+Enter in older Excel |
| CI lower bound for the SD | =SQRT((n-1)*VAR.S(r)/CHISQ.INV.RT(0.025,n-1)) | 4.0168 |
| CI upper bound for the SD | =SQRT((n-1)*VAR.S(r)/CHISQ.INV.RT(0.975,n-1)) | 9.6274 |
Grouped data, which has no single function
| Step | Formula | Result |
|---|---|---|
| Column C: f × x | =B2*A2 | fill down |
| Total frequency N | =SUM(B2:B6) | 30 |
| Mean | =SUM(C2:C6)/SUM(B2:B6) | 24.0000 |
| Column D: f(x − mean)² | =B2*(A2-$F$2)^2 | fill down |
| Sample SD | =SQRT(SUM(D2:D6)/(SUM(B2:B6)-1)) | 10.6188 |
| Population SD | =SQRT(SUM(D2:D6)/SUM(B2:B6)) | 10.4403 |
| One-cell version | =SQRT(SUMPRODUCT(B2:B6,(A2:A6-mean)^2)/(SUM(B2:B6)-1)) | 10.6188 |
Seven mistakes that catch people out
- Using STDEV.P because it sounds more official. The P stands for population, not precise. Unless you measured everyone, you want STDEV.S.
- Using the legacy STDEV or STDEVP. They still work for backward compatibility, but the modern names make the divisor explicit and are far less error-prone.
- Confusing STDEVA with STDEV.S. The A version treats text as zero and logical values as 0 or 1, which will silently distort your answer if the range contains anything non-numeric.
- Including the header row in the range. Excel ignores text, so it will not error, but if a header is numeric it will be treated as data.
- Blank cells versus zeros. Blanks are excluded; zeros are included and pull the mean down. If missing data were entered as 0, your SD is wrong.
- Reporting error bars without saying what they are. Excel's default error bars are the standard error, not the standard deviation. Label them.
- Building the SD by hand with Σx² − (Σx)²/n. Algebraically correct, numerically fragile. On large values it can return a negative number under the square root. Use
DEVSQorSTDEV.S.
STDEV and STDEVP. The MAD array formula needs ARRAYFORMULA(...) wrapped around it.STDEV.S.📈 9. How to Calculate Standard Deviation in R
R has one function, sd(), and it always divides by n − 1. There is no argument to change that, which is either a helpful safeguard or an irritation depending on what you need.
sd() has no ddof or population argument. If you genuinely need the population standard deviation you must convert it yourself: sd(x) * sqrt((n - 1) / n). Many people assume a hidden argument exists, do not find it, and quietly report the wrong thing.# Standard Deviation Calculator in R (base R, no packages)
# ---- 1. Your data -----------------------------------------------------
x <- c(52, 48, 55, 61, 47, 58, 50, 63, 45, 56, 54, 49)
n <- length(x)
# ---- 2. Both standard deviations --------------------------------------
m <- mean(x)
s <- sd(x) # SAMPLE: R ALWAYS divides by n - 1
sigma <- sd(x) * sqrt((n - 1) / n) # POPULATION: you must convert manually
var_s <- var(x) # sample variance, also n - 1
var_p <- var(x) * (n - 1) / n # population variance
# ---- 3. Related measures ----------------------------------------------
se <- s / sqrt(n) # standard error OF THE MEAN
cv <- s / m * 100 # coefficient of variation, %
robust_sd <- mad(x) # NOTE: R's mad() ALREADY includes 1.4826
raw_mad <- median(abs(x - median(x))) # the unscaled version
# ---- 4. Confidence interval for the SD --------------------------------
alpha <- 0.05
lo <- sqrt((n - 1) * var_s / qchisq(1 - alpha/2, n - 1))
hi <- sqrt((n - 1) * var_s / qchisq(alpha/2, n - 1))
# ---- 5. Grouped frequency data ----------------------------------------
mids <- c(5, 15, 25, 35, 45)
freqs <- c(3, 7, 12, 6, 2)
N_g <- sum(freqs)
mean_g <- sum(freqs * mids) / N_g
sd_g <- sqrt(sum(freqs * (mids - mean_g)^2) / (N_g - 1))
# ---- 6. Pooled standard deviation --------------------------------------
ns <- c(10, 10); ms <- c(53.5, 70.5); sds <- c(6.096447, 3.979112)
within <- sum((ns - 1) * sds^2)
N_tot <- sum(ns); k <- length(ns)
pooled <- sqrt(within / (N_tot - k))
grand <- sum(ns * ms) / N_tot
between <- sum(ns * (ms - grand)^2)
combined <- sqrt((within + between) / (N_tot - 1))
cat(sprintf("n = %d mean = %.6f\n", n, m))
cat(sprintf("SAMPLE SD s = %.10f (R default, n - 1)\n", s))
cat(sprintf("POPULATION SD s = %.10f (converted manually)\n", sigma))
cat(sprintf(" s is %.4f%% larger, exactly sqrt(n/(n-1))\n", (s/sigma - 1)*100))
cat(sprintf("variance: sample %.6f, population %.6f\n", var_s, var_p))
cat(sprintf("SE = %.6f CV = %.4f%% mad() = %.6f\n", se, cv, robust_sd))
cat(sprintf("95%% CI for the SD: %.6f to %.6f\n", lo, hi))
cat(sprintf("GROUPED N = %d, mean = %.4f, sample SD = %.6f\n", N_g, mean_g, sd_g))
cat(sprintf("POOLED %.6f COMBINED %.6f\n", pooled, combined))
# ---- 7. One figure ----------------------------------------------------
plot(seq_len(n), x, pch = 19, cex = 1.5, col = "#0f766e", bty = "n",
xlab = "observation number", ylab = "value",
ylim = range(c(x, m - 2.4*s, m + 2.4*s)),
main = sprintf("Data with SD bands n=%d, mean=%.2f, s=%.2f", n, m, s))
# shade the +/- 1 and +/- 2 SD bands behind the points
rect(0, m - 2*s, n + 1, m + 2*s, col = adjustcolor("#0369a1", 0.10), border = NA)
rect(0, m - 1*s, n + 1, m + 1*s, col = adjustcolor("#0f766e", 0.18), border = NA)
points(seq_len(n), x, pch = 19, cex = 1.5, col = "#0f766e")
abline(h = m, lwd = 2, col = "#0f172a")
abline(h = c(m - s, m + s), lty = 2, col = "#0f766e")
abline(h = c(m - 2*s, m + 2*s), lty = 3, col = "#0369a1")
legend("topright", bty = "n", cex = 0.85,
legend = c(sprintf("mean = %.2f", m),
sprintf("+/- 1 SD = %.2f", s),
"+/- 2 SD"),
col = c("#0f172a", "#0f766e", "#0369a1"),
lwd = c(2, NA, NA), lty = c(1, 2, 3))
What the script prints
n = 12 mean = 53.166667
SAMPLE SD s = 5.6702306083 (R default, n - 1)
POPULATION SD s = 5.4288324916 (converted manually)
s is 4.4466% larger, exactly sqrt(n/(n-1))
variance: sample 32.151515, population 29.472222
SE = 1.636855 CV = 10.6650% mad() = 6.671700
95% CI for the SD: 4.016764 to 9.627360
GROUPED N = 30, mean = 24.0000, sample SD = 10.618786
POOLED 5.147815 COMBINED 10.057728
These are the same numbers the Python script produces and the same numbers the calculator at the top of this page produces.
Line-by-line explanation
- Block 1 and 2 show the manual conversion R forces on you. Note that
var()also uses n − 1, so the population variance needs the same correction factor. - Block 3 contains a genuine trap. R's
mad()already multiplies by 1.4826 by default, so it returns 6.6717 directly, not the raw MAD of 4.5. If you write1.4826 * mad(x)you will double-scale it. The unscaled version is shown for comparison. - Block 4 builds the confidence interval from the chi-square distribution. Note the reversal: the upper chi-square quantile gives the lower bound of the interval, because the quantity is in the denominator.
- Block 5 handles grouped data, which R has no built-in function for. Weighting by frequency is straightforward with vectorised arithmetic.
- Block 6 computes both the pooled and the combined SD, showing that they answer different questions. The gap between 5.15 and 10.06 here is entirely the difference between the two group means.
- Block 7 draws the SD bands behind the points, which is the single most useful diagnostic plot for a standard deviation.
Useful one-liners
| Task | R | Note |
|---|---|---|
| Sample SD | sd(x) | always n − 1 |
| Population SD | sd(x)*sqrt((length(x)-1)/length(x)) | no built-in |
| Sample variance | var(x) | also n − 1 |
| Standard error | sd(x)/sqrt(length(x)) | no built-in se() |
| Coefficient of variation | sd(x)/mean(x) | multiply by 100 for a % |
| Robust SD | mad(x) | already scaled by 1.4826 |
| Raw MAD | mad(x, constant = 1) | the unscaled version |
| SD of every column | apply(df, 2, sd) | or sapply(df, sd) |
| SD by group | tapply(x, g, sd) | or aggregate(x ~ g, FUN = sd) |
| Ignore missing values | sd(x, na.rm = TRUE) | otherwise NA propagates |
| Weighted SD | sqrt(sum(w*(x-weighted.mean(x,w))^2)/(sum(w)-1)) | for frequency data |
| Full summary | summary(x); sd(x) | summary() omits the SD |
| Rolling SD | zoo::rollapply(x, 5, sd) | needs the zoo package |
🐍 10. How to Calculate Standard Deviation in Python
NumPy has one function with a switch, and the switch defaults to the version most people do not want. The script below was run before being published, so the output shown underneath is the real console output.
np.std(x) defaults to ddof=0, which is the population standard deviation. R's sd() and Excel's STDEV.S both give the sample version. So the same data can produce two different answers depending on the language, and the difference is largest exactly when your sample is smallest. Write ddof=1 explicitly whenever your data are a sample. Note that pandas goes the other way: df.std() defaults to ddof=1.# Standard Deviation Calculator in Python
# Sample and population SD, grouped data, pooled SD, and a stability check.
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from scipy import stats
# ---- 1. Your data -----------------------------------------------------
x = np.array([52, 48, 55, 61, 47, 58, 50, 63, 45, 56, 54, 49], dtype=float)
n = x.size
# ---- 2. Both standard deviations --------------------------------------
mean = x.mean()
s = x.std(ddof=1) # SAMPLE: divides by n-1. Excel STDEV.S, R sd()
sigma = x.std(ddof=0) # POPULATION: divides by N. This is NumPy's DEFAULT
var_s = x.var(ddof=1)
var_p = x.var(ddof=0)
# ---- 3. Related measures ----------------------------------------------
se = s / np.sqrt(n) # standard error OF THE MEAN, not of the data
cv = s / mean * 100 # coefficient of variation, %
med = np.median(x)
mad = np.median(np.abs(x - med))
robust_sd = 1.4826 * mad # scaled to match s for normal data
# ---- 4. Confidence interval for the SD (chi-square) -------------------
alpha = 0.05
lo = np.sqrt((n - 1) * var_s / stats.chi2.ppf(1 - alpha/2, n - 1))
hi = np.sqrt((n - 1) * var_s / stats.chi2.ppf(alpha/2, n - 1))
# ---- 5. Grouped frequency data ----------------------------------------
mids = np.array([5, 15, 25, 35, 45], dtype=float)
freqs = np.array([3, 7, 12, 6, 2], dtype=float)
N_g = freqs.sum()
mean_g = (freqs * mids).sum() / N_g
ss_g = (freqs * (mids - mean_g)**2).sum()
sd_g = np.sqrt(ss_g / (N_g - 1))
# ---- 6. Pooled standard deviation --------------------------------------
groups = [(10, 53.5, 6.096447), (10, 70.5, 3.979112)] # (n, mean, sd)
within = sum((g[0] - 1) * g[2]**2 for g in groups)
N_tot = sum(g[0] for g in groups)
k = len(groups)
pooled = np.sqrt(within / (N_tot - k))
grand = sum(g[0] * g[1] for g in groups) / N_tot
between = sum(g[0] * (g[1] - grand)**2 for g in groups)
combined = np.sqrt((within + between) / (N_tot - 1))
# ---- 7. Why the textbook shortcut is dangerous ------------------------
big = np.array([100000001, 100000002, 100000003], dtype=float)
shortcut_ss = (big**2).sum() - big.sum()**2 / big.size # algebraically right
correct_ss = ((big - big.mean())**2).sum() # numerically right
print(f"n = {n} mean = {mean:.6f}")
print(f"SAMPLE SD s = {s:.10f} (ddof=1, Excel STDEV.S)")
print(f"POPULATION SD s = {sigma:.10f} (ddof=0, NumPy DEFAULT)")
print(f" s is {(s/sigma - 1)*100:.4f}% larger, exactly sqrt(n/(n-1))")
print(f"variance: sample {var_s:.6f}, population {var_p:.6f}")
print(f"SE = {se:.6f} CV = {cv:.4f}% robust SD (1.4826*MAD) = {robust_sd:.6f}")
print(f"95% CI for the SD: {lo:.6f} to {hi:.6f}")
print(f"GROUPED N = {N_g:.0f}, mean = {mean_g:.4f}, sample SD = {sd_g:.6f}")
print(f"POOLED {pooled:.6f} COMBINED {combined:.6f}")
print(f"SHORTCUT on large values: {shortcut_ss} CORRECT: {correct_ss}")
print(f" the shortcut is WRONG by {abs(shortcut_ss - correct_ss)} here")
# ---- 8. One figure ----------------------------------------------------
fig, ax = plt.subplots(figsize=(9, 5))
ax.scatter(range(1, n + 1), x, s=70, color="#0f766e", zorder=4, label="observations")
ax.axhline(mean, color="#0f172a", lw=2, label=f"mean = {mean:.2f}")
for k_sd, col, a in [(1, "#0f766e", .22), (2, "#0369a1", .12)]:
ax.axhspan(mean - k_sd*s, mean + k_sd*s, color=col, alpha=a,
label=f"±{k_sd} SD" if k_sd == 1 else f"±{k_sd} SD")
ax.set_xlabel("observation number")
ax.set_ylabel("value")
ax.set_title(f"Data with SD bands n={n}, mean={mean:.2f}, s={s:.2f}")
ax.legend(frameon=False, fontsize=9, loc="upper right")
ax.spines[["top", "right"]].set_visible(False)
fig.tight_layout()
fig.savefig("standard_deviation.png", dpi=150)
print("saved standard_deviation.png")
Actual output from running the script
n = 12 mean = 53.166667
SAMPLE SD s = 5.6702306083 (ddof=1, Excel STDEV.S)
POPULATION SD s = 5.4288324916 (ddof=0, NumPy DEFAULT)
s is 4.4466% larger, exactly sqrt(n/(n-1))
variance: sample 32.151515, population 29.472222
SE = 1.636855 CV = 10.6650% robust SD (1.4826*MAD) = 6.671700
95% CI for the SD: 4.016764 to 9.627360
GROUPED N = 30, mean = 24.0000, sample SD = 10.618786
POOLED 5.147815 COMBINED 10.057728
SHORTCUT on large values: 0.0 CORRECT: 2.0
the shortcut is WRONG by 2.0 here
Line-by-line explanation
- Block 2 computes both versions side by side with the
ddofargument made explicit in each case, which is the habit worth forming. The printed ratio confirms the relationship s = σ × √(n / (n − 1)). - Block 3 derives the standard error, the coefficient of variation and the robust MAD-based estimate. Unlike R, NumPy has no built-in
mad(), so there is no double-scaling trap here, but you must remember the 1.4826 yourself. - Block 4 builds the confidence interval for the standard deviation from the chi-square distribution. Note the reversal: the upper chi-square quantile produces the lower bound.
- Block 5 handles grouped frequency data by weighting, which vectorises cleanly in NumPy.
- Block 6 computes both the pooled and the combined standard deviation from group summaries alone, without needing the raw data.
- Block 7 is the important one. It runs the textbook shortcut formula alongside the correct calculation on three large values, and prints the result: the shortcut returns 0.0 where the true answer is 2.0. Both terms are around 3 × 1016, so their difference falls below the precision of a double. This is why this calculator uses Welford's method internally.
- Block 8 plots the data with the one and two standard deviation bands shaded behind it.
Useful one-liners
| Task | Python | Note |
|---|---|---|
| Sample SD | np.std(x, ddof=1) | you must ask for it |
| Population SD | np.std(x) | the NumPy default |
| Sample variance | np.var(x, ddof=1) | same switch |
| Pandas SD | df['col'].std() | defaults to ddof=1, unlike NumPy |
| Pandas population SD | df['col'].std(ddof=0) | the opposite switch |
| Standard error | stats.sem(x) | SciPy, uses ddof=1 |
| Coefficient of variation | stats.variation(x, ddof=1) | returns a proportion |
| Robust SD | stats.median_abs_deviation(x, scale='normal') | applies the 1.4826 |
| Raw MAD | stats.median_abs_deviation(x) | unscaled |
| Ignore missing values | np.nanstd(x, ddof=1) | or pandas, which skips NaN by default |
| SD by group | df.groupby('g')['x'].std() | ddof=1 |
| SD of every column | df.std() | ddof=1 |
| Rolling SD | df['x'].rolling(5).std() | ddof=1 |
| Weighted SD | np.sqrt(np.average((x-np.average(x,weights=w))**2, weights=w)) | population form |
| Numerically safe by default | np.std, statistics.stdev | both use a two-pass method |
statistics.stdev(x) from the standard library gives the sample SD and statistics.pstdev(x) the population version, with no ambiguous default. They are slower than NumPy on large arrays but they are unambiguous, which makes them useful for verifying a result you are unsure about.📋 11. Reference Tables
11.1 How much the divisor actually matters
The ratio between the sample and population standard deviation is exactly √(n / (n − 1)). This table tells you when the choice is worth arguing about and when it is not.
| n | n − 1 | s / σ ratio | How much larger s is |
|---|---|---|---|
| 2 | 1 | 1.414214 | 41.421% |
| 3 | 2 | 1.224745 | 22.474% |
| 4 | 3 | 1.154701 | 15.470% |
| 5 | 4 | 1.118034 | 11.803% |
| 6 | 5 | 1.095445 | 9.545% |
| 8 | 7 | 1.069045 | 6.904% |
| 10 | 9 | 1.054093 | 5.409% |
| 12 | 11 | 1.044466 | 4.447% |
| 15 | 14 | 1.035098 | 3.510% |
| 20 | 19 | 1.025978 | 2.598% |
| 25 | 24 | 1.020621 | 2.062% |
| 30 | 29 | 1.017095 | 1.710% |
| 40 | 39 | 1.012739 | 1.274% |
| 50 | 49 | 1.010153 | 1.015% |
| 100 | 99 | 1.005038 | 0.504% |
| 200 | 199 | 1.002509 | 0.251% |
| 500 | 499 | 1.001002 | 0.100% |
| 1000 | 999 | 1.000500 | 0.050% |
11.2 How uncertain is your standard deviation?
Multiply your SD by the two factors to get its 95% confidence interval. This is the table that surprises people most.
| n | 95% CI lower | 95% CI upper | Upper / lower | Interval width |
|---|---|---|---|---|
| 3 | 0.5207 × s | 6.2847 × s | 12.07× | 576.4% of s |
| 5 | 0.5991 × s | 2.8736 × s | 4.80× | 227.4% of s |
| 10 | 0.6878 × s | 1.8256 × s | 2.65× | 113.8% of s |
| 15 | 0.7321 × s | 1.5771 × s | 2.15× | 84.5% of s |
| 20 | 0.7605 × s | 1.4606 × s | 1.92× | 70.0% of s |
| 30 | 0.7964 × s | 1.3443 × s | 1.69× | 54.8% of s |
| 50 | 0.8353 × s | 1.2461 × s | 1.49× | 41.1% of s |
| 100 | 0.8780 × s | 1.1617 × s | 1.32× | 28.4% of s |
| 200 | 0.9107 × s | 1.1089 × s | 1.22× | 19.8% of s |
| 500 | 0.9416 × s | 1.0662 × s | 1.13× | 12.5% of s |
| 1000 | 0.9580 × s | 1.0459 × s | 1.09× | 8.8% of s |
At n = 12 with s = 5.6702, the interval is 5.6702 × 0.7084 = 4.0168 to 5.6702 × 1.6979 = 9.6274. The upper bound is 2.4 times the lower one. You need roughly n = 200 before the interval is within about 10% either side, which is why claims that one small group is "more variable" than another are usually unsupportable.
11.3 The empirical rule, and the guarantee that always holds
The middle columns apply only to roughly bell-shaped data. Chebyshev's inequality on the right holds for any distribution whatsoever, which makes it much weaker but completely safe.
| Within | Normal distribution | Outside | Chebyshev, any distribution |
|---|---|---|---|
| ±0.5 SD | 38.29% | 61.71% | no guarantee |
| ±1 SD | 68.27% | 31.73% | no guarantee |
| ±1.5 SD | 86.64% | 13.36% | at least 55.6% |
| ±1.96 SD | 95.00% | 5.00% | at least 74.0% |
| ±2 SD | 95.45% | 4.55% | at least 75.0% |
| ±2.5 SD | 98.76% | 1.24% | at least 84.0% |
| ±3 SD | 99.73% | 0.27% | at least 88.9% |
| ±4 SD | 99.99% | 0.01% | at least 93.8% |
11.4 Chi-square values behind the SD confidence interval
| n | df | χ² 0.025 | χ² 0.975 | χ² 0.05 | χ² 0.95 |
|---|---|---|---|---|---|
| 5 | 4 | 0.4844 | 11.1433 | 0.7107 | 9.4877 |
| 10 | 9 | 2.7004 | 19.0228 | 3.3251 | 16.9190 |
| 12 | 11 | 3.8157 | 21.9200 | 4.5748 | 19.6751 |
| 15 | 14 | 5.6287 | 26.1189 | 6.5706 | 23.6848 |
| 20 | 19 | 8.9065 | 32.8523 | 10.1170 | 30.1435 |
| 25 | 24 | 12.4012 | 39.3641 | 13.8484 | 36.4150 |
| 30 | 29 | 16.0471 | 45.7223 | 17.7084 | 42.5570 |
| 40 | 39 | 23.6543 | 58.1201 | 25.6954 | 54.5722 |
| 50 | 49 | 31.5549 | 70.2224 | 33.9303 | 66.3386 |
| 60 | 59 | 39.6619 | 82.1174 | 42.3393 | 77.9305 |
| 100 | 99 | 73.3611 | 128.4220 | 77.0463 | 123.2252 |
Note the reversal when you use these: the upper chi-square quantile gives the lower bound of the interval for the standard deviation, because the quantity sits in the denominator.
11.5 Measures of spread compared
| Measure | Formula | Robust to outliers? | Same units? | Best used for |
|---|---|---|---|---|
| Standard deviation | √[Σ(x−x̄)²/(n−1)] | No | Yes | Roughly symmetric data, and anything feeding a parametric test |
| Variance | SD² | No | No, squared | Mathematical work, because variances add |
| Standard error | SD / √n | No | Yes | Describing how precisely the mean is known |
| Coefficient of variation | SD / mean | No | Unitless | Comparing spread across different scales |
| Range | max − min | No, very sensitive | Yes | Quick checks and quality control limits |
| Interquartile range | Q3 − Q1 | Yes | Yes | Skewed data, boxplots |
| MAD | median of |x − median| | Yes, very | Yes | Data with outliers you cannot remove |
| Robust SD | 1.4826 × MAD | Yes | Yes | A drop-in replacement for the SD when outliers are present |
11.6 Software defaults, which do not agree
| Tool | Function | Default divisor | How to get the other one |
|---|---|---|---|
| Excel | STDEV.S / STDEV.P | you choose explicitly | switch function |
| Google Sheets | STDEV / STDEVP | you choose explicitly | switch function |
| R | sd() | n − 1 | multiply by √((n−1)/n) |
| Python, NumPy | np.std() | N | ddof=1 |
| Python, pandas | .std() | n − 1 | ddof=0 |
| Python, statistics | stdev() / pstdev() | you choose explicitly | switch function |
| SPSS | DESCRIPTIVES | n − 1 | not directly offered |
| Stata | summarize | n − 1 | not directly offered |
| SAS | PROC MEANS | n − 1 | VARDEF=N |
| Most calculators | σn-1 and σn keys | both provided | separate keys |
np.std(df['x']) and df['x'].std() on identical data return different numbers, and neither raises a warning. This single inconsistency causes more reproducibility failures than any other default in scientific Python.11.7 What a standard deviation means in familiar contexts
| Context | Typical mean | Typical SD | CV | Interpretation |
|---|---|---|---|---|
| IQ scores | 100 | 15 | 15% | Fixed by construction, not measured |
| Adult male height (UK) | 175 cm | 7 cm | 4% | Very consistent, as biology often is |
| Adult body weight | 75 kg | 15 kg | 20% | Considerably more variable than height |
| Resting heart rate | 70 bpm | 10 bpm | 14% | Moderate individual variation |
| Exam marks | 60 | 15 | 25% | Deliberately spread to discriminate |
| Household income | varies | large | 60% or more | Strongly skewed, so the SD is a poor summary |
| Machined part tolerance | to spec | tiny | under 1% | Process control aims to minimise it |
| Daily stock return | near 0 | 1% to 2% | enormous | The SD itself is the quantity of interest, called volatility |
The coefficient of variation column is the useful one for cross-context comparison, because the standard deviations themselves are in incompatible units. Note the income row: when the CV exceeds about 60% the distribution is usually skewed enough that the mean and SD together mislead.
11.8 Quick reference for common tasks
| You want to | Use | Watch out for |
|---|---|---|
| Describe the spread of a sample | Sample SD, n − 1 | Not the population version |
| Describe a complete population | Population SD, N | Are you sure it is complete? |
| Say how precise your mean is | Standard error | Label it clearly, it is not the SD |
| Compare spread across different units | Coefficient of variation | Ratio scale only |
| Handle data with outliers | 1.4826 × MAD, or the IQR | R's mad() already scales |
| Summarise skewed data | Median and IQR | The SD will mislead |
| Feed a t-test or ANOVA | Pooled SD | Not the combined SD |
| Compute Cohen's d | Pooled SD | Same caution |
| Work from a frequency table | Grouped formula | It is an approximation |
| Work from a published mean and SD | Summary statistics tab | Check which divisor they used |
💡 12. Eight Worked Examples
Every number below was computed with the calculator on this page and cross-checked against Python. Each example has its own colour and its own figure. Examples 3 and 6 are the two worth studying closely: one shows a single value hijacking the result, the other shows a formula from most textbooks returning a standard deviation of zero for three different numbers.
Setup: 52, 48, 55, 61, 47, 58, 50, 63, 45, 56, 54, 49
| n | 12 |
|---|---|
| Mean | 53.1667 |
| Sum of squared deviations | 353.6667 |
| Sample SD (divide by 11) | 5.6702 |
| Population SD (divide by 12) | 5.4288 |
| Sample variance | 32.1515 |
| Population variance | 29.4722 |
| Ratio s / sigma | 1.044466 = √(12/11) |
| Standard error | 1.6369 |
| Coefficient of variation | 10.6650% |
Reading it: The sample version is 5.6702 and the population version is 5.4288, a difference of 4.45%. That gap is exactly √(12/11), and it exists because the sample mean sits closer to these twelve numbers than the true population mean would. Use 5.6702 unless these twelve marks are the entire group you care about. Note the standard error of 1.6369 is a completely different quantity: it describes how precisely the mean is known, not how spread out the marks are.
Setup: The same twelve marks, but now they are every student in the class, and you only want to describe that class.
| Question asked | How spread out is THIS class? |
|---|---|
| Is this a sample? | No, it is the whole group of interest |
| Correct choice | Population SD = 5.4288 |
| If you generalised to all students | Sample SD = 5.6702 |
| Difference | 0.2414 marks |
| Standard error | Not meaningful here, there is nothing to generalise to |
| Rule of thumb | Ask whether you would generalise beyond these numbers |
Reading it: Nothing about the data changed. The correct answer changed because the question changed. If these twelve marks are the entire class and you only want to describe that class, you have a population and 5.4288 is right. If you are using the class to say something about students in general, you have a sample and 5.6702 is right. This is also why the standard error is meaningless in the first case: there is no wider population for the mean to be an estimate of.
Setup: 120, 118, 125, 119, 122, 121, 117, 124, 123, 119, 126, 116, 121, 120, 118, 180
| n | 16 |
|---|---|
| Mean | 124.3125 |
| Classical SD | 15.1205 |
| SD without the 180 | 2.9472 |
| Median | 120.5 |
| MAD | 2.5 |
| Robust SD (1.4826 × MAD) | 3.7065 |
| Ratio classical / robust | 4.08 |
| The outlier's share of the sum of squares | 90.4% |
Reading it: A single value has more than quintupled the standard deviation, from 2.95 to 15.12. The reason is visible in the contribution table: that one observation accounts for 90.4% of the entire sum of squares. The robust MAD-based estimate of 3.71 ignores it entirely and describes the other fifteen readings honestly. A ratio of 4.08 between the classical and robust figures is a loud signal. This does not automatically mean you delete the 180, but you must look at it and decide deliberately.
Setup: Ages in five 10-year classes with midpoints 5, 15, 25, 35, 45 and frequencies 3, 7, 12, 6, 2.
| Total frequency N | 30 |
|---|---|
| Classes | 5 |
| Σfx | 720.0 |
| Mean | 24.0000 |
| Σf(x − mean)² | 3270.0000 |
| Sample SD | 10.6188 |
| Population SD | 10.4403 |
| What was assumed | every person in a class is exactly at its midpoint |
| What was lost | all variation inside each class |
Reading it: Grouped data gives 10.6188, which is an approximation rather than the truth. Every one of the twelve people in the 20 to 30 class has been treated as if aged exactly 25, which discards the real variation inside that class. The error is usually modest with narrow, symmetric classes and grows with wider ones. The worst case is an open-ended class such as "60 and over", where you must invent a midpoint and your invention directly changes the answer. If the raw ages exist anywhere, use them.
Setup: Site A: 52, 48, 55, 61, 47, 58, 50, 63, 45, 56 (mean 53.5)
Site B: 71, 68, 75, 66, 73, 70, 69, 77, 64, 72 (mean 70.5)
| Site A: n, mean, SD | 10, 53.5, 6.0964 |
|---|---|
| Site B: n, mean, SD | 10, 70.5, 3.9791 |
| Within-group sum of squares | 477.0000 |
| Pooled SD | 5.1478 |
| Grand mean | 62.0 |
| Between-group sum of squares | 1445.0000 |
| Combined SD (all 20 merged) | 10.0577 |
| Ratio | 1.95 times larger |
Reading it: The pooled SD of 5.1478 says that within either site, values typically sit about 5 units from that site's own mean. The combined SD of 10.0577 says that if you ignore which site a value came from, the spread is nearly twice as large. Both are correct; they answer different questions. The entire gap comes from the 17-point difference between the two site means, which the combined figure absorbs and the pooled figure excludes. Use pooled for a t-test or Cohen's d, and combined when describing the merged dataset. Quoting the wrong one is invisible to a reader.
Setup: Three values: 100000001, 100000002, 100000003. The true standard deviation is exactly 1.
| Values | 100000001, 100000002, 100000003 |
|---|---|
| Mean | 100000002 |
| True sum of squared deviations | 2 |
| Σx² | 30000001200000014 |
| (Σx)² / n | 30000001200000012 |
| Shortcut result | 0 (should be 2) |
| Shortcut SD | 0 (should be 1) |
| Why | both terms are about 3 × 1016, so their difference falls below double precision |
| What this tool uses | Welford's method, which never forms those large terms |
Reading it: This is the most important example on the page and no other standard deviation calculator will show it to you. The formula Σx² − (Σx)²/n is algebraically identical to the definition and is taught in most textbooks because it needs only one pass through the data. On a computer it is unsafe: here both terms are around 30 quadrillion, and their true difference of 2 is smaller than the rounding error in either one, so the answer comes out as exactly zero. Three visibly different numbers get a standard deviation of zero. This calculator runs both methods and warns you whenever they disagree.
Setup: The same twelve exam marks, with s = 5.6702. How precisely do we actually know the spread?
| Sample SD | 5.6702 |
|---|---|
| n | 12 |
| Degrees of freedom | 11 |
| χ² at 0.025 | 3.8157 |
| χ² at 0.975 | 21.9200 |
| 95% CI lower | 4.0168 |
| 95% CI upper | 9.6274 |
| Upper / lower | 2.40 times |
| n needed for a ±10% interval | about 200 |
Reading it: The standard deviation is itself an estimate, and from twelve observations it is a very rough one. The 95% confidence interval runs from 4.02 to 9.63, with the upper limit 2.4 times the lower. Notice the interval is not symmetric around 5.67, because the chi-square distribution behind it is skewed. The practical consequence is that comparing two standard deviations from small samples almost never establishes anything, and the bar chart shows how slowly the interval narrows: you need roughly 200 observations before it sits within about 10% either side.
Setup: Group A: 48, 50, 52, 54, 53, 51, 49, 55
Group B: 30, 70, 45, 58, 62, 38, 66, 42
| Group A mean | 51.5000 |
|---|---|
| Group B mean | 51.3750 |
| Group A SD | 2.4495 |
| Group B SD | 14.5498 |
| Ratio | 5.94 times more variable |
| Group A CV | 4.76% |
| Group B CV | 28.32% |
| Group A range | 7 |
| Group B range | 40 |
Reading it: Both groups average almost exactly 51, and a report quoting only the mean would call them identical. Group A is tightly clustered with an SD of 2.45; Group B is scattered from 30 to 70 with an SD of 14.55, six times larger. If these were delivery times, treatment responses or machine outputs, that difference would matter far more than the average does. This is the whole case for reporting a measure of spread alongside every mean, and for plotting your data rather than trusting any pair of summary numbers.
📋 13. Data Collection Protocol
A standard deviation is only as meaningful as the measurements behind it. Most of what makes it trustworthy is decided long before you open a calculator.
- Decide first whether you have a sample or a population. Write the answer into your protocol. It determines the divisor, and it is far harder to argue about honestly after you have seen the number.
- Use one measurement protocol throughout. Same instrument, same units, same conditions, same operator instructions. Mixing two methods inflates the standard deviation with measurement noise that has nothing to do with the thing you are studying.
- Calibrate and check drift. An instrument that slowly wanders adds variability that looks exactly like real spread. Record calibration checks alongside the data.
- Record raw values at full resolution. Rounding before computing changes the standard deviation, and coarse rounding can turn genuine variation into apparent ties. Round at the reporting stage only.
- Never record missing data as zero. A zero is a measurement; a blank is not. Zeros pull the mean down and inflate the SD, and nothing in the output will tell you it happened.
- Watch for values at a measurement limit. Readings recorded as "below detection" or capped at an instrument maximum compress the tails and understate the true spread.
- Keep the observations independent. Repeated measurements of the same subject, or several plants from the same pot, are not independent observations. Treating them as such understates the real variability between subjects.
- Log every exclusion when it happens, with a reason. If you removed an outlier, say which one, how many, and by what rule. Reviewers compare your stated n against your tables.
- Plot the data before summarising it. Thirty seconds with a dot plot or histogram will reveal skew, bimodality or a stray value that the mean and SD together will hide completely.
- Collect enough observations to pin the SD down. Section 11.2 shows the confidence interval by sample size. If comparing dispersion between groups is one of your aims, you need considerably more data than you would for comparing means.
- Store the mean, SD and n together. A standard deviation without its sample size cannot be judged, and without its mean it cannot be interpreted relative to scale.
- State the divisor in your write-up. One sentence saying you used n − 1 removes an entire class of ambiguity for anyone trying to reproduce your work.
🎯 14. When to Use Standard Deviation, and When Not To
Use the standard deviation when
- Your data are roughly symmetric and you want a single number for the spread in the original units.
- You are reporting a mean. A mean without a measure of spread is close to useless, and the SD is the conventional partner.
- You are feeding a parametric procedure. t-tests, ANOVA, regression, confidence intervals and effect sizes are all built on it.
- You are doing quality control. Control limits are almost always expressed in standard deviations from a target.
- You need to standardise. Z-scores, and every machine learning method that scales features, divide by the standard deviation.
- Large deviations should count for more than small ones. Squaring is a feature here, not a bug.
Do not rely on it when
- The data are strongly skewed. The mean minus two SDs can fall outside the possible range, which is a sign the summary does not fit. Report the median and interquartile range instead.
- Outliers are present and you cannot remove them. One extreme value can dominate, as Example 3 shows. Use the MAD-based estimate or the IQR.
- The data are ordinal. Likert responses, rankings and grades have no meaningful arithmetic mean, so they have no meaningful standard deviation either.
- The distribution is bimodal. When the data form two clusters, the mean sits in the empty gap between them and the SD describes a spread nothing actually has.
- You want to describe the precision of a mean. That is the standard error, and confusing the two is the most common reporting error in applied statistics.
- The sample is tiny. Below about n = 5 the SD is so imprecise that quoting it to two decimals implies a confidence you do not have.
- You are comparing spread across different units or scales. Use the coefficient of variation, which is unitless.
What to use instead
| Situation | Better choice | Why |
|---|---|---|
| Skewed data | Interquartile range with the median | Neither is distorted by a long tail |
| Outliers present | 1.4826 × MAD | The median cannot be moved by an extreme value |
| Ordinal data | Frequencies, mode, or the range of ranks | Arithmetic on ordinal codes is not meaningful |
| Comparing different scales | Coefficient of variation | Unitless, so comparison is possible |
| Precision of an estimate | Standard error or a confidence interval | Answers a different question entirely |
| Bimodal data | Report the two groups separately | A single summary describes neither |
| Counts or rates | Poisson or negative binomial dispersion | Variance is tied to the mean for count data |
| Very small samples | Report the raw values and the range | Honest, and the reader can see everything |
| Proportions | √[p(1−p)/n], the standard error of a proportion | The SD of a binary variable is determined by p |
🔧 15. Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Your answer differs from a colleague's in the second decimal | One of you used n and the other n − 1 | Agree on sample or population, and say which in the write-up |
| NumPy and R give different answers | np.std() defaults to N, sd() uses n − 1 | Write ddof=1 in NumPy |
| NumPy and pandas give different answers | They have opposite defaults in the same language | Set ddof explicitly in both |
| The standard deviation is zero | Every value is identical | Arithmetically correct. Check the data were not rounded or copied |
| The SD is larger than the mean | Highly variable positive data, or negative values present | Legitimate. But check the data are on a ratio scale before quoting a CV |
| The SD is enormous compared with the data | One value in the wrong unit, or a typo adding a digit | Sort the data and look at the extremes |
| Excel returns #DIV/0! | Fewer than two numeric values in the range | STDEV.S needs at least two |
| Your manual calculation gives a negative variance | The Σx² shortcut has lost precision | Use the definition, or DEVSQ, or this calculator |
| The SD does not match the software | Blank cells, text, or missing values handled differently | Check how each tool treats non-numeric entries |
| Error bars look too small in a chart | They are standard errors, not standard deviations | Excel's default is the SE. Label them either way |
| Grouped result differs from the raw-data result | Grouping is an approximation | Expected. Use raw data when available |
| R's mad() gives a much larger number than expected | It already multiplies by 1.4826 | Use mad(x, constant = 1) for the raw MAD |
| Pooled SD does not match the SD of the merged data | They are different quantities | Correct behaviour. See Example 5 |
| The SD changed a lot after adding one observation | Small sample, or the new value is extreme | Check the per-value contribution table |
| Two groups look equally variable but the SDs differ | Small samples give imprecise SDs | See the confidence interval in section 11.2 before claiming a difference |
| The empirical rule does not hold on your data | The data are not bell-shaped | Report the median and IQR alongside |
⚖ 16. Assumptions and Limitations
What the standard deviation assumes
The arithmetic itself assumes almost nothing. It will happily produce a number for any set of values. The assumptions are about whether that number means what you want it to mean.
| Assumption | Needed for | What happens if it fails | How to check |
|---|---|---|---|
| Interval or ratio scale | The number to mean anything | An SD of Likert codes is arithmetic on labels | Inspect what the numbers represent |
| Correct divisor for your question | An unbiased estimate | Systematic under- or over-statement, largest at small n | Are these values the whole group? |
| Independent observations | Generalising beyond the data | Understates true between-subject variability | A property of the design |
| Roughly symmetric distribution | The empirical rule and mean ± SD intervals | Intervals can extend outside the possible range | Histogram, or compare mean with median |
| No dominant outlier | Describing the bulk of the data | The SD describes one point rather than the dataset | Compare against 1.4826 × MAD |
| Unimodal distribution | Any single summary to be meaningful | Mean sits in an empty gap, SD describes nothing real | Plot the data |
| Approximate normality | The confidence interval for the SD only | The chi-square interval becomes unreliable | Q-Q plot, or treat the interval as indicative |
| Common variance across groups | The pooled SD only | Pooling produces a number describing no real group | Variance ratio between groups |
Limitations worth stating in a write-up
- It says nothing about shape. Two datasets can share a mean and an SD and look entirely different, as Example 8 demonstrates in a milder form. Always plot as well as summarise.
- It is not robust. One extreme value can multiply it several times over, and the SD gives you no warning that this has happened. Only comparing against a robust measure reveals it.
- It is itself an estimate with wide uncertainty. From twelve observations the 95% interval spans a factor of 2.4. Claims that one small group is more variable than another are usually unsupportable.
- The n − 1 correction gives an unbiased variance, not an unbiased SD. Because the square root is non-linear, s remains very slightly biased low. The effect is tiny and almost nobody corrects for it, but the precise claim matters.
- The empirical rule requires bell-shaped data. On skewed data the 68 and 95 percent landmarks can be substantially wrong.
- Grouped calculations are approximations. Class midpoints discard within-class variation, and open-ended classes force you to invent a value.
- The coefficient of variation needs a ratio scale. It is meaningless for temperatures in Celsius, for anything that can be negative, and for scales with an arbitrary zero.
- The old computational formula is numerically unsafe. On large values it can return zero or even a negative variance. This is a property of floating-point arithmetic, not of your data.
- An SD without n cannot be judged. The same figure means very different things from 5 observations and from 500.
🏁 17. Conclusion
The standard deviation is the average distance of your values from their mean, expressed in the same units as your data. You subtract the mean from each value, square the results so they cannot cancel, average those squares, and take the square root to get back to your original units. Everything else on this page follows from those four steps.
The one decision that trips people up is the divisor. Divide by n − 1 when your data are a sample from something larger, which is nearly always, and by N only when the values you have are the entire group you want to describe. The correction exists because the sample mean sits closer to your own data than the true population mean does, so the sum of squared deviations comes out too small every time. The gap between the two versions is 12% at n = 5, 1.7% at n = 30 and 0.5% at n = 100, which tells you where to spend your attention. This calculator shows both side by side so the choice is deliberate rather than accidental.
Three distinctions are worth keeping straight. Standard deviation is not standard error: the first describes how spread out your data are and does not shrink as you collect more, while the second describes how precisely you know the mean and does. Reporting one when you meant the other is the most common error in published figures, and it is why every error bar needs a label. Pooled is not combined: the pooled SD estimates within-group spread and feeds a t-test, while the combined SD describes all your groups merged into one pile and is larger by exactly the amount the group means differ. Variance is not standard deviation: they carry identical information, but variance lives in squared units, which is why it drives the mathematics and the SD gets reported.
Two failure modes deserve real caution. Because deviations are squared, a single extreme value can dominate the result completely. In Example 3 one reading of 180 among heart rates in the 120s accounts for 90% of the entire sum of squares and multiplies the SD from 2.95 to 15.12. The classical figure gives you no hint that this has happened; only comparing it against a robust measure such as 1.4826 times the median absolute deviation reveals it, which is why this calculator reports both and flags the ratio. And the textbook shortcut formula, Σx² − (Σx)²/n, is algebraically correct but numerically unsafe: on the three values 100000001, 100000002 and 100000003 it returns a variance of zero when the true answer is one. This tool uses Welford's method and warns you whenever the two disagree.
Finally, remember that the standard deviation is an estimate with substantial uncertainty of its own. From twelve observations, an SD of 5.67 has a 95% confidence interval running from 4.02 to 9.63, an upper bound nearly two and a half times the lower one. It narrows slowly, needing around 200 observations to sit within about 10% either side. That is worth knowing before you claim one group is more variable than another.
Report the standard deviation with its mean and its sample size, say which divisor you used, label your error bars, check it against a robust measure when outliers are plausible, and plot the data as well as summarising it. Done that way it remains the single most useful description of spread in statistics.
❓ 18. Frequently Asked Questions
What is standard deviation in simple terms?
How do you calculate standard deviation?
Should I divide by n or n minus 1?
Why do we divide by n minus 1?
What is the difference between standard deviation and variance?
What is the difference between standard deviation and standard error?
What is a good or normal standard deviation?
Can standard deviation be zero or negative?
How does an outlier affect the standard deviation?
What is the 68-95-99.7 rule?
Why do R and Python give me different standard deviations?
np.std() defaults to dividing by N while R's sd() always divides by n − 1. Write ddof=1 in NumPy to match R. Confusingly, pandas goes the other way: df.std() defaults to n − 1, so NumPy and pandas disagree with each other within the same language and neither raises a warning.How do I calculate standard deviation in Excel?
=STDEV.S(range) for a sample and =STDEV.P(range) for a population. The P stands for population, not precise, and choosing it by mistake is common. For the sum of squared deviations use =DEVSQ(range), and for the standard error divide STDEV.S by SQRT(COUNT(range)).How do I find the standard deviation from grouped data?
What is a pooled standard deviation and how is it different from combining the data?
How accurate is a standard deviation from a small sample?
Why does my textbook formula give a different answer on large numbers?
Can I calculate a standard deviation from Likert scale data?
What does it mean if the standard deviation is bigger than the mean?
How many decimal places should I report?
Does a larger sample size reduce the standard deviation?
🔖 19. Cite This Tool
🔗 20. Related Calculators
📖 21. Glossary
| Term | Meaning |
|---|---|
| Standard deviation | The typical distance of values from their mean, in the original units. |
| Variance | The standard deviation squared. Same information, squared units. |
| s | The sample standard deviation, computed with n − 1. |
| σ (sigma) | The population standard deviation, computed with N. |
| Bessel's correction | Dividing by n − 1 instead of n, which removes downward bias in the variance. |
| Degrees of freedom | The number of values free to vary. One is used up estimating the mean. |
| ddof | The delta degrees of freedom argument in NumPy. ddof=1 gives the sample version. |
| Sum of squares | Σ(x − mean)², the numerator of the variance. |
| Standard error | SD divided by the square root of n. The precision of the mean, not the spread of the data. |
| Coefficient of variation | SD divided by the mean. Unitless, valid only on a ratio scale. |
| MAD | Median absolute deviation, the median of the distances from the median. |
| Robust SD | 1.4826 × MAD, scaled to match s for normal data but immune to outliers. |
| Range | Maximum minus minimum. Very sensitive to extremes. |
| Interquartile range | Q3 minus Q1, the spread of the middle half. Robust. |
| Pooled SD | A weighted combination of group SDs, estimating a shared within-group spread. |
| Combined SD | The SD of all groups merged into one dataset. Includes between-group variation. |
| Empirical rule | The 68-95-99.7 approximation, valid only for bell-shaped data. |
| Chebyshev's inequality | A weaker guarantee that holds for any distribution: at least 75% within two SDs. |
| Skewness | Asymmetry. High skew makes the mean and SD a poor summary. |
| Kurtosis | Tail heaviness relative to a normal distribution. |
| Grouped data | A frequency table. Standard deviations from it are approximations. |
| Class midpoint | The centre of a class interval, used as the value for every observation in it. |
| Welford's method | A numerically stable one-pass algorithm for the mean and sum of squares. |
| Catastrophic cancellation | Loss of precision when subtracting two nearly equal large numbers. |
| Computational formula | Σx² − (Σx)²/n. Algebraically correct, numerically unsafe. |
| Outlier | A value far from the rest. Squaring gives it outsized influence on the SD. |
| Volatility | The standard deviation of returns, in finance. |
| Z-score | A value expressed as a number of standard deviations from the mean. |
📚 22. References
- Pearson, K. (1894). Contributions to the mathematical theory of evolution. Philosophical Transactions of the Royal Society A, 185, 71-110. doi.org/10.1098/rsta.1894.0003
- Welford, B. P. (1962). Note on a method for calculating corrected sums of squares and products. Technometrics, 4(3), 419-420. doi.org/10.1080/00401706.1962.10490022
- Chan, T. F., Golub, G. H., & LeVeque, R. J. (1983). Algorithms for computing the sample variance: Analysis and recommendations. The American Statistician, 37(3), 242-247. doi.org/10.1080/00031305.1983.10483115
- Higham, N. J. (2002). Accuracy and Stability of Numerical Algorithms (2nd ed.). SIAM. doi.org/10.1137/1.9780898718027
- Rousseeuw, P. J., & Croux, C. (1993). Alternatives to the median absolute deviation. Journal of the American Statistical Association, 88(424), 1273-1283. doi.org/10.1080/01621459.1993.10476408
- Leys, C., Ley, C., Klein, O., Bernard, P., & Licata, L. (2013). Detecting outliers: Do not use standard deviation around the mean, use absolute deviation around the median. Journal of Experimental Social Psychology, 49(4), 764-766. doi.org/10.1016/j.jesp.2013.03.013
- Cumming, G., Fidler, F., & Vaux, D. L. (2007). Error bars in experimental biology. Journal of Cell Biology, 177(1), 7-11. doi.org/10.1083/jcb.200611141
- Altman, D. G., & Bland, J. M. (2005). Standard deviations and standard errors. BMJ, 331(7521), 903. doi.org/10.1136/bmj.331.7521.903
- Nagele, P. (2003). Misuse of standard error of the mean (SEM) when reporting variability of a sample. British Journal of Anaesthesia, 90(4), 514-516. doi.org/10.1093/bja/aeg087
- Barde, M. P., & Barde, P. J. (2012). What to use to express the variability of data: Standard deviation or standard error of mean? Perspectives in Clinical Research, 3(3), 113-116. doi.org/10.4103/2229-3485.100662
- Moore, D. S., McCabe, G. P., & Craig, B. A. (2021). Introduction to the Practice of Statistics (10th ed.). W. H. Freeman. macmillanlearning.com
- Tukey, J. W. (1977). Exploratory Data Analysis. Addison-Wesley. archive.org
- Huber, P. J., & Ronchetti, E. M. (2009). Robust Statistics (2nd ed.). Wiley. doi.org/10.1002/9780470434697
- Wilkinson, L., & the Task Force on Statistical Inference (1999). Statistical methods in psychology journals: Guidelines and explanations. American Psychologist, 54(8), 594-604. doi.org/10.1037/0003-066X.54.8.594
- American Psychological Association (2020). Publication Manual of the American Psychological Association (7th ed.). apastyle.apa.org
- Jamieson, S. (2004). Likert scales: How to (ab)use them. Medical Education, 38(12), 1217-1218. doi.org/10.1111/j.1365-2929.2004.02012.x
- Bland, J. M., & Altman, D. G. (1996). Statistics notes: Measurement error. BMJ, 312(7047), 1654. doi.org/10.1136/bmj.312.7047.1654
- Press, W. H., Teukolsky, S. A., Vetterling, W. T., & Flannery, B. P. (2007). Numerical Recipes: The Art of Scientific Computing (3rd ed.). Cambridge University Press. numerical.recipes
- Harris, C. R., et al. (2020). Array programming with NumPy. Nature, 585, 357-362. doi.org/10.1038/s41586-020-2649-2
- R Core Team (2024). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. r-project.org
