Index Ai Academy
Phase 2 · Math, when you need it · Probability & statistics

The normal distribution

The bell curve, and why it shows up everywhere.

About 25 minutes · A free account opens the whole lesson

Create a free account Try part of it here

Already have an account? Sign in to open this lesson

Why it matters

Measure the same kind of thing many times and the results often pile up in one familiar shape: a hump in the middle that thins out evenly on both sides. That shape is the bell curve, also called the normal distribution. It describes measurement noise. It describes how averages spread, which is why A/B tests (comparing two versions of a page or an ad) work. And many neural networks start from random numbers drawn from it. Learn its two numbers and a couple of rules of thumb, and you can look at a result and say "that's ordinary" or "that's three standard deviations out, something happened."

What you'll be able to do

  • Describe the normal distribution by its mean and standard deviation
  • Use the 68–95–99.7 rule and z-scores to judge how unusual a value is
  • Compute normal probabilities and percentiles with SciPy
  • Explain why sums and averages of many effects end up normal

What it covers

  1. A shape you already know
  2. The 68–95–99.7 rule
  3. z-scores: how far out is this?
  4. Worked example: placing test scores on the ruler
  5. Probabilities and percentiles with SciPy
  6. Why it shows up everywhere: the central limit theorem

A shape you already know

Picture a bakery that weighs every loaf it makes. The loaves are meant to be 500 grams. Most land close to that. Some are a little heavy and some a little light. Very few are far off in either direction.

Stack the weights into a bar chart and you get a bell: tall in the middle, sloping down evenly on both sides. This is the normal distribution. People also call it the Gaussian distribution, after the mathematician Carl Friedrich Gauss, or the bell curve.

Two numbers describe the whole bell. You met both in the last lesson:

  • The mean says where the middle is. Here it's 500 grams. Books write it μ\mu (mu, pronounced "mew").
  • The standard deviation says how wide the bell is. Books write it σ\sigma (sigma).

A small standard deviation gives a tall, narrow bell: the loaves are all much the same. A large one gives a low, wide bell: the weights vary a lot. Every bell curve is the same shape. Only its middle and its width change.

In plain words: a normal distribution is a symmetric bell. The mean sets where the middle is. The standard deviation sets how wide it is. The further a value sits from the middle, the rarer it is, and it gets rare fast.

Quick check
Two bakeries both average 500 grams, but one has a much larger standard deviation. How does its curve look?
  1. Exactly the same
  2. Taller and narrower
  3. Lower and wider
  4. Shifted to the right
Show the answer

Lower and wider

The mean sets where the middle is. A bigger standard deviation spreads the same total out, so the bell gets flatter.

Go deeper The formula for the bell

The height of the bell at any value xx is given by this formula:

f(x)=1σ2π e−(x−μ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}}\, e^{-\frac{(x - \mu)^2}{2\sigma^2}}

Here π\pi is the usual 3.14159. The letter ee is the number 2.718 from the exponentials and logarithms lesson.

Read it as: "take how far xx is from the middle, measure that distance in standard deviations, square it, halve it, and use it as a negative power of ee." The fraction in front only makes sure the total area under the bell comes to 1. The height is a density, not a probability. The chance of landing in a range is the area under the curve over that range.

You don't need to memorize it. What matters is the pattern. Take the standard bell, with mean 0 and standard deviation 1:

  • at the middle, x=0x = 0, the height is about 0.399;
  • one standard deviation out, it drops to about 0.242;
  • two out, about 0.054;
  • three out, about 0.004.

Each step away shrinks the height by a bigger share than the step before. That's why values far from the mean are so rare.

import math

def bell_height(x, mu, sigma):
    return math.exp(-(x - mu) ** 2 / (2 * sigma ** 2)) / (sigma * math.sqrt(2 * math.pi))

for x in [0, 1, 2, 3]:
    print(x, round(bell_height(x, 0, 1), 3))
It runs right here in your browser, with nothing to install.

Books often write "XX follows a normal distribution" as X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2). Read it as: "X is normal with mean mu and variance sigma squared." Note that the second number is the variance, the standard deviation squared.

The 68–95–99.7 rule

Every normal distribution shares three handy facts. Count outward from the mean in steps of one standard deviation:

