Ko-fiSupport
Guides2026-12-02•Last updated: 2026-12-02•7 min read

Sample vs. Population Standard Deviation, Variance, and IQR Outlier Detection Explained

B

Brian De Vivar

• Tech Contributor at BrainyTools

Reviewed by Brian De Vivar — software developer & computer science educator with 20+ years of experience building software and teaching networking & systems engineering.

About the Author →
Sample vs. Population Standard Deviation, Variance, and IQR Outlier Detection Explained

Two teams report an average API response time of 50 ms. Team A's requests consistently land between 46 ms and 54 ms. Team B's requests bounce wildly between 12 ms and 240 ms. Reporting only the mean hides the entire operational story.

To measure spread accurately—and spot anomalous data points before they skew dashboards or machine-learning models—you need standard deviation, variance, and Interquartile Range (IQR) outlier fences. In this guide, we walk through the formulas, explain when to divide by $n$ versus $n - 1$, and show how to verify calculations instantly with the Standard Deviation Calculator and Descriptive Statistics Calculator.


Population ($\sigma$) vs. Sample ($s$) Standard Deviation

Standard deviation measures the typical distance of data points from the mean, expressed in the same units as your original measurements (milliseconds, dollars, kilograms).

Population Standard Deviation ($\sigma$)

Use the population formula when your dataset contains every single member of the group you are studying (for example, all 30 students in one specific classroom, or every server in a 12-node cluster):

$$\sigma = \sqrt{\frac{1}{N} \sum_{i=1}^{N} (x_i - \mu)^2}$$

Sample Standard Deviation ($s$)

Use the sample formula when your dataset is a subset drawn from a larger population (for example, 500 surveyed customers out of 200,000, or 100 latency probes sampled over an hour):

$$s = \sqrt{\frac{1}{n - 1} \sum_{i=1}^{n} (x_i - \bar{x})^2}$$

