Ctrl + K
AI18 min read

Backpropagation Explained

Understand backpropagation, the algorithm used to efficiently calculate gradients and train neural networks.

Published: 2026-09-14

Backpropagation is one of the fundamental algorithms behind modern neural network training. It provides an efficient way to calculate how much each weight and bias in a neural network contributed to the final prediction error.

A neural network can contain thousands, millions, or even billions of trainable parameters. Changing these parameters one by one and measuring the effect on the loss would be extremely inefficient. Backpropagation solves this problem by using the chain rule of calculus to calculate gradients for many parameters efficiently.

Backpropagation is closely connected to gradient descent, but the two processes have different jobs. Backpropagation calculates the gradients, while an optimizer such as gradient descent or Adam uses those gradients to update the model parameters.

What Is Backpropagation?

Backpropagation is an algorithm for calculating the gradients of a neural network's loss with respect to its trainable parameters. These gradients tell the optimizer how changing each parameter would affect the loss.

The name comes from the direction in which the error information is propagated. During the forward pass, information moves from the input layer toward the output. During backpropagation, gradient information moves backward through the network, from the output toward earlier layers.

Backpropagation does not mean that the network simply sends the prediction error backward. More precisely, it applies the chain rule to efficiently calculate partial derivatives of the loss with respect to intermediate values and parameters.

Why Is Backpropagation Necessary?

Consider a neural network with many layers. The final prediction depends on the parameters of every layer. If the prediction is incorrect, training needs to determine how each parameter should change to reduce the error.

A straightforward approach would be to change one parameter slightly, run the network again, measure how the loss changed, and repeat this process for every parameter. This numerical approach would require an enormous number of additional calculations for a large network.

Backpropagation calculates these derivatives analytically using the computational structure of the network. The same intermediate calculations can be reused, making gradient calculation dramatically more efficient.

💡 The key idea behind backpropagation is reuse. Instead of independently calculating the effect of every parameter on the final loss, the algorithm reuses intermediate derivatives while moving backward through the computational graph.

The Neural Network Training Process

A simplified neural network training step can be divided into several stages.

  • The network receives training inputs.
  • A forward pass calculates predictions.
  • A loss function measures the prediction error.
  • Backpropagation calculates gradients of the loss.
  • An optimizer uses the gradients to update weights and biases.
  • The process is repeated for many training examples and batches.

Backpropagation is therefore one part of the complete training process rather than the entire training algorithm.

Forward Propagation Comes First

Before gradients can be calculated, the network must produce a prediction. This happens during the forward pass, also called forward propagation.

Each layer receives activations from the previous layer, applies a weighted transformation, and usually passes the result through an activation function.

z = Wx + b
a = f(z)

Here, x represents the input or previous layer's activations, W represents weights, b represents biases, z is the pre-activation value, f is the activation function, and a is the resulting activation.

The output of one layer becomes the input to the next layer. After passing through all layers, the network produces its final prediction.

Calculating the Loss

After the forward pass, the model's prediction is compared with the expected target using a loss function.

For example, a regression model might use mean squared error, while a classification model might use cross-entropy loss.

loss = loss_function(prediction, target)

The loss provides a single value describing how poorly the model performed for the current training example or batch. Backpropagation then determines how this loss depends on the network's intermediate values and parameters.

The Chain Rule Is the Core of Backpropagation

The mathematical foundation of backpropagation is the chain rule from calculus. The chain rule allows the derivative of a composition of functions to be calculated by multiplying the derivatives of the individual functions.

Consider a simple chain of operations:

x → a → b → y → loss

The final loss depends on y, y depends on b, b depends on a, and a depends on x. To determine how the loss changes with respect to a parameter near the beginning of the chain, the derivatives can be multiplied together.

∂L/∂a = (∂L/∂y) × (∂y/∂b) × (∂b/∂a)

A deep neural network is essentially a much larger computational graph. Backpropagation applies the same principle systematically across all of its layers.

A Simple Computational Example

Suppose a network contains a parameter w and produces an intermediate value z:

z = wx

Assume the output depends on z and the loss depends on that output. Backpropagation starts from the loss and calculates how much the loss changes with respect to the output. It then continues backward to determine how the output changes with respect to z and finally how z changes with respect to w.

