Home › Excel functions › STDEV
Standard Deviation in Excel: STDEV.S and STDEV.P
Standard deviation tells you how far your numbers typically sit from the average. A low standard deviation means the values are close together; a high one means they're spread out. In Excel you calculate it with STDEV.S (for a sample) or STDEV.P (for a whole population).
In this guide
STDEV.S or STDEV.P?
| Function | Use it when | Example |
|---|---|---|
STDEV.S | Your data is a sample of a bigger group | A survey of 200 customers out of thousands |
STDEV.P | Your data is the whole group | The scores of every student in one class |
When in doubt, use STDEV.S: most data is a sample. The old STDEV function is the same as STDEV.S and still works, but Microsoft keeps it only for compatibility.
Worked example: test scores
| A | B | |
|---|---|---|
| 1 | Student | Score |
| 2 | Anna | 72 |
| 3 | Ben | 85 |
| 4 | Chris | 90 |
| 5 | Dana | 66 |
| 6 | Eli | 78 |
| 7 | Fay | 95 |
| 8 | Gus | 81 |
| 9 | Hana | 73 |
| Formula | Result |
|---|---|
=AVERAGE(B2:B9) | 80 |
=STDEV.S(B2:B9) | 9.74 |
=STDEV.P(B2:B9) | 9.11 |
The average score is 80 and the scores typically lie about 10 points above or below it. STDEV.P is a bit lower because it divides by the number of values (8), while STDEV.S divides by one less (7) to correct for working with a sample.
STDEV practice: try it yourself
Reading is one thing, typing it is another. Build the formula below step by step: the tips tell you what to type next, and you can click or drag across cells to add them, just like in Excel.
Task: Work out the standard deviation of the scores, in B10: =STDEV.P(B2:B9)
How Excel calculates it
- Take the average: 80.
- Subtract the average from each score and square the result: 64, 25, 100, 196, 4, 225, 1, 49.
- Add these up: 664.
- Divide by 7 for a sample (94.86) or by 8 for the population (83). This is the variance (VAR.S and VAR.P in Excel).
- Take the square root: 9.74 or 9.11.
Calculate it by hand with one formula
Want to see the steps above in a single formula, or check what STDEV.S returns? This formula subtracts the average from each score, squares the differences, adds them up, divides by the number of values minus one and takes the square root:
=SQRT(SUMPRODUCT((B2:B9-AVERAGE(B2:B9))^2)/(COUNT(B2:B9)-1))The result is 9.74, the same as STDEV.S. Leave out the -1 and you get 9.11, the population version. Prefer to see every step? Put =(B2-AVERAGE($B$2:$B$9))^2 in D2 and fill it down to D9: you get 64, 25, 100 and so on, and =SQRT(SUM(D2:D9)/7) gives the same 9.74.
Standard deviation with a condition
There's no STDEVIF. In Excel 365 you can combine STDEV.S with FILTER. With classes in column C:
=STDEV.S(FILTER(B2:B9, C2:C9="Class A"))In older versions, use =STDEV.S(IF(C2:C9="Class A", B2:B9)) and confirm with Ctrl+Shift+Enter.
Compare spread: coefficient of variation
A standard deviation of 10 is a lot for scores around 20 and little for scores around 1,000. To compare, divide by the average:
=STDEV.S(B2:B9) / AVERAGE(B2:B9)Format the cell as a percentage: 12%. The lower this number, the more consistent the data.
Related functions
- STDEVA / STDEVPA: also count text as 0 and TRUE as 1. Rarely what you want.
- VAR.S / VAR.P: the variance, the standard deviation squared.
- AVERAGE, MEDIAN: the centre of your data. See AVERAGE.
Keep learning
Frequently asked questions
Why do I get #DIV/0! with STDEV.S?
STDEV.S needs at least two numbers. Empty cells and text are ignored, so check whether your range really contains numbers.
Does STDEV ignore blank cells?
Yes. Blank cells and text in a range are skipped. A cell with 0 does count.
How do I show mean ± standard deviation?
Use =ROUND(AVERAGE(B2:B9),1) & " ± " & ROUND(STDEV.S(B2:B9),1), which shows 80 ± 9.7.
How do I add error bars with the standard deviation to a chart?
Select the chart, click the + button, tick Error Bars and choose Standard Deviation, or choose More Options › Custom to use your own calculated values.
How many values fall within one standard deviation?
Count them with =COUNTIFS(B2:B9, ">="&AVERAGE(B2:B9)-STDEV.S(B2:B9), B2:B9, "<="&AVERAGE(B2:B9)+STDEV.S(B2:B9)). In the example that's 5 of the 8 scores (between 70.3 and 89.7). For roughly bell-shaped data, expect about two thirds of the values within one standard deviation and about 95% within two.
How do I ignore errors or zeros?
One #N/A in the range makes STDEV.S return #N/A as well. =AGGREGATE(7, 6, B2:B9) calculates STDEV.S and skips errors (7 = STDEV.S, 8 = STDEV.P, 6 = ignore errors). To leave out zeros, for example from forms that weren't filled in, use =STDEV.S(IF(B2:B9<>0, B2:B9)); in versions before Excel 365, confirm it with Ctrl+Shift+Enter.
Can I calculate one standard deviation over several ranges?
Yes: =STDEV.S(B2:B9, D2:D9) treats both ranges as one set of numbers. Need a separate value per column? Then use one formula per column, such as =STDEV.S(B2:B9) and =STDEV.S(D2:D9).