Formula Bro

Math and physics formulas, explained like you are new.


Layer Normalization

In one sentence: Layer normalization takes the list of numbers that describe one example, makes their average 0 and their spread about 1, so the numbers stay in a steady range whatever other examples are nearby.

x̂i=xi−μσ2+ϵyi=γix̂i+βi\hat x_i = \frac{x_i - \mu}{\sqrt{\sigma^2 + \epsilon}} \qquad y_i = \gamma_i \, \hat x_i + \beta_i

Read it out loud: “x-hat sub i equals x sub i minus mu, all divided by the square root of sigma squared plus epsilon. Then y sub i equals gamma sub i times x-hat sub i, plus beta sub i. Read mu as mew, sigma as SIG-muh, epsilon as EP-sih-lon, gamma as GAM-uh and beta as BAY-tuh. Here x sub i is one number in the list, mu is the average of the list, sigma squared measures how spread out the list is, and x-hat is the centered and rescaled number.”

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.

Greek letters and subscripts, like μ\mu, σ\sigma, ϵ\epsilon, γ\gamma, β\beta and xix_i

Greek letters are extra names for quantities, because the Latin alphabet runs out of letters. μ\mu is read mew and usually stands for an average. σ\sigma is read sigma, and σ2\sigma^2 is read sigma squared. ϵ\epsilon is epsilon, γ\gamma is gamma and β\beta is beta. A small number under a letter, such as xix_i, is a subscript that picks one item from a list. x1x_1 is the first item, and xix_i means the item at position ii, for whichever position is meant.

Average, variance and square root

The average, or mean, of a list is its sum divided by how many numbers there are. The variance measures how spread out the numbers are: take each number’s distance from the average, square each distance, and average those squares. Its unit is the square of the original unit. The square root, written ⋅\sqrt{\cdot}, undoes squaring, so 9=3\sqrt{9} = 3 because 3×3=93 \times 3 = 9.

Feature and vector

A feature is one number that describes an example, such as one test score or one measurement. A vector is a list of features treated as one object. In a transformer, the network design behind modern language models, each word is one vector, and its features are numbers that together describe that word’s meaning inside the model. Layer normalization works on one such list at a time.

Neural network, parameters and learned values

A neural network is a model made of many small calculators called neurons, and it learns its numbers from examples. The numbers it learns are called parameters or weights, and training adjusts them until the answers improve. The scale γi\gamma_i and the shift βi\beta_i are parameters of this kind. The model starts from 1 and 0, then changes them to whatever works best.

Hats on letters, like x̂i\hat{x}_i

A small hat over a letter, such as x̂i\hat{x}_i (read x-hat sub i), marks a new version of the same quantity. Here x̂i\hat{x}_i is the normalized version of xix_i: the value after the average has been subtracted and the result divided by the spread. The original xix_i is kept for the calculation, and the hat tells you which version you are reading.

Approximately equal, ≈\approx, and rounding

The sign ≈\approx means approximately equal. Many square roots have decimals that never end, so 125≈11.18\sqrt{125} \approx 11.18 is written after rounding to a few digits. Rounding changes only the last digits. When you check a step with a calculator, you should get the same first three or four digits, which is enough to confirm the answer.

What each symbol means

SymbolMeaning

xix_i

One feature of the example: a single number in its list of features. For example, one of a student’s four test scores, measured in points out of 100. It has the unit of the feature, so a score is measured in points.

μ\mu

The average of all the features of this one example. It is in the same unit as xix_i, so if the scores are in points, μ\mu is also in points. For a student whose four scores are 60, 70, 80 and 90, μ=75\mu = 75 points, the middle of the scores.

σ2\sigma^2

The variance of the features of this one example: the average of the squared distances from μ\mu. Its unit is points squared, which is hard to picture, so read it as a measure of spread. A small variance means the scores sit close together, and a large one means they are far apart.

ϵ\epsilon

A tiny positive number, such as 0.001, added so that the division never divides by zero. It has no unit. It is far smaller than a typical variance, so it changes the result very little, and it only matters when every feature is almost the same.

x̂i\hat x_i