∂L/∂w = (∂L/∂z) × (∂z/∂w)

Because z = wx, the derivative of z with respect to w is x. Therefore, the gradient for w can be obtained by multiplying the upstream gradient by x.

This local calculation can be repeated throughout a neural network, allowing gradients for all parameters to be calculated efficiently.

Backpropagation Through a Single Neuron

Consider a neuron with one input, one weight, one bias, and an activation function.

z = wx + b
a = f(z)

The loss L depends on the neuron's activation a. To calculate the gradient with respect to the weight w, backpropagation applies the chain rule.

∂L/∂w = ∂L/∂a × ∂a/∂z × ∂z/∂w

Since z = wx + b, the derivative of z with respect to w is x. Therefore, the weight gradient depends on the input, the activation function's derivative, and the gradient arriving from later computations.

For the bias, the corresponding derivative is simpler because z changes directly with b.

∂L/∂b = ∂L/∂a × ∂a/∂z

How Backpropagation Moves Through Layers

In a multilayer network, backpropagation starts at the output layer and works toward the input layer. Each layer receives a gradient from the layer after it and uses local derivatives to calculate gradients for its own parameters and inputs.

For a layer represented by:

z = Wx + b
a = f(z)

backpropagation needs to calculate gradients with respect to W, b, and the previous activation x. These gradients are then passed to the preceding layer.

ValueRole during backpropagation
Loss gradientStarts the backward calculation
Activation gradientShows how loss changes with the layer output
Pre-activation gradientAccounts for the activation function
Weight gradientDetermines how the weights affect loss
Bias gradientDetermines how the biases affect loss
Input gradientPasses gradient information to the previous layer

A Two-Layer Network

Consider a simplified network with an input layer, one hidden layer, and an output layer.

x → hidden layer → output layer → prediction → loss

During the forward pass, the input is transformed by the hidden layer and then by the output layer. The loss is calculated from the final prediction.

During backpropagation, the process is reversed. The algorithm first calculates the gradient at the output layer. It then uses the chain rule to calculate how the hidden layer affected the output and ultimately the loss.

The hidden layer therefore receives gradient information from the output layer. This allows the network to calculate how its earlier weights and biases should change.

What Is an Upstream Gradient?

An upstream gradient is the gradient arriving at a particular operation from computations that occur later in the computational graph.

A local operation can combine this upstream gradient with its own local derivative. The result is the gradient that should be passed to earlier operations.

gradient_to_previous = upstream_gradient × local_derivative

This local view is important because it explains why backpropagation scales to complicated networks. Each operation only needs to know how its own output changes with respect to its inputs and parameters.

Backpropagation and Computational Graphs

A computational graph represents a mathematical calculation as a collection of connected operations. Neural networks can be viewed as large computational graphs in which tensors flow through operations such as matrix multiplication, addition, activation functions, normalization, and attention.

The forward pass evaluates the graph from inputs toward outputs. Backpropagation traverses the graph in reverse and applies the chain rule to calculate gradients.

Modern deep learning frameworks rely heavily on automatic differentiation to construct or track these computational relationships and calculate gradients.

Automatic Differentiation

Automatic differentiation, often called autodiff, is a general technique for calculating derivatives of functions represented as compositions of elementary operations.

Deep learning frameworks can record the operations performed during the forward pass and then automatically calculate the required gradients during the backward pass.

This means developers usually do not need to manually derive and implement every derivative for a neural network. The framework handles much of the gradient calculation while the developer defines the model and loss function.

Backpropagation vs Automatic Differentiation

These concepts are related but not identical. Backpropagation is the reverse-mode application of the chain rule commonly used to calculate gradients in neural networks. Automatic differentiation is a broader family of techniques for automatically computing derivatives.

Reverse-mode automatic differentiation is particularly efficient when a function has many inputs or parameters and relatively few outputs, which closely matches the structure of neural network training: there can be millions of parameters but usually one scalar loss value.

Why Reverse Mode Is Efficient for Neural Networks

Suppose a model contains millions of parameters but produces a single scalar loss. Training needs the derivative of that one loss with respect to every parameter.

Reverse-mode differentiation starts with the output and propagates derivative information backward. This makes it especially suitable for neural networks because one backward pass can calculate gradients for a very large number of parameters.