How far from the meanShare of values inside that range
within 1 standard deviation, μ±1σ\mu \pm 1\sigmaabout 68%
within 2 standard deviations, μ±2σ\mu \pm 2\sigma (more precisely 1.96σ)about 95%
within 3 standard deviations, μ±3σ\mu \pm 3\sigmaabout 99.7%

The sign ± means "plus or minus": the range runs from the mean minus that amount to the mean plus that amount.

Back at the bakery, say the mean is 500 grams and the standard deviation is 10 grams:

  • about 68% of loaves weigh between 490 and 510 grams;
  • about 95% weigh between 480 and 520 grams;
  • about 99.7% weigh between 470 and 530 grams.

That leaves 0.3% outside 470 to 530. So a loaf more than 3 standard deviations from the mean turns up about 3 times in 1,000.

In plain words: about two thirds of values sit within one standard deviation of the mean. Nearly all sit within two. Almost none go past three.

Try it now

Draw 500 samples and check the readout. Close to 68% land within one standard deviation, whatever mean and σ you pick.

Quick check
Session length averages 180 seconds with σ = 40 seconds (roughly normal). About what share of sessions last between 100 and 260 seconds?
  1. About 50%
  2. About 99.7%
  3. About 68%
  4. About 95%
Show the answer

About 95%

100 is 180 − 80 and 260 is 180 + 80. 80 seconds is 2σ, so this is the range within 2 standard deviations of the mean: about 95%.

z-scores: how far out is this?

A day of 30 °C (86 °F) is hot for London in April. In Dubai in July, it's a mild day. A raw number means little until you know what's normal for that place.

A z-score solves this. It counts how many standard deviations a value sits from the mean. Then everything is on the same ruler, whatever the units:

z=x−μσz = \frac{x - \mu}{\sigma}

Here xx is the value you're checking. The answer, zz, is its z-score.

In plain words: subtract the average, then divide by the standard deviation. The answer is "how many standard deviations away". A positive z is above average and a negative z is below.

A small example. A class test averages 70 points with a standard deviation of 10. You scored 85. Your distance from the mean is 85 − 70 = 15 points. Divide by 10 and z=1.5z = 1.5. You're one and a half standard deviations above average.

Now a business example. A shop's daily orders average 420, with a standard deviation of 35. Today it got 520. That's z=(520−420)/35≈2.9z = (520 - 420) / 35 \approx 2.9, nearly three standard deviations up. Fewer than 0.5% of ordinary days reach that high. So it's worth a look: maybe an influencer mentioned the shop, or maybe a tracking bug is counting orders twice.

Worked example

Worked example: placing test scores on the ruler

The class test averages 70 with a standard deviation of 10. Work out the z-score for four students who scored 85, 60, 70 and 98.

mu, sigma = 70, 10   # class average and standard deviation

for score in [85, 60, 70, 98]:
    z = (score - mu) / sigma
    print(score, "z =", z)
In the lesson you can change this and run it.

85 is 1.5 standard deviations above average: a good score, but not a rare one. 60 has z = −1.0, one standard deviation below. A score exactly at the mean has z = 0. 98 has z = 2.8. If the scores are roughly bell-shaped, the 68–95–99.7 rule says under 2.5% of the class would score that far above the mean, so it's a standout result.

Quick check
What does this print?
mu, sigma = 50, 5
print((40 - mu) / sigma)
  1. 0.5
  2. 2.0
  3. -10
  4. -2.0
Show the answer

-2.0

40 − 50 is −10, and dividing by 5 gives -2.0. The value is two standard deviations below the mean, so its z-score is negative.

Probabilities and percentiles with SciPy

The rule of thumb covers 1, 2 and 3 standard deviations. For any other value, let the computer work out the area under the bell. The SciPy library's scipy.stats.norm has three functions for this:

  • cdf gives the chance of a value at most x. (The name stands for "cumulative distribution function".)
  • sf gives the chance of a value at least x: the upper tail. (Short for "survival function".)
  • ppf goes the other way. You give it a percentile and it gives back the value. It undoes cdf.

A percentile is a value with a given share of results below it. The 95th percentile is the value that 95% of days fall below.

