SeeingML
Visual Math Toolkit Guide 6 of 6 · tap to switch
✦ Interactive Visual Guide 8 min · 4 hands-on labs · Beginner friendly

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!

Interactive Lab 1: Linked Bicycle Gears (Chain Rule)
Total multiplier: 2 × 3 = 6×
Try a setup:
Chain Rule: dy/dx = (du/dx) · (dy/du) = 2 × 3 = 6×du/dx = 2×dy/du = 3×Pedal Gear (x)1 turnYou spin this knobMiddle Gear (u)2 turns2× per pedal turnBack Wheel (y)6 turns6× per pedal turn
1 turn
2×
3×
Linked multipliers multiply: Each pedal turn spins the middle gear 2×, and each middle turn spins the back wheel 3×, so the back wheel spins 2 × 3 = 6× as fast as the pedals. Turning the pedals 1 time spins the back wheel 6 times.

You already understood the Chain Rule before ever seeing the symbols: ratios along a single chain multiply (dy/dx = (dy/du) · (du/dx)).

💡 Insight

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:

  1. Multiply to get the pre-activation (u): Take an input signal x and multiply it by an adjustable weight knob w (u = w · x). That raw score u, right before any squashing curve touches it, is called the pre-activation.
  2. Squash through an S-shaped curve (y = σ(u)): Next, the neuron turns that raw score u into a probability between 0 and 1 using 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!

Interactive Lab 2: Inside One Artificial Neuron (w → u → S-Curve)
dy/dw = 0.393 (Steep Active Zone)
Step 1: Check steep center, then click Flat Tail:
Flat tailSteep middleFlat tail1.00.50.0-6-4-20+2+4+6Pre-activation score (u = w · x)Output (y)(u=1.0, y=0.73)Tangent = 0.197
Live Slope Strength Bars
Watch the tangent bar flatten when the dot enters either tail.
Curve slope here (dy/du)0.197 / 0.250
Input multiplier (du/dw = x)2.00
Total weight slope (dy/dw)0.393
1. Weight Knobw = 0.5input x = 2.0
→ u = w · x →← du/dw = 2.00 ←
2. Pre-Activationu = 1.00Raw score before curve
→ S-curve →← dy/du = 0.197 ←
3. Output Proby = 0.731Curve slope here: 0.197
Chain Rule Product: dy/dw = 0.197 (curve slope) × 2.00 (input x) = 0.393
0.5
2.0
Healthy Active Zone: At u = 1.00, the dot sits on the steep middle hill of the S-curve. Multiplying the local input slope (du/dw = 2.00) by the curve slope here (dy/du = 0.197) passes a clear learning signal of dy/dw = 0.393 back to weight w.

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 +$3 per degree.
  • Path B (Blower fan): The circulation fan also runs longer, adding +$1 per 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!

Interactive Lab 3: Splitting Paths (Parallel Slopes Add Together)
Combined slope (dy/dx) = +2.00
InputxStep 1: × 3Path A: 3 × 2 = +6.00Step 1: × 4Path B: 4 × (-1) = -4.00× 2× (-1)Total effect (ADD)dy/dx = +2.00Combined slope
Combined slope: +6.00 + (-4.00) = +2.00
Parallel paths add together: Path A multiplies along its chain to push the output up by +6.00, while Path B pulls it back down by -4.00. Adding both branches lets them partially cancel to a combined slope of (+6.00) + (-4.00) = +2.00. Try turning Path B OFF, or switch to Skip Connection (ResNet)!

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!

Interactive Lab 4: Forward Mode (4 Passes) vs. Backprop (1 Sweep)
Forward Mode: Pass 1 of 4 (1/4 solved)
4 WEIGHTS (KNOBS)HIDDEN LAYER1 SINGLE LOSS× 2.0× 1.5× 1.0× 3.0× 0.5× 0.4w₁slope = 1.00w₂waiting...w₃waiting...w₄waiting...h₁activeh₂hiddenLoss (L)dL/dw₁ = 1.001 weight per pass→ → → Pass 1 of 4 only solves w₁ (2.0 × 0.5 = 1.00) → → →
Now Scale That Up to Real AI Models:1,000,000× faster
Forward Mode (Left → Right)1,000,000 passes
Must run one separate pass for each of the 1,000,000 weights.
Reverse Mode = Backpropagation1 sweep
Starts at 1 Loss score and computes all 1,000,000 weight slopes together!
Forward Mode (Pass 1 of 4): This single pass only computed the slope for w₁ (1.00). Finishing all 4 weights takes 4 separate passes vs. 1 sweep in Backprop. At Medium Net (1,000,000 weights) scale (1,000,000 weights), Forward Mode demands 1,000,000 passes while Reverse Mode still takes just 1 single sweep!
See Univariate, Multivariable & Vector Jacobian Chain RuleThesis / Reference

