Standard Deviation in Google Sheets: Which Function, and Why
In Google Sheets, =STDEV.S(range) is the sample standard deviation and =STDEV.P(range) is the population one. STDEV is the older name for STDEV.S. Exact formulas, a worked example and the errors that trip people up.
Key takeaways
- In Google Sheets, =STDEV.S(range) returns the sample standard deviation and =STDEV.P(range) returns the population standard deviation, while STDEV and STDEVP are the older names that Google lists as the same functions.
- For the eight values 2, 4, 4, 4, 5, 5, 7 and 9, STDEV.P returns exactly 2 and STDEV.S returns about 2.138, because the sample version divides the squared deviations (which sum to 32) by 7 instead of 8.
- The sample result is larger than the population result by a factor of the square root of n divided by n-1: 41.4% at n = 2, 5.4% at n = 10, 1.7% at n = 30 and 0.5% at n = 100.
- Google Sheets has no STDEVIF, so for a conditional standard deviation use =STDEV.S(FILTER(B2:B101, A2:A101 = "West")), which returns #DIV/0! for exactly one match and #N/A for none.
- STDEVA and STDEVPA behave like STDEV and STDEVP except that they set text to 0, and all six functions return #DIV/0! when given fewer than two values.
In Google Sheets, =STDEV.S(A2:A9) gives the standard deviation of a sample and =STDEV.P(A2:A9) gives it for a whole population. STDEV is the older name for STDEV.S, and STDEVP is the older name for STDEV.P.[3] Pick the wrong pair and your answer is off by 0.5% to 41%, depending on how many numbers you have.
Here's a dataset small enough to check by hand. Put 2, 4, 4, 4, 5, 5, 7 and 9 in cells A2 through A9. The mean is 5. STDEV.P returns exactly 2. STDEV.S returns about 2.138.[7] Same data, same sheet, two answers, and the rest of this post is about which one is yours.
Sample or population: pick the function in one question
The deciding question is whether your numbers are everything or a slice. If you measured every member of the group you're describing, that's a population. If you measured some members to learn about all of them, that's a sample. Most spreadsheet data is a sample, even when it doesn't feel like one.
Choosing the function
Is your data everything, or a slice of something bigger?
Your data is
- A sample500 survey answers out of a whole country
- The whole populationEvery transaction in a closed quarter
- Numbers mixed with text you want counted as 0Rare, and usually a mistake
Standard deviation
Pick the function that matches the data
Formula to type
- =STDEV.S(A2:A9)Divides by n − 1
- =STDEV.P(A2:A9)Divides by n
- =STDEVA(A2:A9) or =STDEVPA(A2:A9)Set text to 0
If you can't decide, use the sample version. It never understates the spread.
The exact formulas for all six functions
Google Sheets documents six standard deviation functions. Two have dotted aliases, and Google's function list points each alias at the older page: STDEV.S says “See STDEV” and STDEV.P says “See STDEVP.”[3]
=AVERAGE(A2:A9) 5
=STDEV.P(A2:A9) 2 population, divides by n
=STDEV.S(A2:A9) 2.138 sample, divides by n - 1
=STDEV(A2:A9) 2.138 same as STDEV.S
=STDEVP(A2:A9) 2 same as STDEV.P
=STDEVA(A2:A9) 2.138 sample, text counts as 0 (no text here)
=STDEVPA(A2:A9) 2 population, text counts as 0 (no text here)
=SQRT(VAR.S(A2:A9)) 2.138 the same number, built from variance| Function | Measures | Divisor | Text in a referenced cell |
|---|---|---|---|
| STDEV.S (alias of STDEV) | Sample | n − 1 | Ignored[1] |
| STDEV.P (alias of STDEVP) | Population | n | Ignored[2] |
| STDEVA | Sample | n − 1 | Counted as 0[4] |
| STDEVPA | Population | n | Counted as 0[5] |
My rule for any workbook another person will open: type the dotted names. STDEV and STDEVP differ by one letter and mean opposite things, so six months later nobody can tell whether =STDEV(A2:A101) was a decision or the first autocomplete suggestion. STDEV.S and STDEV.P state the assumption in the name.
Why the sample version is bigger
Both versions start the same way: subtract the mean from each value, square the result, and add those squares up. The only difference is what you divide by.[7] For our eight numbers, the squared deviations add to 32.
| Value | Minus the mean (5) | 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 |
| Sum | 32 |
Population: 32 / 8 = 4, and the square root of 4 is 2. Sample: 32 / 7 is about 4.571, and the square root is about 2.138. The divisor n − 1 is called Bessel's correction.
A sample's own mean sits closer to its own values than the true mean would, so dividing by n understates the spread, and dividing by n − 1 corrects most of that bias.[7]
The size of the gap depends only on n, and it's the square root of n / (n − 1). If your population standard deviation were exactly 1, here is what STDEV.S would return:
STDEV.P
STDEV.S
- n = 21.0001.414 (+41.4%)
- n = 51.0001.118 (+11.8%)
- n = 101.0001.054 (+5.4%)
- n = 301.0001.017 (+1.7%)
- n = 1001.0001.005 (+0.5%)
Takeaway
The choice matters for a column of 10 numbers and barely matters for 100. If your sheet has fewer than about 30 rows, spend the five seconds to choose deliberately.
Standard deviation of only some rows
The formula people need five minutes after the basic one is the spread of a subset. Sheets has no STDEVIF, which is the thing everyone searches for and gives up on. Use FILTER inside the function. For column B where column A says West:
=STDEV.S(FILTER(B2:B101, A2:A101 = "West"))
=STDEV.S(FILTER(B2:B101, A2:A101 = "West", C2:C101 > 100))FILTER takes each condition as its own argument, so the second line keeps only West rows where column C is above 100. Google's page shows the two-condition form but doesn't spell out how the conditions combine, so test it on a handful of rows before building a dashboard on it.[6]
Heads up
STDEV.S gets one number and returns #DIV/0!, because it needs at least two values.[1] If the filter matches no rows, FILTER itself returns #N/A before the standard deviation ever runs.[6] Neither is a bug in your data. Wrap the formula in IFERROR(..., "") only after you know which case you're hiding.What counts as a number: text, blanks and the n you actually got
Google's STDEV page says text in a referenced cell is ignored, and that text typed directly as an argument produces an error.[1]
So =STDEV.S(A2:A101) skips a stray “n/a” in the column but =STDEV.S("n/a", 3, 4) fails. The page says nothing about empty cells, so don't rely on memory for those either.
The habit that settles every one of these cases is comparing counts: =COUNT(A2:A101) counts numbers only, and =COUNTA(A2:A101) counts everything non-empty.
A formula that returns an empty string, such as IFERROR(..., ""), is text, so a column of them shrinks your n without any warning. When the two counts disagree, that gap is your answer.
When to use STDEVA and STDEVPA
Almost never. These two set each text value to 0 before calculating.[4] [5] That's useful in exactly one situation, where text in a cell really does mean zero, such as a “none” label in a count column.
In every other case it drags your mean down and inflates the spread. That's how one “N/A” in a data export turns a calm series into a volatile one.
What the number tells you, and where it lies
For roughly normal data, about 68.27% of values fall within one standard deviation of the mean, 95.45% within two, and 99.73% within three.[8] Pair AVERAGE with your standard deviation and you have a usable summary. For our example, mean 5 and population standard deviation 2 puts about two-thirds of values between 3 and 7.
That rule only holds for approximately normal data. Income, page views, file sizes and most things that follow a power law have heavy tails, where a few huge values dominate the spread and the standard deviation is technically correct and practically useless.
Take the logarithm first: =STDEV.S(ARRAYFORMULA(LN(A2:A101))) measures spread in proportional terms, which is how skewed data actually behaves. Or skip the standard deviation and describe the data with PERCENTILE.
Returns on a stock are the obvious case. Financial returns are heavy-tailed, so a standard deviation understates how large the worst days can get. What volatility actually means goes through that in detail, and why traders quote percentages instead of dollars explains why the inputs are usually percentage returns rather than dollar changes.
The one-line rule
A sample of anything: =STDEV.S(range). Every member of the group: =STDEV.P(range). A subset of rows: put FILTER inside. Heavy-tailed data: take logs or use percentiles.
That covers nearly every spreadsheet use I've come across. If you're also counting arrangements or combinations in the same workbook, the factorial behind them is in what is a factorial.
Sources and further reading
- 1.PrimaryGoogle Docs Editors Help, "STDEV". Syntax STDEV(value1, [value2, ...]), the two-value minimum and #DIV/0!, text in referenced cells ignored, and text typed as an argument returning an error.
- 2.PrimaryGoogle Docs Editors Help, "STDEVP". Population standard deviation, the two-value minimum, and equivalence to the square root of VARP.
- 3.PrimaryGoogle Docs Editors Help, "Google Sheets function list". STDEV.S listed as "See STDEV", STDEV.P as "See STDEVP", and the one-line descriptions of STDEVA and STDEVPA.
- 4.PrimaryGoogle Docs Editors Help, "STDEVA". Sample standard deviation that sets each text value to 0.
- 5.PrimaryGoogle Docs Editors Help, "STDEVPA". Population standard deviation that treats text as 0.
- 6.PrimaryGoogle Docs Editors Help, "FILTER". Syntax with multiple conditions, and #N/A when no values meet the conditions.
- 7.ReportingWikipedia, "Standard deviation". Population versus corrected sample formulas, Bessel's correction, and the worked example with 2, 4, 4, 4, 5, 5, 7, 9 (mean 5, squared deviations summing to 32).
- 8.ReportingWikipedia, "68–95–99.7 rule". The 68.27%, 95.45% and 99.73% shares for a normal distribution, and the caveat that fat tails break it.
Frequently asked questions
- How do I calculate standard deviation in Google Sheets?
- Type =STDEV.S(A2:A101) for a sample or =STDEV.P(A2:A101) for a whole population, replacing the range with your data. Use the sample version when your numbers are a subset of a larger group, which is the usual case. Both return a single number in the same units as your data.
- What is the difference between STDEV, STDEV.S and STDEV.P in Google Sheets?
- STDEV and STDEV.S both calculate the sample standard deviation, and STDEV.P calculates the population standard deviation. Google lists STDEV.S as "See STDEV" in its function list, so the two are the same function. The sample version divides by n-1 and the population version divides by n, so STDEV.S is always the larger of the two.
- Should I use STDEV.S or STDEV.P?
- Use STDEV.S when your data is a sample of a bigger group, such as 500 survey respondents out of a country. Use STDEV.P only when your data is every member of the group, such as every transaction in a closed quarter. If you are unsure, STDEV.S is the safer default, and the gap between the two shrinks to 0.5% by n = 100.
- How do I calculate standard deviation with a condition in Google Sheets?
- Wrap the range in FILTER: =STDEV.S(FILTER(B2:B101, A2:A101 = "West")). Google Sheets has no STDEVIF function. If the filter matches exactly one row you get #DIV/0!, and if it matches none you get #N/A, because FILTER returns #N/A when no rows meet the condition.
- Why does STDEV.S return #DIV/0! in Google Sheets?
- The function was given fewer than two numbers. Google documents that STDEV returns #DIV/0! when the total number of values supplied is below two, and the sample formula divides by n-1, which is 0 when n is 1. Check how many numbers the function actually sees with =COUNT(range).
- What do STDEVA and STDEVPA do differently?
- STDEVA and STDEVPA set each text value to 0 before calculating, where STDEV and STDEVP ignore text in referenced cells. STDEVA is the sample version and STDEVPA is the population version. You rarely want them, because counting text as zero drags the mean down and inflates the spread.
Written by
Tech Talk News Editorial
Computer engineering background. Writes about software, AI, markets, and real estate, and the places where the three meet.
More about the author