How to Calculate Standard Deviation

By Udit Agarwal · Updated October 17, 2026

Standard deviation measures how spread out a set of numbers is: roughly, how far a typical value sits from the mean. To calculate it, find the mean, subtract it from every value, square the differences, average the squares (dividing by n for a whole population or by n − 1 for a sample) and take the square root. For the numbers 2, 4, 4, 4, 5, 5, 7 and 9, the mean is 5 and the population standard deviation is exactly 2.

What standard deviation tells you

An average on its own, such as the mean from the Mean, Median, Mode Calculator, hides how much the values differ. Two groups of eight students can both average 5 on a 10-point quiz:

  • Group A scored 2, 4, 4, 4, 5, 5, 7 and 9. The population standard deviation is 2.
  • Group B scored 4, 5, 5, 5, 5, 5, 5 and 6. The population standard deviation is 0.5.

Group B's scores all sit within a point of the mean; Group A's run from 2 to 9. Standard deviation puts that difference into one number, in the data's own unit. It is never negative, it is 0 only when every value is the same, and because the differences are squared, a single extreme value can inflate it sharply.

How to calculate standard deviation, step by step

Take Group A's scores: 2, 4, 4, 4, 5, 5, 7, 9.

  1. Find the mean. Add the values and divide by how many there are: 40 ÷ 8 = 5.
  2. Subtract the mean from each value. Each result is that value's deviation.
  3. Square each deviation, so every one becomes positive.
  4. Add the squares. The total is called the sum of squares.
  5. Divide by n for a population, or by n − 1 for a sample. The result is the variance.
  6. Take the square root of the variance. That is the standard deviation.
Value (x) Deviation (x − mean) Squared deviation
2 −3 9
4 −1 1
4 −1 1
4 −1 1
5 0 0
5 0 0
7 2 4
9 4 16
Total 0 32

If these eight students are the whole group you want to describe, divide by n = 8: the variance is 32 ÷ 8 = 4 and the standard deviation is √4 = 2. If they are a sample standing in for a larger group, divide by n − 1 = 7: the variance is 32 ÷ 7 ≈ 4.571 and the standard deviation is about 2.138.

The deviations always add up to zero, which is why they are squared before averaging. Squaring also gives large deviations more weight, so the standard deviation is usually larger than the plain average distance from the mean. Here that distance, called the mean absolute deviation, is 12 ÷ 8 = 1.5.

Variance and the square root

Variance is the average of the squared deviations, the number you have just before the last step: 4 for Group A as a population, or about 4.571 as a sample. Its symbols are σ² and s², because it is the square of the standard deviation.

Variance is handy in calculations, because the variances of independent quantities add up: the total of two dice has twice the variance of one die. Its unit is squared, though. Quiz scores in points have a variance in "points squared", which nobody can picture, so people report the square root: 2 points rather than 4 squared points.

Population vs sample standard deviation

Population Sample
Use it when The data is the entire group you care about The data is a subset standing in for a larger group
Divide by n n − 1
Formula σ = √(Σ(x − μ)² ÷ n) s = √(Σ(x − x̄)² ÷ (n − 1))
Spreadsheet function STDEV.P STDEV.S

Use the population formula when your numbers are the complete group you want to describe, such as every student in one class. Use the sample formula when they are part of a bigger group you want to learn about, such as 50 customers from a survey or ten bolts from a box of thousands. Most research and quality-control data is a sample, so when in doubt, use the sample formula. The NIST/SEMATECH e-Handbook of Statistical Methods uses n − 1 in its definition.

Why n − 1? The deviations are measured from the sample's own mean, which sits closer to the sample's values than the true population mean does, so the squared deviations come out slightly too small on average. Dividing by n − 1 instead of n corrects for this; the adjustment is called Bessel's correction, and it makes the sample variance an unbiased estimate of the population variance. Put another way, once the mean is known only n − 1 deviations can vary, because they must sum to zero.

The sample standard deviation is √(n ÷ (n − 1)) times the population one: about 6.9% larger for 8 values, 1.7% for 30 and 0.5% for 100. With a single value it cannot be calculated at all, because n − 1 is zero.

The 68–95–99.7 rule

For data that follows a normal distribution, the familiar bell curve, about 68% of values lie within 1 standard deviation of the mean, about 95% within 2 and about 99.7% within 3. The exact figures are 68.27%, 95.45% and 99.73%, and the pattern is called the empirical rule. If exam scores are roughly normal with a mean of 70 and a standard deviation of 10, about 68% of students scored between 60 and 80, about 95% between 50 and 90, and nearly all between 40 and 100. Exactly 95% lies within 1.96 standard deviations, the multiplier behind a 95% confidence interval.

A value's distance from the mean in standard deviations is its z-score: z = (x − mean) ÷ standard deviation. A score of 85 has z = (85 − 70) ÷ 10 = 1.5, higher than about 93.3% of scores on a normal curve. The Z-score Calculator turns any value into a z-score and a percentile.

