How the Chain Rule Works
Functions Inside Functions
What happens when you compose f(g(x))?
Composition means plugging one function into another. Here g(x) = 2x + 1 runs first, then its output feeds into f(g) = g². The value flows left to right: x = 1.5 → g = 4.0 → f = 16.00.
Step 1 of 6: Functions Inside Functions
What happens when you compose f(g(x))?
Composition means plugging one function into another. Here g(x) = 2x + 1 runs first, then its output feeds into f(g) = g². The value flows left to right: x = 1.5 → g = 4.0 → f = 16.00.
Step 2 of 6: Local Derivatives
Each function has its own rate of change
Each function has a local derivative -- its own rate of change. For g(x) = 2x + 1, dg/dx = 2 (always 2). For f(g) = g², df/dg = 2g = 8.0 (depends on what g outputs).
Step 3 of 6: Multiply the Chain
The total derivative is the product of local ones
The chain rule says: multiply the local derivatives together. At x = 1.5: g'(x) = 2 × f'(g) = 8.0 = 16.0. A tiny nudge to x gets amplified 16.0× at the output.
Step 4 of 6: A Longer Chain
What about f(g(h(x)))?
With three functions composed as f(g(h(x))), the chain rule still works the same way -- just multiply all the local derivatives together. Notice how dh/dx = cos(1.0) = 0.540 can shrink or flip the total derivative depending on x.
Step 5 of 6: Chains in Networks
Each layer is a function — backprop IS the chain rule
Each layer in a neural network is just a function. The forward pass goes left to right, and backpropagation sends gradients right to left. At each layer, multiply by the local derivative -- that's the chain rule in action.
Step 6 of 6: Why It Matters
Without the chain rule, deep learning wouldn't work
In a shallow network, the gradient passes through few multiplications and stays strong. In a deep network, the chain rule multiplies many local derivatives together. If those derivatives are small (< 1), the gradient vanishes -- early layers barely learn. Understanding the chain rule led to innovations like ResNets, batch normalization, and careful initialization that keep gradients flowing.