Visual walkthrough — Batch normalization
We follow one tiny mini-batch of activations through all four operations, then handle the two cases that break naive BN (a constant batch, and single-example inference).
Step 1 — The problem, drawn as a cloud of dots
WHAT. We have a mini-batch: a small handful of numbers that one neuron produced, one per training example. Call them . Here is just how many examples are in the batch. We will use with values .
WHY. A neuron's job is to feed the next layer. But as training proceeds, these numbers drift — their center and their spread wander around. "Center" = where the dots sit on the number line on average. "Spread" = how far apart they are. A wandering center and spread is exactly the internal covariate shift the parent note warned about. To fix a drifting thing, we must first measure it.
PICTURE. The dots below live on a horizontal number line. Notice two facts we will attack in the next two steps: (1) the cloud's middle is nowhere near , and (2) the cloud is wide.
Step 2 — Find the center (the mean )
WHAT. Add all the numbers up, divide by how many there are. That balancing point is the mean.
Reading it term by term: is a compact instruction — "start at the first value , keep adding until the last value ." The out front turns that total into an average. For our batch: .
WHY. Before we can center the cloud on zero, we must know where its center currently is. is that "where." Why the mean and not, say, the median? Because the next steps (variance, and the gradient) are built from sums of squares, and the mean is the point that minimizes total squared distance — it is the natural companion to variance.
PICTURE. The yellow tick is the balance point . Imagine the number line as a see-saw with a dot's weight at each value: it balances exactly under the yellow tick.
Step 3 — Measure the spread (the variance )
WHAT. For each dot, measure its distance from the center, square that distance, then average the squares. That average is the variance; its square root is the standard deviation — a single number for "typical width of the cloud."
Term by term: is the signed gap of dot from the yellow tick — negative if it sits left of center, positive if right. Squaring does two jobs: it kills the sign (a gap of and are equally "far"), and it punishes far-away dots more. Averaging with gives one spread number.
For our batch, gaps are , squares , sum , so and .
WHY. To shrink the cloud to a standard width, we must first know its current width. Variance is that measurement. Why divide by and not ? BN deliberately uses the biased () estimator — it treats the batch as the whole world for this step, matching the parent note's formula.
PICTURE. Each red segment is a squared distance drawn as a little square whose side is the gap. The variance is the average area of those squares.
Step 4 — Standardize (subtract, then divide → )
WHAT. Slide the whole cloud left by so its center lands on ; then squeeze it by dividing every number by so its width becomes .
The numerator moves the cloud so its middle is at zero (this is the slide). The denominator is (almost) the standard deviation, so dividing by it makes the typical width equal to (this is the squeeze). The little (a tiny number like ) is a safety cushion — we meet it properly in Step 6.
For our batch, gaps divided by give Check: these average to and have variance . ✓
WHY. Now every neuron, in every layer, hands the next layer a cloud with the same center and the same width, no matter how the layers below drift. The next layer stops chasing a moving target — the core promise of BN, and why we can use larger, safer learning rates.
PICTURE. Two arrows tell the whole story: a yellow slide arrow moving the cloud onto , and a green squeeze bracket pulling the edges inward to width .
Step 5 — Give the freedom back (scale , shift → )
WHAT. After forcing center , width , we let the network re-choose its own center and width using two learnable knobs.
multiplies, so it sets the new width (a stretch if , a shrink if ). adds, so it sets the new center. Both are learned by gradient descent, exactly like weights — the network dials them to whatever it finds useful.
With : .
WHY. Forcing mean /var can cost the network expressive power — a neuron, for instance, needs inputs away from to behave nonlinearly. So we don't leave the network stuck at the standardized cloud; we hand it two dials. Crucially, if identity were best, it could set and to recover the original numbers. So BN never removes power — it only changes the starting point the network optimizes from.
PICTURE. The standardized cloud (from Step 4) sits at center , width ; the dials stretch and slide it to a chosen place. The gradients that train these dials come from Backpropagation.
Step 6 — Edge case: the constant batch ()
WHAT. What if every number in the batch is identical, e.g. ? Then every gap is , so , and the Step-4 denominator would be — a division by zero.
The in the denominator is what saves us: instead of (undefined) we get , a clean answer.
WHY. Real batches sometimes are constant (a dead ReLU, a saturated region). Without the whole forward pass would produce NaN and training would collapse. With it, a constant batch maps to all-zeros — meaning BN erases information that is constant across the batch. That is precisely why tiny batches hurt BN: with few examples, the mean/variance estimates are noisy or near-degenerate. In that regime prefer Layer Normalization or Group Normalization, which don't rely on a batch of examples.
PICTURE. All three dots stack on top of each other at ; the width is literally zero, the yellow center sits right on them, and the output collapses to .
Step 7 — Edge case: one example at test time (running stats)
WHAT. At inference you may get a single input — there is no batch to average over, so don't exist. Instead, during training BN quietly accumulates a running average of the batch statistics, and uses those fixed numbers at test time.
Here (a small number like ) is the update rate: each new batch nudges the running estimate a little toward the batch's own statistic, so becomes a smoothed picture of the whole training set. At test time:
Worked check. With and a single new input : , so .
WHY. Test outputs must be deterministic — the same must give the same regardless of who else is (or isn't) in the batch. Running statistics guarantee that. A bonus: since are now all fixed constants, the whole BN operation becomes one straight-line (affine) map that can be folded into the previous layer's weights — zero extra cost at inference.
PICTURE. A timeline of training batches, each nudging a slowly-moving running mean toward the true population center; at test the single dot is standardized by that frozen value.
The one-picture summary
Read this figure left to right: raw cloud → measure center → measure width → slide to → squeeze to width → apply learnable . Every arrow is one of the seven steps above.
Recall Feynman retelling of the whole walkthrough
You have a spilled handful of beads on a ruler. First you find the point where the ruler would balance — that's the mean. Then you measure how far the beads sprawl out on average — that's the spread. Now you do two clean moves: slide the whole handful so the balance point sits on the zero mark, and squeeze it so the sprawl becomes exactly one ruler-unit wide. Every neuron in the network now hands over beads arranged the same tidy way, so nobody downstream is surprised. Finally you give the network two dials — one to stretch the beads back out to whatever width it likes, one to slide them to whatever center it likes — because sometimes tidy-at-zero isn't what it wants, but now it starts from tidy instead of chaos. Two special cases: if all the beads landed on the exact same spot (zero spread) a tiny safety number keeps you from dividing by zero and the output is just zero. And when a single bead shows up at test time with no handful to average, you use a running memory of where past handfuls balanced and how wide they were — so the answer is always the same for the same bead.
Related: Training Deep Networks · Weight Initialization · Dropout · 3.2.08 Batch normalization (Hinglish)