Chain Rule Calculator
Last updated: 7 August 2026
Reviewed by Gavin Meiring, Lead research and primary author · Doctoral Candidate (Corporate Governance) · Research and drafting assisted by AI
- The chain rule first appeared in Leibniz's 1684 paper that launched the calculus — and his dy/dx notation makes it look like simple fraction cancellation: dy/dx = dy/du × du/dx.
- The chain rule is the workhorse of modern artificial intelligence: neural networks are trained by backpropagation, which is essentially the chain rule applied millions of times, popularised by Rumelhart, Hinton and Williams in 1986.
- Leibniz's chain rule was initially so confusingly stated that his contemporaries struggled with it — Isaac Newton is said to have claimed he could have written the paper in half the space.
Chain Rule Calculator
The chain rule calculator differentiates composite functions by applying the chain rule automatically, showing each step of the process. It is an essential tool for calculus students and anyone working with functions nested inside other functions, such as sin(x^2) or e^(3x+1). Enter your composite function to get the derivative instantly with full working.
How to Use the Chain Rule Calculator
- Enter your composite function f(g(x)) in the input field.
- The calculator identifies the outer function f and the inner function g(x).
- Click Calculate to apply the chain rule and find the derivative.
- Review the step-by-step output showing f'(g(x)) and g'(x) separately before combination.
- Verify the final result against any known derivatives to build confidence in the method.
The Formula
The chain rule states that for a composite function h(x) = f(g(x)):
h'(x) = f'(g(x)) * g'(x)
In words: differentiate the outer function (leaving the inner function unchanged), then multiply by the derivative of the inner function. A helpful way to remember this is: "derivative of the outside times derivative of the inside."
Using Leibniz notation, if y = f(u) and u = g(x):
dy/dx = (dy/du) * (du/dx)
Real-World Example
Find the derivative of h(x) = sin(3x^2).
- Identify the outer function: f(u) = sin(u), so f'(u) = cos(u)
- Identify the inner function: g(x) = 3x^2, so g'(x) = 6x
- Apply the chain rule: h'(x) = cos(3x^2) * 6x = 6x cos(3x^2)
The derivative of sin(3x^2) is 6x cos(3x^2). The chain rule correctly differentiates the outer sine function while multiplying by the derivative of the inner 3x^2.
Applying the Chain Rule to Multiple Layers
The chain rule extends naturally to functions with more than two layers. For a triple composite function h(x) = f(g(k(x))):
h'(x) = f'(g(k(x))) * g'(k(x)) * k'(x)
You work from the outermost function inward, multiplying each derivative as you go. For example, the derivative of e^(sin(x^2)) requires three applications: differentiating the exponential, then the sine, then x^2. Practising multi-layer examples helps build fluency in spotting composite structure within more complex expressions.
Frequently Asked Questions
How do I recognise when to use the chain rule? Use the chain rule whenever a function is composed of two or more functions. If substituting u for an inner expression would give a simpler form, the chain rule applies. Common examples include trigonometric functions of polynomials, exponentials with non-linear exponents, and logarithms of expressions other than plain x.
Can I combine the chain rule with the product rule? Yes, and this is common. If your function is a product where one or both factors are themselves composite, you apply the product rule first to split the derivative, then the chain rule to differentiate each composite factor.
What is a common mistake when using the chain rule? The most common error is forgetting to multiply by the derivative of the inner function. Students often differentiate the outer function correctly but fail to include g'(x), giving an incomplete result.
Does the chain rule work for implicit differentiation? Yes. When differentiating an equation implicitly with respect to x, every y term is treated as a composite function of x, so the chain rule applies. Each time you differentiate a y term, you multiply the result by dy/dx.
A worked example with three layers
Two layers are the easy case. Three layers are where most mistakes happen, so the worked example here is a function nested three deep:
h(x) = ln(cos(x^2))
Work from the outside in and name each layer before differentiating anything.
| Layer | Function | Its derivative |
|---|---|---|
| Outer | ln(u) | 1/u |
| Middle | cos(v) | -sin(v) |
| Inner | x^2 | 2x |
The chain rule turns those three derivatives into one product, with each derivative evaluated at the layer inside it: 1/cos(x^2), multiplied by -sin(x^2), multiplied by 2x. The first two factors collapse into a tangent, because sin divided by cos is tan, so the answer simplifies to:
h'(x) = -2x tan(x^2)
That simplified form is worth reaching for, because it is the version a numeric check confirms most cleanly. The table below compares the formula against a central difference estimate at four points.
| x | h(x) | h'(x) from the formula | h'(x) by central difference | Difference |
|---|---|---|---|---|
| 0.2 | -0.00080021 | -0.01600854 | -0.01600854 | 4.1e-11 |
| 0.5 | -0.03158105 | -0.25534192 | -0.25534192 | 1.2e-10 |
| 1.0 | -0.61562647 | -3.11481545 | -3.11481545 | 2.1e-09 |
| 1.2 | -2.03696683 | -18.24438255 | -18.24438277 | 2.2e-07 |
The central difference column is not a second method to learn. It is a way of asking the formula a question that involves no algebra, and its agreement to nine or ten decimal places is the answer.
A check you can run on any derivative
A central difference estimates the slope at a point by measuring the function a small distance either side, then dividing the rise by the run. With a step of 0.001 the arithmetic fits on one line.
Take h(x) = (3x + 1)^5. The chain rule gives h'(x) = 5(3x + 1)^4, multiplied by 3, which is 15(3x + 1)^4. At x = 1 that is 15 times 4^4, which is 15 times 256, or 3840.
Now estimate the same slope from the function alone. h(1.001) = 4.003^5 = 1027.84576432. h(0.999) = 3.997^5 = 1020.16575568. The rise is 7.68000864 across a run of 0.002, which gives 3840.00.
| Step size | h at 1 + step | h at 1 - step | Estimate | Error against 3840 |
|---|---|---|---|---|
| 0.01 | 1062.98033622 | 986.17169618 | 3840.432 | 0.432 |
| 0.001 | 1027.84576432 | 1020.16575568 | 3840.004 | 0.004 |
| 0.0001 | 1024.38405760 | 1023.61605760 | 3840.000 | 0.000 |
Shrinking the step improves the estimate, which is what makes this a real check rather than a coincidence. A derivative that disagrees with the numeric estimate by a wide margin is wrong, and you have found the error without re-reading your own algebra.
A table of composites and their derivatives
These six cover the shapes that turn up most often in coursework. Each derivative is confirmed numerically at x = 0.5.
| h(x) | h'(x) | h(0.5) | h'(0.5) |
|---|---|---|---|
| sin(3x^2) | 6x cos(3x^2) | 0.68163876 | 2.19506661 |
| e^(3x + 1) | 3e^(3x + 1) | 12.18249396 | 36.54748188 |
| ln(x^2 + 1) | 2x / (x^2 + 1) | 0.22314355 | 0.80000000 |
| (2x + 7)^4 | 8(2x + 7)^3 | 4096.00000000 | 4096.00000000 |
| sqrt(4x^2 + 9) | 4x / sqrt(4x^2 + 9) | 3.16227766 | 0.63245553 |
| cos(x^3) | -3x^2 sin(x^3) | 0.99219767 | -0.09350605 |
The fourth row surprises people. Both the function and its derivative are exactly 4096 at x = 0.5, because 2x + 7 is 8 there and 8 times 8^3 is also 4096. That is a coincidence of the chosen point, not a property of the function.
Combining with the product rule
When a product has a composite factor, differentiate the product first and let the chain rule handle each factor. For h(x) = x^2 sin(3x), the product rule gives 2x sin(3x) plus x^2 times the derivative of sin(3x). The chain rule supplies that last piece, since the derivative of sin(3x) is 3 cos(3x).
| x | h(x) | h'(x) from the combined rule | h'(x) by central difference |
|---|---|---|---|
| 0.5 | 0.24937375 | 1.05054789 | 1.05054789 |
| 1.0 | 0.14112001 | -2.68773747 | -2.68773747 |
| 2.0 | -1.11766199 | 10.40438145 | 10.40438145 |
The same combination works the other way round. For h(x) = sin(x) / (x^2 + 1), the quotient rule handles the fraction and the chain rule does its work inside the denominator. At x = 1 the result is -0.15058434.
Where the rule stops working
The chain rule carries a precondition. The inner function has to be differentiable where you evaluate it, and the outer function has to be differentiable at the value the inner one produces. When either condition fails, the rule does not apply and the derivative may not exist at all.
The logarithmic example is the clearest case. ln(cos(x^2)) exists only where cos(x^2) is positive, because the logarithm of a non-positive number is undefined. That holds up to the first zero of the cosine.
| x | cos(x^2) | Is ln defined |
|---|---|---|
| 1.25 | +0.0082962316 | Yes |
| 1.2533 | +0.0000354368 | Yes |
| 1.26 | -0.0168028824 | No |
| 1.30 | -0.1189215693 | No |
The boundary sits at x = sqrt(pi/2), which is 1.25331414. The domain of the function is the open interval from negative that value to positive that value. A derivative quoted outside that interval describes a slope on a curve that is not there.
Two other preconditions catch people out. A function with a corner or a cusp, such as the absolute value function at zero, is not differentiable at that point, and no amount of chain rule arithmetic produces a valid slope there. A composite whose inner function is constant across an interval has a derivative of zero throughout, which the rule reports correctly but which usually means the problem was set up wrong.
What a symbolic answer assumes
The calculator differentiates with respect to x unless told otherwise. It identifies the outer and inner functions before differentiating, which is why the step-by-step output shows the two derivatives separately rather than only the combined result. That split matters, because the most common error is differentiating the outer function correctly and never multiplying by the inner derivative.
Several assumptions sit behind a symbolic answer. Every other letter in the expression is treated as a constant, so sin(ax) differentiates to a cos(ax) rather than to something containing a derivative of a. The tool applies the standard differentiation rules instead of a numeric or series method, so results arrive as exact expressions rather than decimal approximations. Simplification follows convention, which is why -2x tan(x^2) and -2x sin(x^2) / cos(x^2) may appear in either order of preference: they are the same function, and the choice reflects display rules rather than mathematics.
The output is a derivative, not an antiderivative. No constant of integration appears, and none should.
Where the rule comes from
Every introductory calculus text states the rule in the same two forms. In function notation, the derivative of f(g(x)) is f'(g(x)) multiplied by g'(x). In Leibniz notation, if y is a function of u and u is a function of x, then dy/dx = (dy/du)(du/dx).
OpenStax Calculus Volume 1 sets out the rule in section 3.6, "The Chain Rule". That section covers the rule for a composition of two functions, its combination with the power, product and quotient rules, the extension to three or more functions, and a statement of the proof. Learning objective 3.6.5 is specifically to describe that proof, which works by rewriting the difference quotient for the composite function as the product of the outer and inner difference quotients plus a correction term that vanishes in the limit.
The multi-layer form used above, f'(g(k(x))) g'(k(x)) k'(x), is the same rule applied twice rather than a separate result. That is why working from the outside in always works, however many layers a function has.
Also try these free tools: