Visual Math Toolkit Guide 6 of 6 · tap to switch
The Chain Rule
Feel the Chain Rule as linked spinning gears, trace gradients through a real sigmoid neuron, and see why skip connections and Backprop work.
Picture a bicycle with three interlocking gears: the front pedal gear (x), a middle gear (u), and the back wheel (y). Every time you turn the pedals 1 full turn, the middle gear spins 2 times. Every time the middle gear spins once, the back wheel spins 3 times.
How many times does the back wheel spin for 1 turn of the pedals? You do not need a calculus textbook to figure it out: 2 × 3 = 6 full turns!
Deep learning models work just like a long chain of linked gears. An input enters Layer 1, whose output feeds Layer 2, whose output feeds Layer 3, all the way to the final error score called the Loss. In math notation, that nested pipeline is written L(f₃(f₂(f₁(w)))), meaning each layer wraps around the output of the layer before it.
When we train a neural network, we ask one essential question: if I nudge an early weight knob w by a tiny amount, how much does the final output y move? In calculus, each single step’s multiplier is called a local slope (or derivative), and multiplying those linked multipliers from end to end is called The Chain Rule.
Dial the two gear ratios (du/dx and dy/du) below, then spin the pedal knob to watch the entire Chain Rule happen right in front of you!
You already understood the Chain Rule before ever seeing the symbols: ratios along a single chain multiply (dy/dx = (dy/du) · (du/dx)).
One jammed gear stops the whole chain. Try sliding either gear ratio down to 0× above. Because the Chain Rule multiplies ratios together, a single zero anywhere in the chain forces the total multiplier to zero. Keep that picture in mind for the next section!
How the Chain Rule Works Inside a Neural Network
Now trade bicycle gears for a real artificial neuron. It takes just two linked steps:
- Multiply to get the pre-activation (
u): Take an input signalxand multiply it by an adjustable weight knobw(u = w · x). That raw scoreu, right before any squashing curve touches it, is called the pre-activation. - Squash through an S-shaped curve (
y = σ(u)): Next, the neuron turns that raw scoreuinto a probability between0and1using a smooth S-shaped curve called the sigmoid.
Look closely at how an “S” bends. Near the center (u = 0), the hill is steep: even a small nudge to u noticeably moves the output y. Out in the flat tails (when u grows very positive like +5, or very negative like -5), the curve flattens almost completely against 1 or 0. Once a neuron slides into those flat tails (called saturation), nudging u barely changes y at all, so the curve’s local slope (dy/du) shrinks almost to zero.
Slide w and x below and watch the live dot travel along the S-curve. Then click Flat Tail (Saturation) to see how one flat slope at the end chokes the learning signal for the weight behind it!
Notice why this chain stays so clean and modular: the multiplication step only needs its own local slope (du/dw = x), and the S-curve step only needs its own local slope (dy/du). Neither stage has to look inside the rest of the network. Each stage simply multiplies its own local slope onto the signal passing through!
When paths split: the Multivariable Chain Rule (& Skip Connections!)
Not every chain is a single straight line. Imagine turning up your home thermostat by 1 degree (x). That single knob change raises your monthly electric bill (y) through two separate paths at the same time:
- Path A (Heater coils): The heating coils work harder, adding
+$3per degree. - Path B (Blower fan): The circulation fan also runs longer, adding
+$1per degree.
What is the total impact on your bill? You simply add both parallel effects together: $3 + $1 = +$4 per degree! And if a second path pulls in the opposite direction (a negative slope), adding them lets the two paths partially cancel out.
In calculus, this rule for splitting paths is called the Multivariable Chain Rule, and it follows one unforgettable motto: multiply along each path, then ADD all parallel paths together.
Modern Transformers and deep image models (called ResNets) use this exact rule to beat the flat-tail vanishing problem! Instead of forcing the learning signal through only one deep neural block F(x), they split input x into two parallel paths that add back together (y = F(x) + x): the neural layers F(x) on top, and a direct skip connection (+ x) underneath whose local slope is always a steady +1.00. Even when the deep block’s slope shrinks to 0.05, adding the skip highway (0.05 + 1.00 = 1.05) keeps the gradient alive across hundreds of layers.
Start with the simple 2-path split below, then switch to Skip Connection (ResNet) and toggle the Bottom Skip Branch OFF to watch the gradient collapse!
From the Chain Rule straight to Backpropagation
Now imagine a giant factory with 1,000,000 control dials (weights) whose outputs all combine into 1 single quality score (the final Loss). You need to measure how much nudging every single dial changes that 1 Loss score. You have two choices for running the Chain Rule:
- Walk Forward from each dial (Forward-Mode Chain Rule): Nudge Dial 1 and trace its ripple left-to-right all the way to the Loss. That only tells you the slope for Dial 1! To learn Dial 2’s slope, you must reset and trace all the way forward again. For 1,000,000 weights, that means 1,000,000 separate passes.
- Walk Backward from the 1 Loss (Reverse-Mode Chain Rule, called Backpropagation): Start at the single Loss score on the right (whose sensitivity to itself is
1) and walk right-to-left once, multiplying by each local slope as you go. Because every dial shares the same downstream path into that single Loss, 1 single backward sweep delivers the exact slope for all 1,000,000 weights at the exact same time!
That asymmetry (millions of weights funneling down to 1 single Loss) is why modern AI training runs the Chain Rule in reverse. Step through the 4-weight network below in Forward Mode first, then flip to Reverse Mode (Backprop) to watch all 4 slopes light up in a single sweep!
See Univariate, Multivariable & Vector Jacobian Chain RuleThesis / Reference
1. Univariate Composition: For differentiable and :
2. Multivariable Total Derivative (Parallel Branches): When and each intermediate node depends on , sensitivities sum over every path:
3. Matrix Jacobian Composition (Deep Layers): For stacked vector layers , the overall Jacobian is the matrix product . Reverse-mode Backpropagation evaluates vector-Jacobian products (VJPs) from left to right starting with the scalar loss gradient, costing only backward sweeps regardless of parameter count!
See Chain Rule & Residual Skip Gradients in PyTorchOptional Code
import torch
x = torch.tensor(2.0, requires_grad=True)
# Residual block: F(x) = 0.05 * x PLUS skip highway + x
f_x = 0.05 * x
y = f_x + x
y.backward()
print("Total dy/dx (0.05 + 1.00):", x.grad.item()) # 1.05Toolkit complete! Put every piece into action
You now hold the complete visual math foundation behind modern AI: Vectors & Dot Products, Span, Basis & Rank, Matrices & Determinants, Eigenvectors & PCA, Derivatives & Gradients, and The Chain Rule!
Ready to see the Chain Rule come alive inside a multi-layer neural network? Jump directly into Backpropagation, or return to the full Curriculum Explorer to pick any Machine Learning or LLM path!
Quick Intuition Check
Four quick real-world scenarios. No scores, just test your intuition.
In a three-gear chain, the middle gear turns 4 times per pedal turn (du/dx = 4), and the back wheel turns 3 times per middle-gear turn (dy/du = 3). By the Chain Rule, what is the total multiplier dy/dx?
In a skip-connection block y = F(x) + x, suppose the deep neural path F(x) currently has a tiny slope of 0.02. What is the combined slope dy/dx?
Reverse-Mode Chain Rule (Backpropagation) computes exact slopes for all 100 million weights of a neural network in a single backward sweep starting from the single Loss score.
Inside a neuron y = sigmoid(w * x), why does an extreme pre-activation score (like u = 8.0) make weight updates stall?
Common Questions
What is the chain rule and when do you use it?
How do you apply the chain rule step by step?
What is the Chain Rule in plain English?
What happens in the Multivariable Chain Rule when a variable splits into multiple branches?
How is the Chain Rule connected to Backpropagation?
Why does a saturated sigmoid neuron kill gradients in the Chain Rule?
Related Visual Guides
Backpropagation
See how neural networks pass blame backward from a wrong guess to every weight in one efficient Chain Rule sweep.
Derivatives, Slopes & the Gradient
Zoom into a curve to turn a chord into a derivative, slice a 2D bowl into partial slopes, and follow the Gradient compass downhill.
Neural Networks & the Perceptron
Demystify neural networks from a single weighted switch to multi-layer perceptrons that solve XOR and approximate any curve.
Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference
Cite this guide in a paper, thesis, or course (BibTeX & APA)
@misc{irshad2026thechainrule,
author = {Irshad, Muhammad Aashir},
title = {The Chain Rule: Interactive Visual Guide},
howpublished = {SeeingML},
year = {2026},
month = {dec},
url = {https://seeingml.com/learn/the-chain-rule/},
note = {Interactive visual guide}
} Irshad, M. A. (2026). The Chain Rule: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/the-chain-rule/