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

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:

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:

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:

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?

Exactly the currency calculation: u is the euros. Note how the outer rate had to be evaluated at the euro amount you actually holdu = 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:

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