Backpropagation Does Not Update the Weights

One of the most common misunderstandings is treating backpropagation and gradient descent as the same thing. They are different stages of the training process.

StagePurpose
Forward passCalculate predictions
Loss calculationMeasure prediction error
BackpropagationCalculate gradients
OptimizerUse gradients to update parameters

For example, after backpropagation the model may have a gradient for a particular weight. An optimizer can then use that gradient to modify the weight according to its update rule.

weight = weight - learning_rate × gradient

This update is part of gradient-based optimization, not the calculation of the gradient itself.

The Complete Training Step

Putting everything together, a simplified neural network training step looks like this:

1. Input batch
2. Forward pass
3. Calculate loss
4. Backpropagate gradients
5. Update parameters
6. Clear or reset gradients
7. Repeat

Modern frameworks combine many of these operations into convenient APIs, but the underlying conceptual process remains similar.

Why Backpropagation Can Become Difficult

Although the basic principle is straightforward, deep networks can contain extremely long chains of operations. During backpropagation, gradients are repeatedly multiplied through these chains.

If many derivatives have magnitudes smaller than one, repeated multiplication can make gradients extremely small. If they are large, the opposite can happen. These effects contribute to the vanishing and exploding gradient problems.

Vanishing Gradients

A vanishing gradient occurs when gradients become extremely small as they propagate backward through a network. Earlier layers may then receive tiny updates and learn very slowly.

This problem was historically associated with deep networks using certain activation functions, particularly saturating functions such as sigmoid and tanh in some settings. Modern architectures use techniques such as ReLU-family activations, careful initialization, normalization, and residual connections to make optimization more practical.

Exploding Gradients

Exploding gradients occur when repeated derivative calculations cause gradient magnitudes to become extremely large. This can lead to very large parameter updates and numerical instability.

Gradient clipping is one technique used to limit the magnitude of gradients before the optimizer applies an update. Appropriate initialization, architecture design, normalization, and learning-rate choices can also help.

⚠️ Vanishing and exploding gradients are optimization problems, not evidence that backpropagation itself is incorrect. They arise from how gradients behave as they propagate through particular network architectures and parameter configurations.

Backpropagation in Deep Networks

In a deep neural network, the backward pass can travel through dozens, hundreds, or more computational layers. The same chain-rule principle is applied repeatedly.

The output layer receives the initial gradient from the loss. Each preceding operation transforms that gradient according to its local derivative and passes the resulting gradient farther backward.

Although the mathematical graph can be extremely large, frameworks can execute these calculations efficiently using optimized tensor operations and hardware accelerators such as GPUs.

Backpropagation in Convolutional Neural Networks

Backpropagation is not limited to fully connected neural networks. It can also calculate gradients through convolutional layers.

During the backward pass, the convolution operation receives gradients from later layers and calculates how the convolution filters and their inputs contributed to the loss. The filters can then be updated by the optimizer.

Backpropagation in Transformer Models

Transformers also rely on gradient-based training. Their computational graph contains operations such as embeddings, linear transformations, attention, normalization, and nonlinear layers.

During training, the model produces an output and a loss. Backpropagation then calculates gradients through the entire computation, including the attention mechanism and the model's trainable parameters.

This is one of the fundamental mechanisms that allows large language models and other transformer-based systems to learn from massive training datasets.

A Simplified Backpropagation Example

Imagine a network that predicts whether an input belongs to a particular class. The network produces a prediction of 0.8 while the target is 1.

The loss function calculates an error based on this difference. Backpropagation starts from that loss and determines how the output changes with respect to the final layer's parameters.

The resulting gradient is then propagated through the activation function and weighted transformation of the previous layer. The process continues until gradients have been calculated for all trainable parameters.

The optimizer then uses these gradients to adjust the parameters. After many training iterations, the model should learn parameter values that produce predictions with lower loss on the training objective.

Backpropagation Does Not Mean the Model Learns Instantly

Backpropagation only provides information about how the current loss changes with respect to the parameters. It does not decide whether a parameter should be changed by a large or small amount on its own.

The optimizer and learning-rate configuration determine how gradients are converted into parameter updates. Training therefore depends on the interaction between gradient calculation and optimization.

