---
title: The Gaussian and the central limit theorem
heading: Why so much randomness has the same bell shape
eyebrow: A11 · Lesson 16 · The Gaussian and the central limit theorem
xp: 40
---

::: hook
The noise voltage across a resistor is the combined effect of countless electrons jiggling independently. Nobody knows what any one of them does, and it doesn't matter: add up enough small independent effects, of almost any kind, and the total follows the same bell-shaped curve. That's the central limit theorem, and it's why the Gaussian distribution describes thermal noise, measurement scatter and manufacturing spread so well.

::: play
- Each draw is the sum of $k$ independent uniform random numbers, shifted and scaled to have mean 0 and standard deviation 1. The curve is the Gaussian with the same mean and spread.
- With $k = 1$ the histogram is flat, nothing like a bell. Raise $k$ to 2, then 3, then 12. How quickly does it take the Gaussian's shape?
- The readout counts the fraction of draws within ±1 of the mean. What does it settle near?
:::
:::

```sim plot
view: random
x: z = -4..4
slider: k = 1..30 step 1 = 1
sample: (rand(k) - k/2)*sqrt(12/k)
trials: 40000
bins: 48
density: exp(-z^2/2)/sqrt(2*pi)
measure: step(1 - abs(z)) | name: P1
measure: step(2 - abs(z)) | name: P2
readout: within ±1σ = 100*P1 %
readout: within ±2σ = 100*P2 %
```

::: predict
## A Gaussian noise voltage has standard deviation 1 mV. Roughly what fraction of the time is it more than 3 mV from zero?

- [ ] About 30%
- [ ] About 3%
- [x] About 0.3%
- [ ] Never

::: reveal
About 0.3%: the Gaussian's tails fall off very fast. Within ±1σ is about 68% of the time, ±2σ about 95%, and ±3σ about 99.7%. But "rarely" isn't "never": at a million samples a second, a 3σ spike happens thousands of times each second, and even 6σ events happen eventually. That tail is exactly what sets a digital link's error rate (lesson 41).
:::
:::

::: nameit
## The Gaussian distribution

**The density.** A Gaussian (or **normal**) variable with mean μ and standard deviation σ has

$$p(x) = \frac{1}{\sigma\sqrt{2\pi}}\,e^{-(x - \mu)^2/2\sigma^2}$$

Every Gaussian is the same curve, shifted and stretched. Subtracting the mean and dividing by σ gives the **standard normal**, $z = (x - \mu)/\sigma$, with mean 0 and σ = 1.

**How much is where:**

| Range | Fraction inside | Fraction outside |
|---|---|---|
| ±1σ | 68.3% | 31.7% |
| ±2σ | 95.4% | 4.6% |
| ±3σ | 99.73% | 0.27% |

**The tail.** The chance of landing more than $z$ standard deviations above the mean is the **Q function**:

$$Q(z) = P(Z > z) = \frac{1}{\sqrt{2\pi}}\int_z^\infty e^{-u^2/2}\,du$$

It has no simple formula, but tables and calculators give it: $Q(1) = 0.159$, $Q(2) = 0.0228$, $Q(3) = 0.00135$, $Q(6) \approx 10^{-9}$. Two tails together are $2Q(z)$.

**The central limit theorem.** Add up $n$ independent random variables, each with its own mean and variance, none dominating. As $n$ grows, the sum's distribution approaches a Gaussian, with mean $\sum\mu_i$ and variance $\sum\sigma_i^2$, whatever the shapes of the pieces. Adding twelve uniform numbers already gives a good bell, which is an old trick for making Gaussian noise. It explains why:

- **thermal noise** is Gaussian: it's the sum of the motions of enormous numbers of electrons;
- **measurement scatter** is often Gaussian: many small independent disturbances add;
- **manufacturing spread** is often Gaussian: many small process variations combine.

It also warns you when *not* to expect a Gaussian: when one cause dominates (a single bad batch, a power-line spike), or when effects multiply instead of add.
:::

::: example
## Resistors are Gaussian with mean 1000 Ω and σ = 5 Ω. What fraction is within ±1%?

::: solution
1. **Convert to standard deviations.** ±1% is ±10 Ω, which is ±2σ.
2. **Fraction inside.**
   $$1 - 2Q(2) = 0.954$$
   so 4.6% fall outside.

