TExcelTAD
Home › Probability Theory › The Normal Density

The Normal Density

The bell curve appears whenever many small independent effects add up: measurement errors, heights, test scores, the sum of many dice. The central limit theorem explains why. This lesson covers its density, its standardization and the rules of thumb for its tails. Reading normal tables and z-scores is covered in the Statistics course.

The density

The standard normal ZZ has density

ϕ(z)=12πe−z2/2\phi(z) = \frac{1}{\sqrt{2\pi}} e^{-z^2/2}

with mean 0 and variance 1. A normal variable with mean μ\mu and standard deviation σ\sigma is X=μ+σZX = \mu + \sigma Z, with density 1σ2πe−(x−μ)2/(2σ2)\frac{1}{\sigma\sqrt{2\pi}} e^{-(x - \mu)^2/(2\sigma^2)}. The constant 2π\sqrt{2\pi} comes from the Gaussian integral ∫−∞∞e−z2/2 dz=2π\int_{-\infty}^{\infty} e^{-z^2/2}\,dz = \sqrt{2\pi}.

The CDF Φ(z)\Phi(z) has no formula in elementary functions, but Python computes it through the error function: Φ(z)=12(1+erf⁡(z/2))\Phi(z) = \frac{1}{2}\left(1 + \operatorname{erf}(z/\sqrt{2})\right).

python · try it yourself
import math

Phi = lambda z: 0.5 * (1 + math.erf(z / math.sqrt(2)))
for k in [1, 2, 3, 4, 6]:
    inside = Phi(k) - Phi(-k)
    print(f"within {k} sd: {inside:.6f}   outside: {1 - inside:.2e}")
print("97.5% quantile ~", 1.96, "->", round(Phi(1.96), 4))
within 1 sd: 0.682689   outside: 3.17e-01
within 2 sd: 0.954500   outside: 4.55e-02
within 3 sd: 0.997300   outside: 2.70e-03
within 4 sd: 0.999937   outside: 6.33e-05
within 6 sd: 1.000000   outside: 1.97e-09
97.5% quantile ~ 1.96 -> 0.975

This is the 68–95–99.7 rule: about 68% of values lie within one standard deviation, 95% within two, 99.7% within three. "Six sigma" corresponds to about 2 in a billion outside.

Standardization

To find probabilities for XX with mean μ\mu and standard deviation σ\sigma, convert to z=(x−μ)/σz = (x - \mu)/\sigma. If response times are normal with mean 120 ms and standard deviation 15 ms, the fraction above 150 ms is 1−Φ(2)≈2.3%1 - \Phi(2) \approx 2.3\%.

Sums of normals

If XX and YY are independent normals, X+YX + Y is normal with mean μX+μY\mu_X + \mu_Y and variance σX2+σY2\sigma_X^2 + \sigma_Y^2 (see Sums of Continuous Variables). Standard deviations do not add; variances do.

python · try it yourself
import numpy as np

rng = np.random.default_rng(1)
x = rng.normal(10, 3, 500_000)
y = rng.normal(5, 4, 500_000)
s = x + y
print("mean of sum:", round(s.mean(), 3), " sd of sum:", round(s.std(), 3), " predicted sd:", np.sqrt(3 ** 2 + 4 ** 2))
print("fraction within 1 sd:", round((np.abs(s - 15) < 5).mean(), 4))
mean of sum: 15.001  sd of sum: 4.996  predicted sd: 5.0
fraction within 1 sd: 0.6832

Generating normal samples

The Box–Muller transform turns two independent uniforms into two independent standard normals:

Z1=−2ln⁡U1cos⁡(2πU2),Z2=−2ln⁡U1sin⁡(2πU2)Z_1 = \sqrt{-2\ln U_1}\cos(2\pi U_2), \qquad Z_2 = \sqrt{-2\ln U_1}\sin(2\pi U_2)

It works because, in polar coordinates, two independent normals have an exponentially distributed squared radius and a uniform angle.

python · try it yourself
import math
import random

rng = random.Random(5)
zs = []
for _ in range(100_000):
    u1, u2 = 1 - rng.random(), rng.random()
    r = math.sqrt(-2 * math.log(u1))
    zs += [r * math.cos(2 * math.pi * u2), r * math.sin(2 * math.pi * u2)]
m = sum(zs) / len(zs)
v = sum((z - m) ** 2 for z in zs) / len(zs)
print("mean", round(m, 4), " variance", round(v, 4))
print("within 1, 2, 3 sd:", [round(sum(abs(z) < k for z in zs) / len(zs), 4) for k in (1, 2, 3)])
mean 0.0007  variance 1.0035
within 1, 2, 3 sd: [0.6818, 0.9543, 0.9974]

In software

Neural network weights are initialised from scaled normals (Xavier/He initialization), diffusion models add and remove Gaussian noise, and Gaussian processes model unknown functions. Monitoring uses "3 sigma" alert thresholds, which only make sense if the metric is roughly normal; latencies usually are not (they have long right tails), which is why percentiles are preferred.

Exercises

Exercise 1: Response times

Response times are normal with mean 120 ms and standard deviation 15 ms. What fraction lies between 105 and 150 ms?

Answer

About 0.8190.819.

Solution

zz from −1-1 to 22: Φ(2)−Φ(−1)≈0.9772−0.1587=0.8186\Phi(2) - \Phi(-1) \approx 0.9772 - 0.1587 = 0.8186.

Exercise 2: Sum of two parts

Two parts have independent normal lengths with means 40 mm and 60 mm and standard deviations 0.3 mm and 0.4 mm. What is the standard deviation of the assembled length?

Answer

0.5 mm.

Solution

Variances add: 0.09+0.16=0.250.09 + 0.16 = 0.25, so the standard deviation is 0.50.5.

Exercise 3: Quantile by bisection (code)

Find zz with Φ(z)=0.99\Phi(z) = 0.99 by bisection using math.erf.

Answer

z≈2.3263z \approx 2.3263.

Solution

Φ\Phi is increasing, so bisection on [0,5][0, 5] converges.

python · try it yourself
import math

Phi = lambda z: 0.5 * (1 + math.erf(z / math.sqrt(2)))
lo, hi = 0.0, 5.0
for _ in range(60):
    mid = (lo + hi) / 2
    if Phi(mid) < 0.99:
        lo = mid
    else:
        hi = mid
print(round(lo, 4))
2.3263

Test yourself

About what fraction of a normal distribution lies within 2 standard deviations of the mean?

  1. 68%
  2. 90%
  3. 95%
  4. 99.7%

If XX and YY are independent normals with standard deviations 3 and 4, the standard deviation of X+YX + Y is…

  1. 7
  2. 5
  3. 12
  4. 1