The Chain Rule
You land in Paris with British pounds. Every pound buys 1.2 euros. A week
later you fly on to Tokyo, where every euro buys 180 yen. How many yen is
one pound worth? You don't hesitate: 1.2 \times 180 = 216 yen.
You multiplied the two rates — pounds-to-euros times euros-to-yen gives
pounds-to-yen. No one taught you that; it's just obviously how conversion chains work.
Same story on a bicycle. One turn of the pedals spins the rear wheel
3 times, and each wheel turn rolls the bike
2 metres down the road. Metres per pedal turn?
3 \times 2 = 6. Pedal → wheel → road: the rates multiply through
the chain.
Now say it abstractly: if A changes
3 times as fast as B, and
B changes 2 times as fast as
C, then A changes
6 times as fast as C.
That single sentence is the chain rule — arguably the most important rule
in all of calculus. Everything on this page is that sentence wearing different clothes.
Functions in a chain
Where do chains show up in calculus? In composite functions — a function
inside another function, like (3x + 1)^5. Here
an inner function g(x) = 3x + 1 does its work first, and its
output feeds an outer function f(u) = u^5. The input
x is your pound, the intermediate value
u = g(x) is your euros, and the final output is your yen.
So how fast does the final output respond to the original input? Exactly like the currency:
the inner function converts changes in x into changes in
u at the rate g'(x), and the outer
function converts changes in u into changes in
y at the rate f'(u). The overall
rate is the product. Drag the two gear ratios below and watch the overall
rate \frac{dy}{dx} track their product.
Notice there is no setting of the sliders where the rates add or where one of them
can be ignored. Two gears in series always multiply — and so do two functions.
The rule, in both dialects
-
If g is differentiable at x and
f is differentiable at g(x), then
the composite f(g(x)) is differentiable at
x, and
\frac{d}{dx}\,f\!\big(g(x)\big) = f'\!\big(g(x)\big)\cdot g'(x).
-
Equivalently, writing u = g(x) and
y = f(u), in Leibniz notation:
\frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx}.
These are the same sentence in two dialects. The prime version says it
function-by-function: differentiate the outer function, evaluated at the inner one,
then multiply by the derivative of the inner function. The Leibniz version says it
rate-by-rate: yen-per-pound equals yen-per-euro times euros-per-pound. Read one
aloud and you're reading the other. Two details deserve a second look:
-
In f'(g(x)), the outer derivative is evaluated at the
inner function's output, not at x. The outer gear
only ever sees what the inner gear hands it.
-
In the Leibniz version, the dus appear to cancel like
a fraction. That's a wonderful memory aid — and only a memory aid. More on this
in the "Watch out!" below.
Worked example: (x^2 + 1)^5 without expanding
Could you differentiate y = (x^2 + 1)^5 with just the
power rule? In
principle, yes: expand the fifth power into a six-term
polynomial
(x^{10} + 5x^8 + 10x^6 + \cdots), differentiate every term,
and hope you made no slips. The chain rule does it in two lines. Name the inner
function u explicitly — this small habit prevents
almost every chain-rule mistake:
-
inner: u = g(x) = x^2 + 1, so
g'(x) = 2x;
-
outer: f(u) = u^5, so
f'(u) = 5u^4.
Differentiate the outer function leaving the inner one untouched inside it, then
multiply by the inner derivative:
\frac{dy}{dx} = \underbrace{5\,(x^2 + 1)^4}_{f'(g(x))} \cdot \underbrace{2x}_{g'(x)} = 10x\,(x^2 + 1)^4.
Done — no expansion, no ten-term polynomial, no slips. And here is the identical
calculation in the Leibniz dialect, so you can see the two notations are genuinely saying
one thing:
| Prime notation |
Leibniz notation |
| g(x) = x^2 + 1 |
u = x^2 + 1 |
| f(u) = u^5 |
y = u^5 |
| g'(x) = 2x |
\dfrac{du}{dx} = 2x |
| f'(u) = 5u^4 |
\dfrac{dy}{du} = 5u^4 |
| f'(g(x))\,g'(x) = 5(x^2\!+\!1)^4 \cdot 2x |
\dfrac{dy}{du}\dfrac{du}{dx} = 5u^4 \cdot 2x |
One last move in the Leibniz column: the answer 5u^4 \cdot 2x
still mentions u, and the question was asked in terms of
x — so substitute u = x^2 + 1
back to finish: 10x\,(x^2+1)^4. Same answer, same
steps, two spellings.
A second run: (3x + 1)^5
Once more with a different inner function, to lock in the rhythm. Differentiate
y = (3x + 1)^5. Identify the layers:
- outer: f(u) = u^5, so by the
power rule
f'(u) = 5u^4;
- inner: g(x) = 3x + 1, so
g'(x) = 3.
Differentiate the outer (keeping the inner intact), then multiply by the inner's derivative:
\frac{dy}{dx} = 5\,(3x + 1)^4 \cdot 3 = 15\,(3x + 1)^4
The lonely \cdot\, 3 at the end is the whole point of the chain
rule — forget it and you'd be off by that factor. That extra factor is precisely the inner
gear's rate: 3x + 1 changes 3 times
as fast as x, so everything downstream of it does too.
A chain with actual numbers
The rule feels most real when the rates are plain numbers. Take
y = u^3 where u = x^2 + 1, and ask:
how fast is y changing at the moment
x = 1?
-
Inner link. \frac{du}{dx} = 2x, which at
x = 1 is 2. So right now,
u is changing 2 times as fast as
x.
-
Outer link. At x = 1 the inner function's
value is u = 1^2 + 1 = 2. Then
\frac{dy}{du} = 3u^2 = 3 \cdot 2^2 = 12: right now,
y is changing 12 times as fast as
u.
-
Multiply the links.
\frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx} = 12 \times 2 = 24.
Exactly the currency calculation: u is the euros. Note how the
outer rate had to be evaluated at the euro amount you actually hold —
u = 2, not x = 1. The exchange desk
in Tokyo converts the euros in your pocket; it never sees your original pounds.
And chains needn't stop at two links. For a triple-decker
f(g(h(x))) — pounds → euros → yen → won — the rates simply keep
multiplying:
\frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dv}\cdot\frac{dv}{dx}.
Peel the outermost layer, multiply by the derivative of what's inside, and repeat until you
hit bare x. However deep the nesting, it's one multiplication
per layer.
Nested machines
One more picture, because this is the one that generalises furthest: a composite is two
machines wired in series. The input x runs through the inner
machine g, and that output runs through the outer machine
f. Nudge the input by a whisker: the inner machine amplifies the
nudge by g', and the outer machine amplifies that by
f'. Two amplifiers in series multiply their gains — step through
the figure to watch the nudge travel.
This is why the chain rule matters beyond textbook exercises: the real world is machines
feeding machines. Temperature drives ice-melt, ice-melt drives sea level; radius drives
area, area drives cost. Whenever you know each link's rate, the chain rule hands you the
end-to-end rate — one multiplication per link.
Two traps catch nearly every chain-rule beginner:
-
The classic half-answer: differentiating the outer function only.
Writing
\frac{d}{dx}(x^2+1)^5 = 5(x^2+1)^4 \quad\text{✗}
feels complete — it looks just like the power rule — but it's only half the job. You've
measured the outer gear and ignored the inner one. The derivative isn't finished until
you multiply by the inner derivative 2x:
10x(x^2+1)^4. Quick self-check: if the "inner" function is
just x itself, the extra factor is
1 and nothing changes — but if it's anything else,
a bare power-rule answer is wrong. When in doubt, write u = \ldots
down explicitly; the missing factor then has nowhere to hide.
-
The dus don't literally cancel. In
\frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx} it looks like
plain fraction arithmetic — cross out the dus and you're done.
But \frac{dy}{du} is not a fraction: it's a single
symbol for a limit, and du on its own isn't a number you can
cancel. The notation was designed (by Leibniz, deliberately) so that the true
theorem looks like cancellation — a brilliant mnemonic, and one reason his
notation conquered the world. Trust it as a memory aid; just remember that what makes the
equation true is a theorem about limits, not arithmetic on tiny quantities.
Every time you ask a modern AI a question, the answer was made possible by the chain rule —
run at a scale Leibniz couldn't have dreamed of. A neural network is exactly the "nested
machines" picture above, except with hundreds of layers instead of two:
f_{100}(f_{99}(\cdots f_2(f_1(x))\cdots)). Training the network
means asking, for each of its billions (sometimes trillions) of internal dials: if I
nudge this dial, how fast does the final error change? That is a derivative through a
very long chain — and the algorithm that computes it, backpropagation, is
nothing more than the chain rule applied layer by layer, multiplying link-rates from the
output back toward the input.
Every training step of every large AI model runs this multiplication through every layer,
for every parameter, billions of times over — making the chain rule, by any reasonable
count, the single most-executed rule of calculus in history. The two-gear picture you
played with above is, quite literally, the engine of the AI age with the layer count turned
down.
Watch Sal explain it
Spotting the inner and outer functions is the skill to practise; the rest is one
multiplication. Here is the chain rule introduced:
See it explained