TL;DR
Training a neural network means nudging every weight in the direction that lowers the loss. To know which way to nudge, you need the derivative of the loss with respect to each weight. Backpropagation is the procedure that computes all of those derivatives in one backward sweep through the network, by applying the chain rule from the output back to the input and reusing each intermediate result.
Where you'll see it: in the training loop of every neural network, from a small classifier on a laptop to large language models. Every framework's loss.backward() call is this algorithm.
Intuition
Blame, passed backwards
Picture a factory line with three stations. The final product is wrong by 2 cm. Station three could have caused some of that error, station two could have, and station one could have. To fix the product, each station needs to know how much its own setting contributed. The useful way to work this out is backwards: the last station looks at the error and says "if I had moved my setting by a little, the output would have moved by this much." Then it passes that sensitivity to the station before it, which multiplies it by its own sensitivity and passes the product on again.
That is backpropagation. A neural network is a chain of simple steps: multiply by a weight matrix, add a bias, apply a bend. The loss is at the end. Each step has a local sensitivity, meaning how much its output changes when its input changes. Starting from the loss and walking backwards, you multiply these local sensitivities together, and at every step you also read off how much each weight at that layer contributed.
Why not just measure each weight?
You could find the gradient of each weight numerically. Nudge one weight a tiny amount, rerun the network, see how the loss moved. That works, but a network with a million weights needs a million forward passes to get one gradient, and training needs a gradient on every step. Backpropagation gets all of them for a cost of only a small multiple of one forward pass. Its trick is to reuse the intermediate values from the forward pass and the chain of sensitivities from the backward pass, instead of recomputing the network for each weight.
The reason it is so efficient is that the loss is one number and the parameters are many. Working backwards from one number to all the parameters costs only a small multiple of one forward pass. Working forwards would need a separate pass for each parameter.
- loss as a function of w₁
The math
The network and its loss
Use the notation from Feedforward Neural Network. The input is . Each layer computes a pre-activation and an activation:
Here is a weight matrix, is a bias vector, and is an Activation Function applied entry by entry. The output is (no activation on the last layer). The loss is a single number that measures how wrong the prediction is. Training needs the gradient and for every layer.
The error signal
Define the error signal at layer as the sensitivity of the loss to that layer's pre-activation:
Each entry of answers the question "if this neuron's pre-activation moved a little, how much would the loss move?" Once you have for a layer, the weight gradients for that layer follow directly.
The four equations
Backpropagation is four equations. The first sets up the start of the backward pass, the second moves the error signal back one layer, and the last two read off the parameter gradients.
Here is the entry-by-entry product, is transpose, and is the derivative of the activation. The second equation is the chain rule written for vectors. The loss depends on only through , and depends on through the matrix . Multiplying by carries the signal back through that matrix, and the term carries it back through the bend.
The third equation says that the gradient for a weight is the product of the error at its output neuron and the activation at its input neuron. It is an outer product, so each weight gets its own entry. The fourth says the bias gradient is just the error signal.
Gradients through a matrix product
For a layer , the gradient of a scalar loss with respect to is , and the gradient with respect to is . These two expressions are the building blocks of the four equations above. The Jacobian Matrix of with respect to is , and the backward pass multiplies by its transpose.
Algorithm
- Forward pass. Compute and for , and store them. Compute the loss.
- Output error. Compute from the loss.
- Backward pass. For , compute from , using the stored for .
- Read off gradients. For each layer, compute and .
Step 1 must store the intermediate values. Step 3 needs them, so the memory cost of backpropagation is the cost of keeping every layer's activations until the backward pass is done.
Worked examples
Take a network with one input, one hidden neuron with a ReLU activation, and one output with no activation. The loss is squared error. The numbers are:
- input , target
- hidden weight , hidden bias
- output weight , output bias
Forward pass.
Backward pass. The chain rule is applied from the output back to the input.
- Output layer: , and
- Carry the signal back:
- Through the ReLU: since , , so
- Hidden layer: , and
Check. Nudge to . Then , , and . The slope is 6, which matches step 9. This is the same curve shown in the plot above.
Take a step. With learning rate , the update gives , , , . Rerunning the forward pass: , , and . The loss dropped from 2.25 to 0.316 in one step.
Interpretation: the gradient told us which direction reduces the error for every parameter at once, and a small step in that direction did reduce it. The step size of 0.05 was chosen to keep the change modest. A larger step could overshoot.
Consider a classifier for images that has one hidden layer of 128 neurons and 10 outputs. Its input has values. The number of trainable parameters is
Forward pass cost. The two matrix-vector products cost multiply-adds.
Backward pass cost. Each layer needs one product to move back through , which costs as much as its forward product, and one outer product for the weight gradient, which costs the same again. So the backward pass costs roughly twice the forward pass, about operations.
Comparison. A forward-only method, which computes the derivative with respect to one parameter per pass, would need passes of about operations each. That is about operations. Backpropagation does the same job in about , roughly fifty thousand times less work.
Interpretation: the saving comes from the shape of the problem, one scalar loss and many parameters. It is why backpropagation scales to networks with billions of parameters, and why the number of parameters is not the bottleneck it would otherwise be.
Tradeoffs and failure modes
Backpropagation is the default because it is exact and efficient, but it has practical limits.
| Situation | What goes wrong | Better choice or fix |
|---|---|---|
| Very deep network with sigmoid activations | The factor is multiplied at every layer, so gradients shrink toward zero (vanishing gradients). Early layers barely learn. | Use Rectified Linear Unit (ReLU) or its variants, careful Xavier (Glorot) Initialization or He (Kaiming) Initialization, or residual connections. |
| Weights that grow large with depth | Repeated multiplication by large matrices makes gradients explode. | Gradient clipping, normalisation layers such as Layer Normalization, or smaller learning rates. |
| ReLU at exactly zero | The derivative is undefined at . | In practice a convention is used, such as . The effect is small. |
| Memory-limited training | Backpropagation stores every activation for the backward pass, which can exceed GPU memory. | Gradient checkpointing, which recomputes some activations during the backward pass. |
| Custom operations | Automatic differentiation needs a derivative for every operation. A non-differentiable step breaks the chain. | Replace the step with a differentiable approximation, or use a surrogate gradient. |
Backpropagation computes the gradient of whatever the forward pass computes. It does not know whether that loss is the right one, and it cannot tell you whether a model will generalise. Those problems are handled by the choice of Loss Function, the data, and validation.
History
The core idea predates neural networks. In the early 1960s, control theorists such as Kelley and Bryson described how to compute the sensitivity of a multi-stage system's cost to its settings by working backwards through the stages. In 1970, Seppo Linnainmaa described the general method for computing derivatives of a program's output by running its operations in reverse. Its neural network form was described by Paul Werbos in his 1974 doctoral thesis, which applied it to training multilayer networks.
Interest grew in the mid-1980s. In 1986, David Rumelhart, Geoffrey Hinton and Ronald Williams published a paper in Nature showing that backpropagation could learn useful internal representations in multilayer networks. That paper is the usual reference, and it helped revive the field after a period when single-layer limitations had discouraged work on neural networks.
The method became practical for large networks later. Faster hardware, larger datasets, and automatic differentiation libraries made it routine. Modern frameworks compute the backward pass automatically from the forward definition, so the equations above are rarely written out by hand, but they are what those frameworks run.
Check yourself
QuestionRecall: what does the error signal measure?Show answer
It is the partial derivative of the loss with respect to the pre-activation of layer . Each entry says how much the loss changes if that neuron's pre-activation changes by a small amount. It is the quantity that the backward pass carries from layer to layer.
QuestionComputation: in the scalar example, what is if the target were instead of , with all other values unchanged?Show answer
The forward pass is unchanged, so . Then . Since , the answer is .
QuestionWhy: why does backpropagation need the forward-pass activations, and what would happen if they were discarded?Show answer
The backward pass needs and to compute the local sensitivities and the weight gradients. Those values depend on the input and the current weights, so they cannot be recomputed from the loss alone. Discarding them forces the network to be run again before the backward pass can proceed, which is the trade made by gradient checkpointing.
QuestionApplied: a 50-layer network with sigmoid activations trains very slowly, and the gradients for the first few layers are about while the last layer's are about . What is the likely cause, and what would you change?Show answer
The likely cause is vanishing gradients. Each sigmoid derivative is at most 0.25, so each backward step shrinks the signal, and after 50 layers the factor is tiny. A good response is to switch to ReLU-family activations, use He initialisation for the weights, and consider residual connections so the signal has a short path back to the early layers.
Sources
- Rumelhart, Hinton, Williams, Learning representations by back-propagating errors, Nature, 1986: https://www.nature.com/articles/323533a0
- Backpropagation (Wikipedia)
- Goodfellow, Bengio, Courville, Deep Learning, Chapter 6.5: https://www.deeplearningbook.org/