Common Mistakes About Backpropagation

  • Thinking backpropagation is the same as gradient descent
  • Thinking the prediction error itself is simply sent backward unchanged
  • Assuming backpropagation directly modifies model weights
  • Ignoring the chain rule that connects gradients across layers
  • Assuming every gradient should have the same magnitude
  • Confusing the forward pass with the backward pass
  • Assuming a successful backward pass guarantees good model performance

Backpropagation vs Forward Propagation

FeatureForward propagationBackpropagation
DirectionInput to outputOutput to earlier layers
Main purposeCalculate predictionsCalculate gradients
Starts withInput dataLoss gradient
ProducesActivations and predictionParameter gradients
Used byModel evaluation and trainingTraining

Backpropagation vs Gradient Descent

ConceptMain responsibility
BackpropagationCalculate gradients of the loss
Gradient descentUse gradients to update parameters
AdamUse gradients with adaptive optimization rules
Loss functionMeasure prediction error

A useful mental model is that the loss function tells the network how wrong it was, backpropagation calculates how each parameter contributed to that error, and the optimizer decides how to change those parameters.

Advantages of Backpropagation

  • Efficiently calculates gradients for large neural networks
  • Uses the chain rule to reuse intermediate calculations
  • Works with many types of differentiable neural network architectures
  • Can calculate gradients for millions or billions of parameters
  • Works naturally with automatic differentiation frameworks
  • Provides the foundation for gradient-based neural network training

Limitations and Challenges

  • Requires differentiable operations for standard gradient-based training
  • Can suffer from vanishing or exploding gradients
  • Requires memory to store information needed for the backward pass
  • Can be computationally expensive for very large models
  • Gradient calculation does not guarantee that optimization will find the best solution
  • Training quality still depends on data, architecture, loss function, and optimization settings

Backpropagation and Memory Usage

The backward pass often needs intermediate values from the forward pass. These values are required to calculate local derivatives later.

For large neural networks, storing activations can consume significant amounts of memory. This is one reason memory optimization is important when training large models.

Techniques such as activation checkpointing can reduce memory usage by avoiding the storage of some intermediate activations and recomputing them when needed during the backward pass. This trades additional computation for lower memory consumption.

Why Backpropagation Changed Neural Network Training

The central advantage of backpropagation is computational efficiency. It transformed the practical problem of training multilayer networks by providing an effective method for calculating gradients throughout many layers.

Combined with increasingly powerful hardware, large datasets, improved architectures, better initialization, normalization, and modern optimizers, gradient-based backpropagation became a foundation of modern deep learning.

Frequently Asked Questions

What is backpropagation in simple terms?

Backpropagation is a method for calculating how much each neural network parameter contributed to the final loss. It works backward through the network using the chain rule to calculate gradients.

Does backpropagation update the weights?

No. Backpropagation calculates gradients. An optimizer such as SGD or Adam uses those gradients to update the weights and biases.

What is the difference between backpropagation and gradient descent?

Backpropagation calculates the gradients of the loss with respect to the model parameters. Gradient descent uses those gradients to determine how the parameters should be updated.

Why is the chain rule important for backpropagation?

The chain rule allows derivatives of many connected operations to be multiplied together. This lets backpropagation calculate how early parameters affect the final loss without independently recomputing the entire network for every parameter.

Does every neural network use backpropagation?

Most commonly trained neural networks use backpropagation or an equivalent reverse-mode gradient calculation because it is efficient for models with many parameters and a scalar loss. However, not every learning system relies on standard backpropagation.

Conclusion

Backpropagation is a fundamental method for training neural networks. It efficiently calculates the gradients of the loss with respect to the network's weights, biases, and other trainable parameters by applying the chain rule backward through the computational graph.

The process begins with a forward pass that produces a prediction and a loss. Backpropagation then moves backward from the loss, calculating local derivatives and combining them with upstream gradients. An optimizer such as gradient descent or Adam uses the resulting gradients to update the model parameters.

Understanding backpropagation makes it much easier to understand how neural networks actually learn. The central idea is not that the network simply sends an error backward, but that it efficiently calculates how every parameter affects the final loss and provides that information to the optimization algorithm.

Found an issue?

Found an error, outdated information, or something missing from this article? Let me know through the Contact page.

Your feedback helps improve our articles and keep them accurate and useful.