← Back to the homepage

Backprop Bulletin explainer

What is backpropagation?

Backpropagation works backward through a neural network to calculate how a small change to each weight would affect the loss, a measure of prediction error. These sensitivities are called gradients. An optimizer uses them to adjust the weights.

By Backprop Bulletin.

The short answer

Training a neural network repeats four steps:

  1. Prediction (the forward pass): the network turns an input into a prediction.
  2. Loss: one number measures how wrong the prediction was.
  3. Backpropagation: working backward from the loss, the network calculates a gradient for every weight: how fast the loss would change if that weight changed a little.
  4. Weight update: an optimizer, such as gradient descent, uses those gradients to change the weights.

Backpropagation is step 3 only. It calculates the gradients and changes no weight. Changing the weights is the optimizer’s job, in step 4.

The tiny network

Here we follow one tiny network through one training step, with numbers you can check by hand. It has one input, one hidden value and one output, joined by two weights. It has no activation function, so every step is a multiplication you can follow.

One training step in the tiny network Forward, top to bottom: input x equals 2, times weight w1 of 0.5, gives hidden value h equals 1; times weight w2 of 2, gives prediction y-hat equals 2; compared with the target 3, the loss is 1. Backward, bottom to top: the gradient of the loss with respect to y-hat is minus 2; with respect to w2 it is minus 2 times h, minus 2; with respect to h it is minus 2 times w2, minus 4; with respect to w1 it is minus 4 times x, minus 8. Forward pass Backpropagation x = 2 × w₁ (0.5) h = 1 × w₂ (2) ŷ = 2 vs y = 3 loss L = 1 (2 − 3)² ∂L/∂ŷ = −2 2 × (ŷ − y) ∂L/∂w₂ = −2 −2 × h ∂L/∂h = −4 −2 × w₂ ∂L/∂w₁ = −8 −4 × x weights unchanged
The prediction flows down the left. Backpropagation then works up the right, from the loss back to the first weight, multiplying one local factor at a time.

1. Prediction

The forward pass applies each weight in turn:

h = 0.5 × 2 = 1
ŷ = 2 × 1 = 2

The network predicts 2. The target is 3.

2. Loss

A loss function turns the miss into one number. We use the squared error:

L = (ŷ − y)² = (2 − 3)² = 1

Squaring makes every miss count as positive and makes bigger misses count more. Training aims to make this number smaller.

3. Backpropagation: calculating the gradients

For each weight, backpropagation asks: if this weight grew by a tiny amount, how fast would the loss change? That rate is the weight’s gradient, written ∂L/∂w. Backpropagation starts at the loss and works backward, one link at a time, multiplying the local rates together. This is the chain rule from calculus.

  1. At the loss: ∂L/∂ŷ = 2 × (ŷ − y) = 2 × (2 − 3) = −2. The minus sign says a larger prediction would lower the loss.
  2. Through w₂: since ŷ = w₂ × h, a change in w₂ is multiplied by h. So ∂L/∂w₂ = −2 × 1 = −2.
  3. Back to the hidden value: a change in h is multiplied by w₂, still at its original value of 2. So ∂L/∂h = −2 × 2 = −4.
  4. Through w₁: since h = w₁ × x, a change in w₁ is multiplied by x. So ∂L/∂w₁ = −4 × 2 = −8.

The output gradient, −2, is calculated once and used twice: first to find the gradient for w₂, then to pass the gradient back to h. The −4 that arrives at h is then used in the same way to find the gradient for w₁. Nothing is calculated twice; each result is passed backward to the next step. That reuse is what makes backpropagation efficient: a network with millions of weights gets every gradient from one backward pass.

Both gradients are negative, so increasing either weight would lower the loss. The gradient for w₁ is larger, so right now the loss is more sensitive to w₁ than to w₂. No weight has changed yet.

4. Weight update: the optimizer’s step

Now the optimizer uses the gradients. Plain gradient descent moves each weight a small step against its gradient:

new weight = old weight − learning rate × gradient

Both updates use the gradients from step 3, which all come from the original forward pass (w₁ = 0.5, w₂ = 2, h = 1). The optimizer changes the two weights together; it does not change w₂ first and then recalculate the gradient for w₁ with the new value. With a learning rate of 0.025:

w₂ = 2 − 0.025 × (−2) = 2.05
w₁ = 0.5 − 0.025 × (−8) = 0.7

A fresh forward pass shows the effect:

h = 0.7 × 2 = 1.4
ŷ = 2.05 × 1.4 = 2.87
L = (2.87 − 3)² = 0.0169

The loss fell from 1 to 0.0169 in one step. The learning rate is the optimizer’s setting: too small and training crawls; too large and the update overshoots the target. Other optimizers, such as Adam, start from the same gradients but choose the size of each step differently.

One training step, and who does each part
StepDone byIn the example
1. Predictionthe network’s forward passŷ = 2
2. Lossthe loss functionL = 1
3. Gradientsbackpropagation∂L/∂w₂ = −2, ∂L/∂w₁ = −8
4. Weight updatethe optimizerw₂: 2 → 2.05; w₁: 0.5 → 0.7

In real networks

Real networks follow the same four steps at a far larger scale:

Sources

The worked example is our own. Every number on this page can be recomputed by hand from x = 2, w₁ = 0.5, w₂ = 2, y = 3 and a learning rate of 0.025.