Why Divide by $n - 1$? (Bessel's Correction)

When you only have a sample, you do not know the true population mean $\mu$; you estimate it using the sample mean $\bar{x}$. Because $\bar{x}$ is calculated from those exact same points, the sample points naturally cluster slightly closer to $\bar{x}$ than they do to the true $\mu$. Dividing by $n$ systematically underestimates the true variance. Dividing by $n - 1$ (Bessel's correction) removes that downward bias so $s^2$ is an unbiased estimator of $\sigma^2$.


Worked Example: Step-by-Step Calculation

Consider five server response times (in ms): [42, 46, 50, 54, 58].

  1. Mean ($\bar{x}$):
    $$\bar{x} = \frac{42 + 46 + 50 + 54 + 58}{5} = 50\text{ ms}$$
  2. Squared Deviations from the Mean:
    • $(42 - 50)^2 = 64$
    • $(46 - 50)^2 = 16$
    • $(50 - 50)^2 = 0$
    • $(54 - 50)^2 = 16$
    • $(58 - 50)^2 = 64$
    • Sum of squared deviations = $64 + 16 + 0 + 16 + 64 = 160$
  3. Variance & Standard Deviation:
    • Population: $\sigma^2 = \frac{160}{5} = 32 \implies \sigma = \sqrt{32} \approx \mathbf{5.66\text{ ms}}$
    • Sample: $s^2 = \frac{160}{5 - 1} = 40 \implies s = \sqrt{40} \approx \mathbf{6.32\text{ ms}}$

You can paste any comma- or newline-separated dataset into the Standard Deviation Calculator to compute both $\sigma$ and $s$, variance, and step-by-step deviations automatically.


Why Standard Deviation Alone Fails on Skewed Data: Enter IQR Outliers

Standard deviation is sensitive to extreme values. Add a single garbage-collection spike of 500 ms to our dataset ([42, 46, 50, 54, 58, 500]), and the mean jumps from 50 ms to 125 ms, while the sample standard deviation explodes from 6.32 ms to 183.8 ms!

For skewed distributions (salaries, page load times, housing prices), statisticians pair median-based quartiles with Tukey's Interquartile Range (IQR) fences:

  1. Sort the dataset and find the 25th percentile ($Q_1$) and 75th percentile ($Q_3$).
  2. Compute the Interquartile Range:
    $$\text{IQR} = Q_3 - Q_1$$
  3. Define the outlier fences:
    • Lower Fence $= Q_1 - 1.5 \times \text{IQR}$
    • Upper Fence $= Q_3 + 1.5 \times \text{IQR}$

Any value falling below the lower fence or above the upper fence is flagged as a statistical outlier. Unlike Z-scores ($z = \frac{x - \bar{x}}{s}$), which assume a roughly bell-shaped normal distribution and get distorted by the very outliers they try to detect, IQR fences remain robust even when extreme spikes are present.


Worked IQR Outlier Example: Catching a Real Latency Spike

Let's apply Tukey's $1.5 \times \text{IQR}$ method step by step to an actual sorted set of 9 API response times (in ms):

Sorted values: [38, 41, 43, 45, 48, 50, 52, 55, 210]
  1. Median ($Q_2$): The middle (5th) value is 48 ms.
  2. Lower Quartile ($Q_1$): Median of the lower half [38, 41, 43, 45] $= \frac{41 + 43}{2} = \mathbf{42\text{ ms}}$.
  3. Upper Quartile ($Q_3$): Median of the upper half [50, 52, 55, 210] $= \frac{52 + 55}{2} = \mathbf{53.5\text{ ms}}$.
  4. Interquartile Range ($\text{IQR}$):
    $$\text{IQR} = Q_3 - Q_1 = 53.5 - 42 = \mathbf{11.5\text{ ms}}$$
  5. Tukey Fences:
    • Lower Fence: $42 - (1.5 \times 11.5) = 42 - 17.25 = \mathbf{24.75\text{ ms}}$
    • Upper Fence: $53.5 + (1.5 \times 11.5) = 53.5 + 17.25 = \mathbf{70.75\text{ ms}}$

Any observation below 24.75 ms or above 70.75 ms is flagged as an outlier. Here, 210 ms exceeds 70.75 ms by nearly 3× and is immediately isolated—without letting that single spike inflate the spread calculation the way it inflates standard deviation!


Understanding the Empirical Rule (68–95–99.7) and Z-Scores

When your data is approximately normally distributed (bell-shaped and symmetric—such as manufacturing tolerances, measurement noise, or standardized test scores), standard deviation unlocks the Empirical Rule:

  • ~68.27% of observations fall within $\pm 1\sigma$ of the mean ($\mu \pm \sigma$).
  • ~95.45% of observations fall within $\pm 2\sigma$ of the mean ($\mu \pm 2\sigma$).
  • ~99.73% of observations fall within $\pm 3\sigma$ of the mean ($\mu \pm 3\sigma$).

A Z-score standardizes any raw value $x$ into "number of standard deviations above or below the mean":

$$z = \frac{x - \bar{x}}{s}$$

This lets you compare scores measured on completely different scales (for example, comparing a student's $z = +1.8$ on a 100-point physics exam against $z = +1.2$ on a 1600-point standardized test). Just remember: never apply the 68–95–99.7 rule blindly to heavily skewed data—for example, if average income is $60,000 with $s = $50,000$, subtracting $2s$ predicts impossible negative incomes (-$40,000). Always check skewness and inspect a histogram first.


Quick Decision Guide: Which Metric Should You Report?

Distribution Shape Center Metric Spread Metric Outlier Rule
Symmetric / Bell-Shaped Mean ($\bar{x}$) Standard Deviation ($s$ or $\sigma$) $|z| > 3$ (or IQR fence)
Skewed (Latency, Income, Prices) Median ($Q_2$) IQR ($Q_3 - Q_1$) & Percentiles (P95/P99) $1.5 \times \text{IQR}$ Tukey fences
Multimodal (Two+ Peaks) Report modes separately Plot distribution first Inspect subpopulations

Should You Delete Outliers Automatically?

No—never delete an outlier blindly without investigating its cause:

  1. Data-entry or sensor errors (e.g., a thermometer logging -999°C or a duplicate decimal point 5000 instead of 50.00) should be corrected or removed and documented.
  2. Genuine extreme events (e.g., a Black Friday checkout spike, a real fraud transaction, or a cold-start latency tail) are often the most important signals in your dataset. Deleting them hides real business risk; instead, report both median/IQR and P95/P99 tail metrics.

Frequently Asked Questions (FAQ)

What is the difference between variance and standard deviation?

Variance ($s^2$ or $\sigma^2$) is the average of the squared deviations from the mean, so its units are squared (e.g., $\text{ms}^2$ or $\text{dollars}^2$). Standard deviation ($s$ or $\sigma$) is simply the square root of variance, bringing the number back into the original human-readable units.

Can standard deviation ever be negative or zero?

Standard deviation can never be negative because squared deviations are always non-negative. It equals zero only when every single observation in the dataset is identical (zero spread).

Why do Excel's STDEV.S and STDEV.P give different answers?

STDEV.S computes sample standard deviation (dividing by $n - 1$), while STDEV.P computes population standard deviation (dividing by $n$). As your sample size $n$ grows large (e.g., $n > 100$), the difference between $n$ and $n - 1$ becomes tiny—less than 0.5%.


Visualize Before You Summarize

Summary numbers can never replace looking at the shape of your data. After running your numbers through the Standard Deviation Calculator or Descriptive Statistics Calculator, plot the raw observations in the Interactive Histogram Maker to verify whether your data is symmetric, skewed, or hiding multiple clusters.

Enjoyed this article?

Check out our suite of free online developer tools to boost your productivity even further. 100% Privacy Focused.

Explore Tools