**Answer:** 95.4% of the resistors are within ±1%.
:::
:::

::: example
## A simple generator adds 12 independent uniform numbers on $[0, 1)$ and subtracts 6. What distribution does it approximate, and how often does it exceed 2?

::: solution
1. **One uniform.** Each has mean $\frac12$ and variance $\frac{1}{12}$.
2. **The sum minus 6.** Twelve of them add to mean 6 and variance 1, so the sum minus 6 has mean 0 and variance 1.
3. **Central limit theorem.** It's close to a standard Gaussian, so
   $$\begin{aligned} P(>2) &\approx Q(2) \\ &= 0.023 \end{aligned}$$
4. **Its limit.** It can never exceed 6, unlike a true Gaussian, but that's far out in the tail.

**Answer:** it approximates a standard Gaussian, and exceeds 2 with chance about 0.023.
:::
:::

::: example
## How often does Gaussian noise exceed 3σ, and 6σ, in either direction?

::: solution
1. **Beyond 3σ.**
   $$\begin{aligned} P(|X - \mu| > 3\sigma) &= 2Q(3) \\ &= 0.0027 \end{aligned}$$
   about 1 sample in 370.
2. **Beyond 6σ.**
   $$\begin{aligned} P(|X - \mu| > 6\sigma) &= 2Q(6) \\ &= 2.0 \times 10^{-9} \end{aligned}$$
   about 1 in 500 million.
3. **Six sigma in industry.** A "six sigma" process, even with its mean allowed to drift by 1.5σ, still makes only 3.4 defects per million.

**Answer:** Gaussian noise exceeds 3σ in about 1 sample in 370 (0.0027), and 6σ in about 1 in 500 million ($2.0 \times 10^{-9}$).
:::
:::

::: check
given: k = 1 | 1.5 | 2
answer: 100*erf(k/sqrt(2))
unit: %
tolerance: 0.5%

## What percentage of a Gaussian's values lie within ±{k}σ of its mean?

::: right
Right. {answer}. The whole-number cases are worth remembering: 68%, 95% and 99.7% for 1, 2 and 3σ.
:::

::: misses
- [100*(1 - Q(k))] That's everything below $+k\sigma$. Within ±kσ leaves out both tails: $1 - 2Q(k)$.
- [100*2*Q(k)] That's the fraction outside.
- [any] Not yet. Inside $= 1 - 2Q(k)$.
:::
:::

::: check
given: m = 1000 | 5000; s = 5 | 10 | 20; z = 1 | 2 | 3; let T = m + z*s
answer: Q(z)
tolerance: 1%

## A resistor's value is Gaussian with mean {m} Ω and σ = {s} Ω. What is the chance one is above {T} Ω?

::: right
Right. That's $z = (\given{T} - \given{m})/\given{s} = \given{z}$ standard deviations up: $Q(\given{z})$ = {answer}.
:::

::: misses
- [2*Q(z)] That counts both tails. "Above" is one tail.
- [1 - Q(z)] That's the chance of being below.
- [any] Not yet. Standardize, then use $Q(z)$.
:::
:::

::: check
given: m = 3 | 5; s = 0.1 | 0.2 | 0.5; x = 2 | 6
answer: (x - m)/s
tolerance: 0.5%

## A supply's output is Gaussian with mean {m} V and σ = {s} V. How many standard deviations from the mean is {x} V? (Give z with its sign.)

::: right
Right. $z = (x - \mu)/\sigma$ = {answer}.
:::

::: misses
- [(m - x)/s] Measure from the mean to the value: $x - \mu$.
- [x - m] Divide by σ to count standard deviations.
- [any] Not yet. $z = (x - \mu)/\sigma$.
:::
:::

::: check
given: s = 5 | 10; tol = 1 | 2 | 3
answer: 100*2*Q(tol*10/s)
unit: %
tolerance: 1%

## Resistors are made with mean 1000 Ω and σ = {s} Ω. What percentage fall outside ±{tol}% of 1000 Ω?

::: right
Right. ±{tol}% is ±{tol}0 Ω, which is $z = \given{tol}0/\given{s}$ standard deviations. Both tails: $2Q(z)$ = {answer}.
:::

