Formula Bro

Math and physics formulas, explained like you are new.


Batch Normalization

In one sentence: Batch normalization rescales a group of values so they average out to zero with a steady spread, then lets the network learn its own final scale and shift.

x̂i=xi−μBσB2+ϵyi=γx̂i+β\hat x_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}} \qquad y_i = \gamma \, \hat x_i + \beta

Read it out loud: “x-hat sub i equals x sub i minus mu sub B, divided by the square root of sigma sub B squared plus epsilon. Then y sub i equals gamma times x-hat sub i, plus beta. Here x sub i is one input value, and mu sub B is the average of the batch. Sigma sub B squared is the variance, a measure of spread, and epsilon is a tiny safety number. Gamma and beta are learned numbers. The Greek letters are mu, said myoo; sigma, said SIG-muh; epsilon, said EP-sih-lon; gamma, said GAM-uh; and beta, said BAY-tuh.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Mini-batch

A mini-batch is a small group of examples that the network processes together in one training step, such as 32 photos. Each neuron in a layer produces one value per example, so one neuron gives a whole list of values, one for each photo in the batch. Batch normalization works on the values from that group, not on the whole data set.

The mean, μB\mu_B, the average of a batch

The mean of a list is its average: add the values and divide by how many there are. The mean of 2, 4, 6 and 8 is (2+4+6+8)/4=5(2 + 4 + 6 + 8) / 4 = 5. The Greek letter mu, μ\mu (said myoo), is the usual symbol for a mean. The subscript BB says that the mean is taken over the mini-batch BB.

The variance, σB2\sigma_B^{2}, and the spread

The variance measures spread. Find the distance of each value from the mean, square each distance so that negatives count as positive, and average the squares. For the numbers 2, 4, 6 and 8 the distances from 5 are −3,−1,1,3-3, -1, 1, 3, their squares are 9,1,1,99, 1, 1, 9, and the average of the squares is 5. The Greek letter sigma, σ\sigma (said SIG-muh), is the usual symbol for spread, so σ2\sigma^{2} is the variance.

The square root, ⋅\sqrt{\cdot}, and standard deviation

The square root x\sqrt{x} is the number that, multiplied by itself, gives xx. Since 5≈2.236\sqrt{5} \approx 2.236, and 2.236×2.236≈52.236 \times 2.236 \approx 5, the square root of the variance 5 is about 2.236. That value is the standard deviation σ\sigma, the typical distance from the mean, in the same unit as the data.

Powers of ten, like 10−510^{-5}, and epsilon

A number such as 10−510^{-5} is a power of ten: the exponent says how many times to divide by 10. So 10−5=1/100000=0.0000110^{-5} = 1 / 100000 = 0.00001, a decimal point followed by four zeros and then a 1. The Greek letter epsilon, ϵ\epsilon (said EP-sih-lon), is a tiny positive number added inside the square root. It keeps the division safe when the spread is almost zero.

Learned scale γ\gamma and shift β\beta

γ\gamma (gamma, said GAM-uh) and β\beta (beta, said BAY-tuh) are two numbers that the network learns during training, in the same way that it learns its weights. γ\gamma multiplies the normalized values to set their spread, and β\beta is added to set their center. Many implementations start with γ=1\gamma = 1 and β=0\beta = 0, which leave the normalized values unchanged at the beginning.

What each symbol means

SymbolMeaning

xix_i

One input value from the mini-batch, for example one neuron’s value for one example in the batch. The subscript ii says which example it is. It has whatever unit the feature has, and in this example it is unitless.

μB\mu_B

The mean of the values in the mini-batch BB, their average. It has the same unit as xix_i. For the values 2, 4, 6 and 8 the mean is 5.

σB2\sigma_B^{2}

The variance of the batch values: the average of the squared distances from the mean. It measures spread. Its unit is the square of the unit of xix_i, so it can look large even when the spread is modest.

ϵ\epsilon