The normalized feature: the original value after subtracting the average and dividing by the spread. It has no unit, because points divided by points cancel. Across the features of one example, the normalized values always average to 0, and their spread is close to 1.

γi\gamma_i

A learned scale for feature ii. It multiplies the normalized value and starts at 1, which leaves the value unchanged. It has no unit. Each feature has its own scale, so the model can make some features larger and others smaller as training goes on.

βi\beta_i

A learned shift for feature ii, added after the scaling. It starts at 0, which adds nothing. It has the same unit as the output, which is no unit here. Each feature has its own shift, which lets the model move the center of each feature away from zero if that helps.

yiy_i

The final output for feature ii, after the scale and shift are applied. It has no unit in this example. The layer passes these numbers on to the next part of the network, so each output is the input of the next calculation.

The formula piece by piece

xix_i

Start with the input: one feature, one number from the example’s list, such as one test score. Every other piece of the formula is built from these numbers together with their average and spread.

xi−μx_i - \mu

Subtract the average. After this step the numbers are centered on zero: a positive result means the feature is above the average of its example, and a negative result means it is below. The relative sizes of the features do not change, only their common offset is removed.

σ2+ϵ\sigma^2 + \epsilon

Build the safe spread. The variance measures how spread out the features are, and adding the tiny number epsilon means the bottom of the next fraction can never be zero, even when all the features are equal.

xi−μσ2+ϵ\frac{x_i - \mu}{\sqrt{\sigma^2 + \epsilon}}

Divide the centered value by the spread. Taking the square root turns the variance back into the original unit, so the result is a plain number. It tells you how many spreads a feature sits above or below the average of its example.

γix̂i+βi\gamma_i \, \hat x_i + \beta_i

Scale and shift. Multiply the normalized value by the learned scale, then add the learned shift. Starting values of 1 and 0 leave the normalized value unchanged, so the model begins with a plain normalization.

x̂i=xi−μσ2+ϵyi=γix̂i+βi\hat x_i = \frac{x_i - \mu}{\sqrt{\sigma^2 + \epsilon}} \qquad y_i = \gamma_i \, \hat x_i + \beta_i

Layer normalization centers and rescales each example’s own numbers, and then the model learns a scale and a shift for each feature, so every feature stays in a steady range.

What the formula is doing, and why

Layer normalization takes one example at a time and rescales its own numbers. The example might be a word in a sentence, described by a list of features. The formula does two things. First it subtracts the average μ\mu of those features, so the list is centered on zero. Then it divides by the spread, σ2+ϵ\sqrt{\sigma^2 + \epsilon}, so the typical size of the numbers is about 1. The result is the normalized value x̂i\hat x_i. The model then applies a learned scale and shift to get the final output yiy_i.

Why subtract the average? In a deep network the numbers passed between layers can drift far above or below zero. Large offsets make learning unstable. Subtracting μ\mu moves the whole list so that its average is exactly 0. Nothing about the relative sizes of the features changes, because every feature moves by the same amount.

Why divide by the spread? If the numbers are very large, the next layer receives huge inputs; if they are tiny, it receives weak inputs. Dividing by the square root of the variance puts the list on a common scale. The variance is in squared units, so the square root is needed to bring the spread back to the unit of the features. Epsilon is added so that a list whose features are all equal, with zero spread, does not cause a division by zero.

Why per example? Batch normalization, the older method, takes its averages over a batch of many examples. Layer normalization only uses the features of the one example in front of it. So the result for an example is the same whether it runs alone or in a group. This matters in transformers, because sentences have different lengths and each word is handled on its own.

Why learn a scale and a shift? Centering and scaling force every example into the same average and spread, which may not suit every feature. The learned scale γi\gamma_i and shift βi\beta_i let the model restore whatever center and spread it needs. They start at 1 and 0. Layer normalization needs a list with at least two features to be useful, because a list of a single number has zero spread, and then the output is only the shift β\beta.

An everyday picture

Think of a music app that evens out the loudness of one song by itself. It measures the average loudness of that song and how much its volume jumps around, then rescales the whole song using only those two numbers. It does not compare the song with the rest of the playlist, so the song sounds the same no matter which songs were played before or after it. Layer normalization treats one example’s features in the same way.