1. Univariate Composition: For differentiable y=g(u)y = g(u) and u=f(x)u = f(x):

dydx=dydu⋅dudx\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}

2. Multivariable Total Derivative (Parallel Branches): When y=g(u1,…,uk)y = g(u_1, \dots, u_k) and each intermediate node ui(x)u_i(x) depends on xx, sensitivities sum over every path:

dydx=∑i=1k∂y∂ui duidx\frac{dy}{dx} = \sum_{i=1}^{k} \frac{\partial y}{\partial u_i}\,\frac{du_i}{dx}

3. Matrix Jacobian Composition (Deep Layers): For stacked vector layers x→fu→gy\mathbf{x} \xrightarrow{f} \mathbf{u} \xrightarrow{g} \mathbf{y}, the overall Jacobian is the matrix product Jg∘f(x)=Jg(u) Jf(x)\mathbf{J}_{g \circ f}(\mathbf{x}) = \mathbf{J}_g(\mathbf{u})\,\mathbf{J}_f(\mathbf{x}). Reverse-mode Backpropagation evaluates vector-Jacobian products (VJPs) from left to right starting with the scalar loss gradient, costing only O(1)O(1) backward sweeps regardless of parameter count!

See Chain Rule & Residual Skip Gradients in PyTorchOptional Code
python
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.05

Toolkit 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!

✓ Self-Check

Quick Intuition Check

Four quick real-world scenarios. No scores, just test your intuition.

1

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?

Pick an option first, or peek anytime
2

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?

Pick an option first, or peek anytime
3

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.

Pick an option first, or peek anytime
4

Inside a neuron y = sigmoid(w * x), why does an extreme pre-activation score (like u = 8.0) make weight updates stall?

Pick an option first, or peek anytime
Quick Reference

Common Questions

What is the chain rule and when do you use it?
The chain rule calculates the derivative of a nested (composite) function f(g(x)) by multiplying the outer rate of change by the inner rate of change: f'(g(x)) * g'(x). Use it whenever one variable passes through a sequence of functions, such as layers inside a neural network during backpropagation.
How do you apply the chain rule step by step?
Identify the outer function and inner function, differentiate the outer function while keeping the inner expression intact, then multiply by the derivative of the inner function. In deep networks, backpropagation repeats that exact multiplication from the final loss backward to every weight.
What is the Chain Rule in plain English?
When one variable drives a second, which drives a third (x -> u -> y), the total sensitivity dy/dx simply multiplies the step-by-step gear ratios: (dy/du) * (du/dx). If u moves 3x faster than x, and y moves 2x faster than u, then y moves 6x faster than x.
What happens in the Multivariable Chain Rule when a variable splits into multiple branches?
Multiply local slopes along each individual path from input to output, and then ADD all parallel paths together. In ResNets and Transformers (y = F(x) + x), adding the identity skip path (+1.0) guarantees gradients flow backward cleanly even if F(x) has a tiny derivative.
How is the Chain Rule connected to Backpropagation?
Backpropagation IS Reverse-Mode Automatic Differentiation of the Chain Rule. Instead of differentiating one weight at a time forward from inputs, Backprop starts at the single scalar Loss (dL/dL = 1) and applies the Chain Rule backward once to get every weight's exact gradient simultaneously.
Why does a saturated sigmoid neuron kill gradients in the Chain Rule?
Because the Chain Rule multiplies local derivatives together, one near-zero link (like sigmoid'(u) = 0.002 on the flat tail) multiplies every upstream weight's gradient down to almost zero, halting learning in early layers.

Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference

https://seeingml.com/learn/the-chain-rule/ Open GitHub issue Suggest an edit
Cite this guide in a paper, thesis, or course (BibTeX & APA)
BibTeX
@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}
}
APA

Irshad, M. A. (2026). The Chain Rule: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/the-chain-rule/