The rule only fits roughly bell-shaped data, and for skewed data such as incomes or waiting times the percentages can be well off. Chebyshev's inequality gives a weaker guarantee that holds for any data: at least 75% of values lie within 2 standard deviations of the mean, and at least 88.9% within 3.

Standard deviation in Excel, Google Sheets and code

Each program names the two versions differently:

Software Sample (n − 1) Population (n)
Excel and Google Sheets STDEV.S, or the older STDEV STDEV.P, or the older STDEVP
Variance in Excel and Google Sheets VAR.S VAR.P
Python statistics module statistics.stdev statistics.pstdev
NumPy np.std(x, ddof=1) np.std(x), the default
pandas Series.std(), the default Series.std(ddof=0)
R sd(x) sd(x) * sqrt((n - 1) / n)
TI-83/84 calculators Sx σx

With Group A's scores in A2:A9, =STDEV.S(A2:A9) returns about 2.138 and =STDEV.P(A2:A9) returns 2. Microsoft's STDEV.S documentation confirms the n − 1 method. Note that NumPy and pandas have opposite defaults.

Common mistakes

  • Using the wrong divisor. A textbook, a spreadsheet and a calculator can disagree only because one divides by n and another by n − 1, so check which one is expected.
  • Confusing standard deviation with standard error. Standard deviation describes how individual values spread. The standard error of the mean, s ÷ √n, describes how precisely the sample mean estimates the population mean, and it shrinks as the sample grows: for Group A it is 2.138 ÷ √8 ≈ 0.756.
  • Comparing spreads on different scales. A standard deviation of 5 g is large for 50 g items and tiny for 5 kg ones. The coefficient of variation, standard deviation ÷ mean × 100, expresses spread as a percentage of the mean: 10% against 0.1%.
  • Missing an outlier. Type 90 instead of 9 in Group A's scores and the population standard deviation jumps from 2 to about 28.3.

Using the Standard Deviation Calculator

The Standard Deviation Calculator opens with Group A's scores filled in, so you can check the example above. Separate the numbers with commas, spaces, tabs, semicolons or new lines; a pasted spreadsheet column works as it is, and negative numbers and decimals are fine. It shows the count, sum, mean, both variances and both standard deviations, rounded to at most four decimal places, plus a steps table of deviations and squared deviations for the first 50 values. A copy button copies a plain-text summary.

With a single value, the sample figures read "Need ≥ 2 values". Anything that is not a plain number is skipped: $5 and 5% are dropped rather than read as 5, and since the comma separates values, 1,000 becomes two numbers, 1 and 0. Remove currency signs, percent signs and thousands separators first, and check that the count matches what you entered. The calculation runs in your browser and your numbers are not uploaded. For the median, quartiles and skewness, use the Statistics Calculator.

Frequently asked questions

How do you calculate standard deviation? Find the mean, subtract it from each value, square the results and add them up. Divide that total by n for a population or by n − 1 for a sample to get the variance, then take the square root. For 2, 4, 4, 4, 5, 5, 7, 9 the answer is 2 as a population or about 2.138 as a sample.

Should I use sample or population standard deviation? Use population when your data covers the entire group you are describing, and sample when it is a subset used to estimate a larger group. Survey, research and quality-control data is almost always a sample, so STDEV.S is the usual spreadsheet choice.

Why is the sample standard deviation larger? It divides the same sum of squares by n − 1 instead of n. That makes up for values sitting closer to their own sample mean than to the true population mean. With large samples the two figures are almost identical.

What is a good standard deviation? There is no universal good value; it depends on the unit and the scale. Judge it against the mean or a tolerance: 2 points is a wide spread on a 10-point quiz and a narrow one on a 1,000-point scale.

What is the difference between variance and standard deviation? Variance is the average squared deviation from the mean, and standard deviation is its square root. They carry the same information, but standard deviation is in the data's own unit, so it is easier to interpret.

What does it mean to be 2 standard deviations above the mean? The value's z-score is 2. For normally distributed data, only about 2.3% of values are that high or higher.

Keep going

Calculadora de Desvio Padrão

More guides

  • How to Add, Subtract, Multiply and Divide Fractions — How to add fractions with a common denominator, subtract, multiply, divide and simplify them, and convert mixed numbers and decimals, with worked examples.
  • Random Number Generators, Explained — How a random number generator works, how to pick a random number between 1 and 100, random numbers without repeats, modulo bias and real lottery odds.
  • How to Calculate Percentages — How to calculate percentage problems: X% of Y, what percent one number is of another, the percentage increase formula, reverse percentages and common mistakes.
  • Base64 Encoding, Explained — Base64 explained: how it turns binary into text, the alphabet and padding, the URL-safe variant, size overhead, use cases, and why it isn't encryption.
  • Linux File Permissions and chmod, Explained — What chmod 755, 644 and 777 mean: owner, group and others, read, write and execute, octal and symbolic modes, umask, setuid, setgid and the sticky bit.
  • DMS and Decimal Degrees, Explained — How to convert DMS to decimal degrees and back, how DD, DMS and DDM differ, how many decimal places you need, and which formats Google Maps and GPS accept.

All Math tools · All guides