Backpropagation: How a Network Learns
Imagine you've just baked a chocolate cake for the first time. The result is... a bit dry. You taste it, you think, and you mentally trace back through your recipe: "Maybe I put too much flour? Or not enough eggs? Or maybe the oven was too hot?" You identify the problem, you adjust, and next time, the cake is better.
This is exactly what a neural network does during training. It tastes its result (the loss, or "error"), then traces back through all its steps to understand which decision caused the problem. Backpropagation is this tracing-back process: distributing the final error to each parameter of the network to know how to correct it. Without this algorithm, neural networks simply couldn't learn.
It's the algorithm that computes each weight's contribution to the final error. Conceptually invented in the 1960s-70s, then popularized by Rumelhart, Hinton, and Williams in 1986, it's the beating heart of all today's AI models: from small classification networks to GPTs with hundreds of billions of parameters.
The Movie in Two Acts: Forward and Backward
A learning cycle always unfolds in two steps, like a round trip.
Act 1: The forward pass. Data enters through the first layer and traverses the network layer by layer, neuron by neuron. At each neuron, two simple operations occur:
- It multiplies each of its inputs by a weight (a number representing the importance of that input), sums everything up, and adds a bias (a constant offset)
- It applies an activation function (ReLU, sigmoid, tanh...) to introduce non-linearity, without this, stacking 100 layers would be equivalent to having just one
At the end of the forward pass, you get a prediction. You compare it to the expected answer via a loss function. This loss measures the error as a number: if the network predicts 7 and the correct answer is 10, the loss quantifies this gap. The larger the loss, the more wrong the network was.
Act 2: The backward pass. Now, we go the reverse way. Backpropagation asks each neuron the question: "How much did you contribute to this error?" Then to the layer before: "And you, how much did you contribute to that one's contribution?" And so on, tracing back to the very first layer. At the end, each weight in the network knows its gradient: a number that says "increase me a little" or "decrease me a little" to reduce the error next time.
A gradient is an arrow pointing toward the right direction to modify a weight. If a weight's gradient is , it means: "raising this weight will lower the loss." The sign tells you which way to turn the dial; the magnitude tells you how much this weight matters, so which weights to correct first. Note what it does not tell you: how far to turn. That decision belongs to the learning rate.