Worked example: Four test scores from one student

One student has four test scores, x=(60,70,80,90)x = (60, 70, 80, 90), each in points out of 100. Think of these four numbers as the four features of one example. Use ϵ=0.001\epsilon = 0.001 and the starting values γi=1\gamma_i = 1 and βi=0\beta_i = 0, so the scale does nothing and the shift adds nothing at the start. The scores are in points, so the variance is in points squared.

  1. Find the average score. The average, μ\mu, tells us the center of this student’s four scores. We add the scores and divide by how many there are: μ=60+70+80+904=3004=75\mu = \frac{60 + 70 + 80 + 90}{4} = \frac{300}{4} = 75 points.
  2. Measure each score’s distance from the average. Next we see how far each score sits from 75, with a plus sign if it is above and a minus sign if it is below. The distances are 60−75=−1560 - 75 = -15, 70−75=−570 - 75 = -5, 80−75=580 - 75 = 5 and 90−75=1590 - 75 = 15 points. They add up to zero, which is always true when distances are measured from the average.
  3. Square the distances and average them. Squaring makes every distance positive, so the signs stop mattering for the spread. The squares are 225225, 2525, 2525 and 225225 points squared, and their sum is 500. Dividing by four gives the variance: σ2=5004=125\sigma^2 = \frac{500}{4} = 125 points squared.
  4. Build the bottom of the fraction. We add the tiny epsilon to the variance and take the square root: 125+0.001=125.001≈11.1804\sqrt{125 + 0.001} = \sqrt{125.001} \approx 11.1804 points. The extra 0.001 changes the root by less than a ten-thousandth of a point, so the epsilon has almost no effect here, which is the point of choosing it small.
  5. Normalize each score. Divide each centered score by 11.1804. For the first score, −1511.1804≈−1.3416\frac{-15}{11.1804} \approx -1.3416. The unit cancels, because points divided by points leaves a plain number. The other three become −0.4472-0.4472, 0.44720.4472 and 1.34161.3416, in the same order as the original scores.
  6. Apply the scale and shift. Because γi=1\gamma_i = 1 and βi=0\beta_i = 0, each output is yi=1×x̂i+0=x̂iy_i = 1 \times \hat x_i + 0 = \hat x_i. Multiplying by 1 and adding 0 change nothing, so at the start the outputs equal the normalized values. A trained model would replace these starting values with learned ones.
  7. Check the result. The four outputs should average to 0 and have a variance close to 1. Their sum is −1.3416−0.4472+0.4472+1.3416=0-1.3416 - 0.4472 + 0.4472 + 1.3416 = 0, so the average is 0. The squares of the normalized values add up to about 4.00, so the variance is about 4.00/4=14.00 / 4 = 1. Those two facts are what the normalization is designed to produce.

Answer: The normalized values are (−1.3416,−0.4472,0.4472,1.3416)(-1.3416,\ -0.4472,\ 0.4472,\ 1.3416). The best score sits about 1.34 spreads above this student’s average, and the worst score sits about 1.34 spreads below it. Because the average and spread came from this one student alone, adding other students to a batch would not change these numbers.

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

Why do transformers use layer normalization instead of batch normalization?

Batch normalization depends on the other examples in its batch, and sentences have different lengths. Layer normalization works on one vector at a time, so its result does not depend on the other examples.

How is it different from batch normalization in practice?

Batch normalization keeps running averages from training so it can be used when predicting one example. Layer normalization computes its averages from the example itself, every time, so it needs no running averages at all.

What is a feature here?

One number in the list that describes an example. For a word in a sentence, the list might hold many numbers, each one a learned hint about the word’s meaning inside the model.

Does layer normalization change the order of the features?

No. Each feature keeps its position in the list. The average and spread only set the center and size of the whole list, so the first feature is still the first feature after normalization.

Sources

  1. Layer Normalization, Ba, Kiros and Hinton (arXiv:1607.06450)
  2. Layer normalization, Wikipedia

| All AI & ML formulas |

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