A tiny positive constant, about 10−510^{-5} in many implementations (the example uses 0.001), added inside the square root so that the division never divides by zero. It has the same unit as the variance and is chosen to be very small.

σB2+ϵ\sqrt{\sigma_B^{2} + \epsilon}

The square root of the variance plus epsilon, which is the typical spread of the batch in the same unit as xix_i. Dividing by it turns the spread into a standard size close to 1.

x̂i\hat{x}_i

The normalized value: the centered and rescaled xix_i, with mean 0 and variance close to 1 across the batch. It has no unit, because the units cancel when we divide by the spread.

γ\gamma

The learned scale factor, a number that the network chooses during training. It has no unit. It sets how spread out the layer’s outputs are, and many implementations start it at 1.

β\beta

The learned shift, a number that the network chooses during training. It has the same unit as the output of the layer. It sets the center of the outputs, and many implementations start it at 0.

yiy_i

The output for example ii after the scale and shift, which is passed on to the next layer. It has the same unit as the output of the layer.

The formula piece by piece

xi−μBx_i - \mu_B

Centering: subtract the batch average from one value. Values above the average become positive, values below it become negative, and the average itself becomes zero. In the example, the value 8 minus the mean 5 gives 3.

σB2+ϵ\sqrt{\sigma_B^{2} + \epsilon}

The spread of the batch, with the tiny epsilon added so that it is never zero. In the example, 5+0.001≈2.2363\sqrt{5 + 0.001} \approx 2.2363.

x̂i=xi−μBσB2+ϵ\hat{x}_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^{2} + \epsilon}}

Normalizing: the centered value divided by the spread, so the batch ends up with mean 0 and a spread close to 1. In the example, the value 8 becomes 3/2.2363≈1.34153 / 2.2363 \approx 1.3415.

yi=γx̂i+βy_i = \gamma \hat{x}_i + \beta

Scaling and shifting: multiply the normalized value by the learned γ\gamma, which sets the spread, and add the learned β\beta, which sets the center. In the example, γ=2\gamma = 2 doubles the spread and β=1\beta = 1 moves the center up to 1.

x̂i=xi−μBσB2+ϵyi=γx̂i+β\hat x_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}} \qquad y_i = \gamma \, \hat x_i + \beta

The whole rule in one sentence: each value is centered on the batch average and divided by the batch spread, then multiplied by gamma and shifted by beta, so the layer can learn its own final spread and center.

What the formula is doing, and why

What goes in and what comes out. Batch normalization takes a group of values for one feature or one neuron, taken from the examples in the mini-batch BB. It returns new values that are centered and scaled. Inside a deep network, the values that reach a layer keep shifting as the layers before it learn, so each layer receives values whose average and spread keep moving.

Why center and divide? The mean μB\mu_B is the average of the batch, and the variance σB2\sigma_B^{2} is the average squared distance from that mean. Subtracting μB\mu_B moves the center to zero. Dividing by the square root of the variance sets the spread to about 1. The tiny ϵ\epsilon sits inside the square root, so that a batch whose values are all equal, which has zero spread, does not cause a division by zero.

Why learn gamma and beta? Forcing every layer to a mean of 0 and a spread of 1 can throw away useful information. So each layer also gets two learned numbers, γ\gamma and β\beta. The output yi=γx̂i+βy_i = \gamma \hat{x}_i + \beta can take whatever spread and center training finds useful. If γ=1\gamma = 1 and β=0\beta = 0, the output equals the normalized values. If training chooses other numbers, the layer can even undo the normalization completely.

Where it applies, and prediction time. Batch normalization works best with reasonably large batches, because the mean and variance from a tiny batch are noisy. The paper that introduced it reported faster training, and the method became common in image models. When a model makes predictions one example at a time, there is no batch to average, so the layer uses running averages of the mean and variance that were collected during training.

An everyday picture