::: misses
- [100*Q(tol*10/s)] Count both tails: too high and too low.
- [100*2*Q(tol/s)] ±{tol}% of 1000 Ω is ±{tol}0 Ω.
- [any] Not yet. Find z for the tolerance limit, then $2Q(z)$.
:::
:::

::: check
kind: choice

## A noise voltage is the sum of the effects of many independent electrons. What distribution should you expect it to have?

- [ ] Uniform
- [x] Gaussian
- [ ] Whatever distribution one electron's effect has
- [ ] It can't be predicted

::: right
Right. The central limit theorem: the sum of many small independent contributions is Gaussian, whatever each contribution's own distribution.
:::

::: misses
- [1] One uniform contribution is flat, but the sum of many is not.
- [3] Adding many of them reshapes the distribution into a bell.
- [4] The total is predictable in distribution, even if individual electrons aren't.
:::
:::

::: check
kind: parts
given: k = 1 | 2 | 3

## Gaussian noise, in standard deviations.

::: part
answer: 2*Q(k)
tolerance: 0.5%

### What fraction exceeds {k}σ in either direction?

::: misses
- [Q(k)] Both tails count.
- [any] $2Q(k)$.
:::
:::
:::

::: check
kind: derivation
vars: m = 900..1100, s = 1..20, x = 950..1050

## Resistors are Gaussian with mean $m$ and standard deviation $s$.

::: step
answer: (x - m)/s

### How many standard deviations is the value $x$ from the mean?
:::

::: step
answer: Q((x - m)/s)

### What fraction exceeds $x$?
:::

::: right
Right. Standardize, then use the tail function $Q$.
:::
:::

::: check
kind: python

## Write `within(t, s)` returning the fraction of Gaussian resistors (mean 1000 Ω, standard deviation `s` Ω) within ±`t` percent, using `math.erf`. Set `f1 = within(1, 5)` and `f2 = within(1, 10)`.

```python starter
import math

def within(t, s):
    return 1.0

f1, f2 = within(1, 5), within(1, 10)
print(f1, f2)
```

```python solution
import math

def within(t, s):
    z = 1000 * t / 100 / s
    return math.erf(z / math.sqrt(2))

f1, f2 = within(1, 5), within(1, 10)
print(f1, f2)
```

```python tests
assert abs(f1 - 0.954500) < 1e-5, f"±10 ohms is ±2 sigma: 95.45%; got {f1}."
assert abs(f2 - 0.682689) < 1e-5, f"±1 sigma holds 68.27%; got {f2}."
```

::: right
Right. $\text{erf}(z/\sqrt2)$ is the fraction within $\pm z\sigma$.
:::
:::

::: explain
## Why does adding many independent random effects produce a bell-shaped distribution, even if each effect on its own is flat?

::: model
To get an extreme total, nearly every effect has to land near its own extreme in the same direction, and there are very few ways for that to happen. Totals near the middle can be made in an enormous number of ways, with highs and lows canceling. As more effects are added, the count of ways piles up in the middle and thins out smoothly toward the edges, and that pile-up has the Gaussian shape whatever the shape of the individual pieces. Each piece only contributes its mean and variance to the result.
:::
:::

::: practice

::: check
given: z = 1 | 2 | 3
answer: 100*2*Q(z)
unit: %
tolerance: 1%

## What percentage of a Gaussian's values are more than {z}σ from the mean, either way?

::: misses
- [100*Q(z)] Both tails count.
- [any] $2Q(z)$.
:::
:::

::: check
given: m = 10..20 int; s = 2 | 5; z = 1 | 2
answer: m + z*s
tolerance: 0.5%

## A Gaussian has mean {m} and σ = {s}. What value is {z}σ above the mean?

::: misses
- [m + z] Multiply by σ.
- [any] $\mu + z\sigma$.
:::
:::

::: check
given: n = 3 | 48 | 108
answer: sqrt(n/12)
tolerance: 0.5%

## What is the standard deviation of the sum of {n} independent uniform numbers on [0, 1)?

::: misses
- [n/12] That's the variance.
- [sqrt(1/12)] That's one number's. Variances add.
- [any] Each has variance 1/12; add them, then take the square root.
:::
:::
:::
