
A tiny neural network predicts 2 when the target is 3. Its squared loss is 1. The network has two weights, so how can one loss tell us which way to adjust each weight? Backpropagation in neural networks uses that loss to compute a gradient for each weight. In this example, the gradients are −8 and −2.
What is backpropagation?
Backpropagation computes how sensitive a neural network’s loss is to each trainable parameter. It starts at the loss and works backward through the operations used to make the prediction. At each step, the chain rule combines the slope already calculated with the slope of the current operation.
A gradient collects those slopes, one per parameter. A weight’s gradient tells you the direction and rate at which the loss changes near its current value, with the other weights held fixed. An optimizer uses those gradients to decide how to change the weights. For a refresher on weights and hidden layers, see Neural Networks Explained.
The forward pass gives us a prediction and a loss
Our fictional model takes one input, uses one hidden unit, and returns one number. It has two weights and no biases. The hidden unit uses ReLU, a rule that passes positive numbers through and returns zero at zero and below.
| Step | Calculation | Result |
|---|---|---|
| Start with the example | Input x = 2 and target y = 3 | First weight w = 0.5 and output weight v = 2 |
| Multiply by the first weight | s = w × x = 0.5 × 2 | s = 1 |
| Apply ReLU | h = max(0, s) = max(0, 1) | h = 1 |
| Make the prediction | ŷ = v × h = 2 × 1 | ŷ = 2 |
| Calculate squared loss | L = (ŷ − y)² = (2 − 3)² | L = 1 |
Here, the loss is the squared error on one example. For more on what happens when you change how errors are scored, see Loss Functions Explained.
How backpropagation in neural networks computes the two gradients
The chain rule connects these slopes. If a weight changes a hidden value, the hidden value changes the prediction, and the prediction changes the loss, how much does that weight change the loss? Multiply the slopes along the path.
The notation ∂L/∂v means “the slope of the loss with respect to v.” The same notation works for intermediate values such as h and s.
| Work backward | Local slope used | Loss slope we get |
|---|---|---|
| Start at the prediction ŷ | The slope of squared error is 2 × (ŷ − y) | 2 × (2 − 3) = −2 |
| Find the gradient for output weight v | With h fixed, the slope of v × h with respect to v is h = 1 | −2 × 1 = −2 |
| Pass the slope back to hidden output h | With v fixed, the slope of v × h with respect to h is v = 2 | −2 × 2 = −4 |
| Pass through ReLU to s | At s = 1, ReLU’s slope is 1 | −4 × 1 = −4 |
| Find the gradient for first weight w | With x fixed, the slope of w × x with respect to w is x = 2 | −4 × 2 = −8 |
Both gradients are negative, so a small increase in either weight would initially lower the loss if the other weight stayed fixed. The first weight has a steeper local slope here because a change travels through both multiplications. Its gradient is four times as large in magnitude at these particular values.
Try a one-step check. Keep the input and weights fixed and change the target to 2. The model already predicts 2, so the slope at the output is zero. Every gradient in this example becomes zero.

One optimizer step uses both gradients
For basic gradient descent, subtract the learning rate times the gradient from each weight. With a learning rate of 0.025, the first weight becomes 0.5 − 0.025 × (−8) = 0.7. The output weight becomes 2 − 0.025 × (−2) = 2.05. Both calculations use gradients from the same original forward pass.
Run the forward pass again with those updated weights. ReLU passes through 0.7 × 2 = 1.4, so the new prediction is 2.05 × 1.4 = 2.87. The squared loss falls from 1 to 0.0169. That is one improvement on one training example. To tell how a model performs on new inputs, evaluate it on separate data.
The same division of work appears in PyTorch. Calling loss.backward() computes and accumulates gradients. Calling optimizer.step() applies an update. A typical training loop clears gradients before the next calculation. PyTorch’s training walkthrough
What changes in a real network?
A real network has more operations and many more weights. When a value feeds multiple downstream operations, the backward pass adds the gradient contributions from those paths. Training often starts with a loss averaged over a batch of examples, so the gradients describe that batch objective.
The local slopes still matter. In our example, s is positive and ReLU passes the slope through. If s were negative, ReLU’s local slope would be zero, so this path would carry no gradient back to w for that example. The same chain-rule idea explains both outcomes. PyTorch’s autograd tutorial
Sources
- Hinton’s publication index for the 1986 backpropagation paper
- Deep Learning, Chapter 6, on backpropagation and the chain rule
Where to Learn Next
You’ve calculated two gradients and used them for one update. See how these steps fit into a full training loop, from loading a batch to evaluating the finished model.
Continue to How Deep Learning Works
For a closer look at the update itself, read Gradient Descent Explained. For choosing settings such as the learning rate, see Hyperparameters Explained.