The Secret: The Chain Rule
Everything rests on a mathematical formula that's several centuries old: the chain rule. It's the only mathematical tool backpropagation needs; it is derived step by step in the chain rule, and the multi-variable derivatives it strings together in partial derivatives and the Jacobian.
The intuition is simple. Imagine a chain of causation: the oven temperature affects how the cake bakes, and how the cake bakes affects the final taste. If you want to know how the oven temperature influences the final taste, you multiply two effects:
- The effect of temperature on baking
- The effect of baking on taste
In math, it's written:
where is the loss (the final error), is an intermediate result (a layer's output), and is the weight you want to adjust.
Why is this so powerful? In a deep network with 100 layers, directly computing how a weight in the first layer affects the final loss would be horrendously complex. But thanks to the chain rule, we decompose this gigantic computation into a series of small local multiplications, layer by layer. Each layer only computes its own small effect, then passes it to the previous layer. This is what makes the computation feasible even for networks with billions of parameters.
The 4 Steps of the Backward Pass
At each layer, the chain rule is applied systematically:
-
Compute the error at the output: (the derivative of the loss with respect to the prediction). This is the starting point: "by how much is our prediction off?"
-
Traverse the activation: compute how the activation function amplified or reduced the signal. If it's ReLU and the value was positive, the gradient passes through intact. If the value was negative, the gradient is blocked (ReLU "kills" negative values).
-
Get the weight's gradient: . This is the multiplication of the received gradient by the neuron's input. If the received gradient is and the input is , then . This tells the weight: "raise yourself and the error will drop." It does not say by how much: the step size will come from the learning rate.
-
Prepare the signal for the previous layer: , which becomes the new "error gradient" for the preceding layer. And the cycle starts again.
These 4 steps are repeated going backward layer after layer until the beginning of the network. It's mechanical, systematic, and works for any architecture.
A Concrete Example with Numbers
Let's take the simplest possible network to see the mechanics in action:
- Input:
- Weight:
- Bias:
- Expected target:
Forward pass: we compute the prediction
The network predicted 7 instead of 10. The error is 9 (squared loss).
Backward pass: we trace back to find the gradient of
The gradient is -12. What does this concretely mean? The negative sign indicates that if we increase , the loss decreases. The network has discovered that its weight was too small: by increasing it (for example with a learning rate of 0.01: you subtract , so you add 0.12), the next prediction will be closer to 10.
PyTorch, TensorFlow, and JAX do all of this automatically. You just write the forward pass (the math operations), and the framework mentally records each operation in a "computation graph." When you call .backward(), it traces back through the graph and computes all gradients on its own. No more hand-deriving. This is called automatic differentiation (autograd).
The Two Monsters: Vanishing and Exploding Gradients
In deep networks (tens or hundreds of layers), two formidable problems appear.
Vanishing gradients. Imagine a chain of 100 people passing a message by whispering. Each person, when transmitting it, slightly reduces the volume (multiplies by 0.9). After 100 passes: . The message has become inaudible. This is exactly what happens in a deep network: gradients get multiplied by many small numbers (often < 1) at each layer, and become microscopic. The first layers of the network receive almost no learning signal. They stagnate.
This was the historical problem that prevented training deep networks before 2010. The sigmoid, very popular at the time, has a slope that never exceeds 0.25: each layer crossed therefore divides the gradient by at least four, which mechanically compounds the problem.
Exploding gradients. The exact opposite: if each layer multiplies the gradient by a factor > 1, the signal grows exponentially. . Gradients become astronomical numbers, weights make uncontrollable jumps, and training diverges (the loss goes toward infinity instead of decreasing).
Modern solutions:
- ReLU: its derivative is 0 or 1 (never a small number in between), which greatly mitigates vanishing
- Residual connections (also called skip connections): a direct path is added that bypasses one or more layers, so the gradient can travel back without passing through them and without being shrunk. Introduced by ResNet in 2015, they are in every transformer today
- Gradient clipping: cap gradients at a maximum length. Beyond that they get shortened without changing direction, which prevents runaway jumps
- Normalization (BatchNorm, LayerNorm): stabilizes the network's internal distributions

In Summary
Backpropagation is three ideas working together:
- Forward pass: compute the prediction and measure the error
- Chain rule: decompose the global gradient into a cascade of small local derivatives
- Backward pass: trace the error back layer by layer, multiplying local derivatives
At the end, each weight in the network knows its direction of improvement. The optimizer (Adam, SGD and the rest, see Modern optimizers) adjusts them in that direction, and on the next iteration, the network is a tiny bit better. Multiplied by millions of iterations, this process transforms a random network into a model capable of recognizing images, translating languages, or writing text.
It's mundane in its mechanics, but profound in its consequences: this algorithm, popularized in the 1980s, literally powers all of modern AI. Every time a model learns something, it's backpropagation doing the work.
The foundational paper "Learning representations by back-propagating errors" (Rumelhart, Hinton, Williams, 1986) published in Nature laid the groundwork for training deep networks. More than 35 years later, the algorithm hasn't fundamentally changed. Improvements focus on optimizers (Adam vs SGD), activation functions (ReLU vs sigmoid), and architectures (skip connections), but the core remains the same.
1. What question does backpropagation answer?
2. Why does the chain rule make gradient computation feasible, even with billions of parameters?
3. The gradient of a weight is −12. What does that mean?
4. Why do gradients vanish in deep networks, and who suffers most?
5. What are the residual connections (skip connections) introduced by ResNet for?