from scipy.stats import norm

mu, sigma = 420, 35
print("P(orders <= 450):", round(norm.cdf(450, mu, sigma), 4))
print("P(orders >= 520):", round(norm.sf(520, mu, sigma), 4))
print("95th percentile:", round(norm.ppf(0.95, mu, sigma), 1))
print("z for the middle 95%:", round(norm.ppf(0.975), 3))

Read the four answers like this:

  • About 80% of ordinary days have 450 orders or fewer.
  • Only about 2 days in 1,000 reach 520 or more.
  • 95% of days stay below about 478 orders.
  • The middle 95% of any normal distribution runs from 1.96 standard deviations below the mean to 1.96 above.

When you leave out the mean and standard deviation, SciPy uses the standard bell (mean 0, standard deviation 1). That's why the last line gives a z-score. That number, 1.96, is the one behind every "95% confidence interval", which you'll meet when you estimate from samples.

Quick check
With daily orders averaging 420 and σ = 35, norm.sf(520, 420, 35) prints about 0.0021. What does that mean?
  1. 520 is the 0.21st percentile
  2. Today's 520 orders were a tracking bug
  3. About 2 ordinary days in 1,000 have 520 orders or more
  4. About 2 ordinary days in 1,000 have 520 orders or fewer
Show the answer

About 2 ordinary days in 1,000 have 520 orders or more

sf is the upper tail: the chance of a value at least 520. It can't tell you the cause, only that such a day is rare.

Why it shows up everywhere: the central limit theorem

Roll one die. Each face from 1 to 6 is equally likely, so a chart of the results is flat. Now roll ten dice and take their average. Averages near 3.5 are common, because highs and lows tend to cancel out. Averages near 1 or 6 need every die to come up low (or high) together, and that almost never happens. Chart many of those averages and you get a bell.

The same thing happens with almost any random effects. Add up or average many of them, and the total comes out roughly normal, whatever shape each single effect has. The effects must be independent, meaning one doesn't sway another. This is the central limit theorem.

In plain words: single values can have any shape. Averages of many independent values come out close to a bell.

Single orders are often lopsided: many small ones and a few huge ones. But the average of a day's orders is close to normal. That's why statistics built on the bell curve works for conversion rates and averages. The code below makes 5,000 pretend days of 40 orders each. On the left are single orders. On the right are the daily averages.

import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(0)
orders = rng.exponential(scale=60, size=(5000, 40))     # lopsided: many small orders, a few large
fig, axes = plt.subplots(1, 2, figsize=(8, 3))
axes[0].hist(orders[:, 0], bins=50)
axes[0].set_title("single orders (skewed)")
axes[1].hist(orders.mean(axis=1), bins=50)
axes[1].set_title("averages of 40 orders (bell-shaped)")

The left chart piles up near zero and trails off to the right. The right chart is a bell. Keep in mind that the theorem is about sums and averages. Single orders, incomes and page views often aren't normal at all, so check the shape before you lean on the 68–95–99.7 rule.

For later: neural network weights usually start as small random draws from a normal distribution (scaled by layer size), and diffusion image models work by gradually adding and then removing normal noise.

Quick check
Which of these is most likely to follow a bell curve?
  1. Which face comes up when you roll one die
  2. The average order value for each day, where every day has 40 orders
  3. The incomes of individual customers
  4. The value of single orders, where most are small and a few are huge
Show the answer

The average order value for each day, where every day has 40 orders

The central limit theorem is about averages and sums of many independent effects. Single values, like one order, one income or one roll, can have any shape.

Practice what you just read

  • 4 code examples you can edit and run
  • a practice exercise that checks your code
  • a 5-question quiz
  • 4 review cards for spaced repetition

Create a free account

Try a quiz question

What does the central limit theorem say?

  1. Averages (or sums) of many independent effects are approximately normal, whatever each effect's distribution
  2. All data is normally distributed, once you've collected enough of it, whatever it measures and however it was gathered
  3. The mean of any large sample equals its median, so for big datasets you can use whichever is simpler to work out
  4. Large samples have no variance, because the ups and downs all cancel, so any estimate from one can be treated as exact

Answer it at the end of the lesson to see if you're right, and why.

Before this lesson