Calculus guide · 6 min read

Chain Rule Explained With Examples (Step by Step)

The chain rule is how you differentiate a function inside another function, like (3x + 1)^5 or sin(x^2). It shows up in almost every derivative past the basics, so it is worth getting automatic at spotting it. This guide explains the rule, then works through every common type of example.

The Chain Rule Formula

If y=f(g(x))y = f(g(x)), then:

ddx[f(g(x))]=f′(g(x))⋅g′(x)\frac{d}{dx}\left[f(g(x))\right] = f'(g(x)) \cdot g'(x)

In words: differentiate the outside function, leave the inside alone, then multiply by the derivative of the inside.

In Leibniz notation, if yy depends on uu and uu depends on xx:

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

Why it works: rates multiply. If uu changes 3 times as fast as xx, and yy changes 2 times as fast as uu, then yy changes 2⋅3=62 \cdot 3 = 6 times as fast as xx.

How to Spot the Inside and Outside

Ask: "What would I calculate last if I plugged in a number?" That last operation is the outside function.

FunctionOutsideInside
(3x+1)5(3x + 1)^5u5u^53x+13x + 1
sin⁡(x2)\sin(x^2)sin⁡u\sin ux2x^2
e4xe^{4x}eue^u4x4x
ln⁡(x2+1)\ln(x^2 + 1)ln⁡u\ln ux2+1x^2 + 1
1−x2\sqrt{1 - x^2}u\sqrt{u}1−x21 - x^2

If the inside is just plain xx, the inside derivative is 1 and you do not need the chain rule.

Example 1: A Power of a Polynomial

Example: Differentiate y=(2x3−5)4y = (2x^3 - 5)^4.

  1. Outside: u4u^4. Inside: u=2x3−5u = 2x^3 - 5.
  2. Differentiate the outside and keep the inside unchanged: 4(2x3−5)34(2x^3 - 5)^3.
  3. Differentiate the inside: 6x26x^2.
  4. Multiply: 4(2x3−5)3⋅6x2=24x2(2x3−5)34(2x^3 - 5)^3 \cdot 6x^2 = 24x^2(2x^3 - 5)^3.

Using Leibniz notation for the same problem: dydu=4u3\frac{dy}{du} = 4u^3 and dudx=6x2\frac{du}{dx} = 6x^2, so dydx=4u3⋅6x2=24x2(2x3−5)3\frac{dy}{dx} = 4u^3 \cdot 6x^2 = 24x^2(2x^3 - 5)^3.

Example 2: Trig Functions

Example: Differentiate sin⁡(5x2)\sin(5x^2).

  1. Outside: sin⁡u\sin u, whose derivative is cos⁡u\cos u. Inside: 5x25x^2.
  2. Outside derivative with the inside kept: cos⁡(5x2)\cos(5x^2).
  3. Inside derivative: 10x10x.
  4. Answer: 10xcos⁡(5x2)10x\cos(5x^2).

Example: Differentiate cos⁡3x\cos^3 x.

  1. Rewrite it so the structure is clear: cos⁡3x=(cos⁡x)3\cos^3 x = (\cos x)^3. The outside is the cube, and the inside is cos⁡x\cos x.
  2. Outside derivative: 3(cos⁡x)23(\cos x)^2.
  3. Inside derivative: −sin⁡x-\sin x.
  4. Answer: −3sin⁡xcos⁡2x-3\sin x \cos^2 x.

Notice the difference: in sin⁡(5x2)\sin(5x^2) the trig function is outside, while in cos⁡3x\cos^3 x the power is outside.

Example 3: Exponentials and Logarithms

ddx[eu]=eu⋅u′ddx[ln⁡u]=u′u\frac{d}{dx}\left[e^{u}\right] = e^{u} \cdot u' \qquad \frac{d}{dx}\left[\ln u\right] = \frac{u'}{u}

Example: Differentiate ex2e^{x^2}.

  1. Outside: eue^u, which is its own derivative. Inside: x2x^2.
  2. Answer: ex2⋅2x=2xex2e^{x^2} \cdot 2x = 2xe^{x^2}.

Example: Differentiate ln⁡(x2+1)\ln(x^2 + 1).

  1. Outside: ln⁡u\ln u, with derivative 1u\frac{1}{u}. Inside: x2+1x^2 + 1.
  2. Answer: 1x2+1⋅2x=2xx2+1\frac{1}{x^2 + 1} \cdot 2x = \frac{2x}{x^2 + 1}.

Example 4: A Chain Inside a Chain

Some functions have three or more layers. Peel them one at a time, from the outside in, and multiply every derivative together.

Example: Differentiate sin⁡3(2x)\sin^3(2x).

  1. Rewrite: [sin⁡(2x)]3\left[\sin(2x)\right]^3. The layers are: cube, then sine, then 2x2x.
  2. Derivative of the cube: 3sin⁡2(2x)3\sin^2(2x).
  3. Derivative of the sine: cos⁡(2x)\cos(2x).
  4. Derivative of 2x2x: 22.
  5. Multiply: 3sin⁡2(2x)⋅cos⁡(2x)⋅2=6sin⁡2(2x)cos⁡(2x)3\sin^2(2x) \cdot \cos(2x) \cdot 2 = 6\sin^2(2x)\cos(2x).

Example 5: Chain Rule With the Product Rule

Example: Differentiate h(x)=x2(3x+1)4h(x) = x^2(3x + 1)^4.

  1. The whole thing is a product, so start with the product rule: f=x2f = x^2 and g=(3x+1)4g = (3x + 1)^4.
  2. f′=2xf' = 2x.
  3. For g′g', use the chain rule: 4(3x+1)3⋅3=12(3x+1)34(3x + 1)^3 \cdot 3 = 12(3x + 1)^3.
  4. Product rule: h′(x)=2x(3x+1)4+x2⋅12(3x+1)3h'(x) = 2x(3x + 1)^4 + x^2 \cdot 12(3x + 1)^3.
  5. Factor out 2x(3x+1)32x(3x + 1)^3: h′(x)=2x(3x+1)3[(3x+1)+6x]h'(x) = 2x(3x + 1)^3\left[(3x + 1) + 6x\right].
  6. Simplify: h′(x)=2x(3x+1)3(9x+1)h'(x) = 2x(3x + 1)^3(9x + 1).

Paste a function into the VeilGPT solver to check each layer of your chain rule work.

Common mistakes

  • Forgetting to multiply by the derivative of the inside function, which turns the derivative of (3x + 1)^5 into 5(3x + 1)^4 instead of 15(3x + 1)^4.
  • Changing the inside while differentiating the outside, like writing 4(6x^2)^3 instead of 4(2x^3 - 5)^3 times 6x^2.
  • Mixing up sin^2(x), which means (sin x)^2, with sin(x^2), which has x^2 inside the sine.
  • Stopping after one layer on a nested function such as sin^3(2x), and missing the final factor of 2.

Try one yourself

Find the derivative of y = sin^2(4x + 1)

Work it out, then check every step with the VeilGPT calculus solver.

Check it with VeilGPT

Questions about this topic

How do I know when to use the chain rule?

Use it any time something other than plain x sits inside a function, like (3x + 1)^5, sin(4x), or e^(x^2). If you could call part of the expression u, you need the chain rule.

What is the difference between the chain rule and the product rule?

The product rule is for two functions multiplied together, like x^2 sin x. The chain rule is for one function inside another, like sin(x^2). Many problems need both.

Does the chain rule work with any number of layers?

Yes. For f(g(h(x))), the derivative is f'(g(h(x))) times g'(h(x)) times h'(x). Each layer adds one more factor.

More study guides