Think of a class whose test scores drift upward from one test to the next. Before comparing the results, a teacher rescales each test so the average is 0 and the typical spread is 1, which puts every test on the same footing. The learned γ\gamma and β\beta are like the teacher then choosing the grading scale that works best for the class.

Worked example: Four values in one mini-batch

Four examples go through one neuron in a mini-batch, and each gives one value: x=(2,4,6,8)x = (2, 4, 6, 8). Use ϵ=0.001\epsilon = 0.001, and the learned values γ=2\gamma = 2 and β=1\beta = 1. The values are unitless, as in a toy example.

  1. Find the mean of the batch. The mean tells us the center of the group. We add the four values, 2+4+6+8=202 + 4 + 6 + 8 = 20, and divide by 4, so μB=20/4=5\mu_B = 20 / 4 = 5. The center of this batch is 5.
  2. Find the variance of the batch. The variance is the average squared distance from the mean. The distances from 5 are −3,−1,1-3, -1, 1 and 33. Squaring gives 9,1,19, 1, 1 and 99, because squaring makes every distance positive. Their average is (9+1+1+9)/4=5(9 + 1 + 1 + 9) / 4 = 5, so σB2=5\sigma_B^{2} = 5.
  3. Compute the denominator. The denominator is the spread with epsilon added to keep it safe: 5+0.001=5.001≈2.2363\sqrt{5 + 0.001} = \sqrt{5.001} \approx 2.2363. The epsilon changes the answer by only a tiny amount, which is what it is designed to do.
  4. Normalize each value. Subtract the mean from each value and divide by the denominator. That gives x̂=(2−5)/2.2363,(4−5)/2.2363,(6−5)/2.2363,(8−5)/2.2363\hat{x} = (2 - 5) / 2.2363, \; (4 - 5) / 2.2363, \; (6 - 5) / 2.2363, \; (8 - 5) / 2.2363, which is about (−1.3415,−0.4472,0.4472,1.3415)(-1.3415, -0.4472, 0.4472, 1.3415). The new values average to 0. Their variance is 5/5.001≈0.99985 / 5.001 \approx 0.9998, which is very close to 1, as intended.
  5. Scale and shift. Each normalized value is multiplied by γ=2\gamma = 2, and then β=1\beta = 1 is added: y=2x̂+1y = 2\hat{x} + 1. The outputs are about (−1.6830,0.1057,1.8943,3.6830)(-1.6830, 0.1057, 1.8943, 3.6830). The scale of 2 doubles the spread, and the shift of 1 moves the center from 0 up to 1.
  6. Check the mean of the outputs. The mean of the outputs is γ×0+β=1\gamma \times 0 + \beta = 1, because the normalized values average to zero. Adding the outputs gives −1.6830+0.1057+1.8943+3.6830=4.0000-1.6830 + 0.1057 + 1.8943 + 3.6830 = 4.0000, and 4.0/4=1.04.0 / 4 = 1.0, which equals β\beta.

Answer: The four outputs have a mean of β=1\beta = 1, and their spread is set by γ=2\gamma = 2. The batch supplied the mean and the variance, and the learned γ\gamma and β\beta set the final spread and center.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

What is a mini-batch?

A small group of examples that the network processes together in one training step, such as 32 or 64 photos. The batch statistics come from that group.

Why does batch normalization need a batch?

Its mean and variance come from the examples in the batch. With one example there is no spread to measure, so at prediction time the layer switches to stored running averages.

Does batch normalization replace the learning rate?

No. The learning rate, the step size of training, still matters. Batch normalization changes the scale of the values each layer sees, which often allows a larger learning rate to work well.

What do gamma and beta do?

They are learned along with the other weights. They let each layer choose its own spread and center, so normalizing does not force one fixed scale.

Sources

  1. Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift, Ioffe and Szegedy (arXiv:1502.03167)
  2. Batch normalization, Wikipedia

| All AI & ML formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: ai-ml/batch-normalization.md.