beginnerstatistics

Variance & Standard Deviation

How spread out is your data? Two numbers that measure the same thing — in different units.

Key Points

What it is

Variance and standard deviation both answer the same question: how spread out is your data? The mean tells you where the center is — these two tell you how wide the data is around that center. Variance gets there by looking at how far each value is from the mean, squaring those gaps, and averaging them. Standard deviation is just the square root of that — which sounds like a small tweak, but it matters because it brings the number back into the same units as your data, making it actually readable.

Why it exists

The mean on its own can be misleading. A dataset of [49, 50, 51] and a dataset of [1, 50, 99] both have a mean of 50 — but they're completely different situations. The first is consistent and predictable. The second is all over the place. Variance and standard deviation exist to capture that difference. Without them, you'd have no way to talk about risk, reliability, or how much you can trust an average.

What it measures

Both measure how far individual values tend to stray from the mean. A variance of 0 means every single value is the same — no spread at all. As it grows, values are increasingly scattered. Standard deviation translates this into something readable: if you're measuring exam scores and the standard deviation is 10, it means a typical student scores within 10 points of the mean.

Intuition

Picture two coffee shops. Both serve coffee with an average temperature of 70°C. Shop A's standard deviation is 1°C — basically every cup is the same. Shop B's is 15°C — some cups are lukewarm, some are burning hot. The mean is identical. The standard deviation tells you which shop is actually consistent. In data science, a feature with high standard deviation has a lot of variation — which could mean it carries useful signal, or just a lot of noise.

Example

Dataset: [2, 4, 4, 4, 5, 5, 7, 9]. Mean = 5. Variance = 4. Standard Deviation = 2.

On average, each value sits about 2 units away from the mean of 5. The value 9 is 2 standard deviations above the mean. The value 2 is 1.5 standard deviations below. This gives you a sense of scale — what counts as 'close to average' and what counts as 'far out' for this particular dataset.

Formulas

Population Variance

σ2=1N∑i=1N(xi−μ)2\sigma^2 = \frac{1}{N}\sum_{i=1}^{N}(x_i - \mu)^2
  • σ² — population variance — pronounced 'sigma squared'. This is what we're calculating.
  • N — the total number of values — every single one in the group
  • xᵢ — each individual value in the dataset
  • μ — the mean of the dataset — pronounced 'mu'
  • (xᵢ − μ)² — how far each value is from the mean, squared. Squaring does two things: removes negatives, and makes large gaps count more

Sample Variance

s2=1n−1∑i=1n(xi−xˉ)2s^2 = \frac{1}{n-1}\sum_{i=1}^{n}(x_i - \bar{x})^2
  • s² — sample variance — used when you only have part of the data, not all of it
  • n−1 — dividing by n−1 instead of n gives a slightly larger, more honest estimate when you're working from a sample. Using just n would underestimate the spread.
  • x̄ — the sample mean — the average of your sample, not the whole population

Standard Deviation

σ=1N∑i=1N(xi−μ)2\sigma = \sqrt{\frac{1}{N}\sum_{i=1}^{N}(x_i - \mu)^2}
  • σ — standard deviation — just the square root of variance
  • √ — the square root undoes the squaring from the variance formula, bringing the unit back to normal — so if your data is in kg, standard deviation is also in kg

When to use

When not to use

Common mistakes

In practice

Standard deviation shows up constantly in data science. When you normalize features before training a model (called standardization), you subtract the mean and divide by the standard deviation — so every feature ends up on the same scale. Outlier detection often uses standard deviation as the measuring stick. When you run cross-validation and check how consistent a model's score is across folds, you're looking at variance in performance. And PCA — a technique for reducing the number of features — is entirely built around finding the directions where data varies the most.

Was this concept helpful?

Spot an error or gap? Suggest an edit →

Related concepts

mean-median-modenormal-distributionoutliersprobability-basicshypothesis-testing
Chirp at me!