If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Chain rule overview

A quick overview sheet of the chain rule.

Introduction

If f(x) and g(x) are two functions, for instance f(x)=x2 and g(x)=sin(x), we know how to take the derivative of their sum:
Rule:ddx(f(x)+g(x))=f(x)+g(x)
Example:ddx(x2+sin(x))=2x+cos(x)
We also know how to take the derivative of their product:
Rule:ddx(f(x)g(x))=f(x)g(x)+g(x)f(x)
Example:ddx(x2sin(x))=x2cos(x)+sin(x)2x
The chain rule now tells us how to take the derivative of their composition, meaning f(g(x)):
Rule:ddx(f(g(x))=f(g(x))g(x)
Example:ddx(sin(x))2=2(sin(x))cos(x)

Intuition using fake algebra

Warning: The following section may induce headache or queasiness for readers who are sensitive to violent abuse of notation.
We tend to write functions and derivatives in terms of the variable x.
ddx(x2)=2x
But of course, we could use any other letter.
dda(a2)=2a
What if we did something crazy, and replaced x with a function instead of another letter.
dd(sin(x))(sin(x))2=2sin(x)
It's unclear exactly what this dd(sin(x)) symbol would mean, but let's just go with it for a second. We can imagine multiplying it by d(sin(x))dx to "cancel out" the d(sin(x)) term:
d(sin(x))2d(sin(x))d(sin(x))dx=ddx(sin(x))2
This is not really a mathematically legitimate thing to do, since these "dx" and "d(sin(x))" terms are not numbers or functions that we can cancel out. There are ways to make this more legitimate that involve some more advanced math, but for now you can think of it as a useful memory trick. The usefulness is that when we expand ddx(sin(x))2 like this, we know what each individual term is, even if we don't know how to take the derivative of (sin(x))2:
ddx(sin(x))2=d(sin(x))2d(sin(x))Imagine replacing xwith sin(x) in d(x2)dxd(sin(x))dxOrdinary derivativeof sin(x)=2sin(x)cos(x)
This trick looks particularly clean when we write it in the abstract, rather than with the specific case of x2 and sin(x):
ddx[f(g(x))]=dfdgdgdx

Example 1:

f(x)=sin(x2)Function to differentiateu(x)=x2Define u(x) as inside functionf(x)=sin(u)Express f(x) in terms of u(x)dfdx=dfdududxExpress chain rule applicable heredfdx=ddusin(u)ddx(x2)Substitute in f(u) and u(x)dfdx=cos(u)2xEvaluate derivativesdfdx=cos(x2)(2x)Substitute u in terms of x.

Example 2:

One pretty cool thing we can now do is find the derivative of the absolute value function |x|, which can be defined as x2. For example, |5|=(5)2=25=5
f(x)=|x|Function to differentiatef(x)=x2Equivalent functionu(x)=x2Define u(x) as inside functionf(x)=[u(x)]12Express f(x) in terms of u(x)dfdx=dfdududxExpress chain rule applicable heredfdx=dduu12ddx(x2)Substitute in f(u) and u(x)dfdx=12u122xCompute derivatives with power ruledfdx=12(x2)122xSubstitute u(x) back in terms of xdfdx=xx2Simplifydfdx=x|x|Express x2 as absolute value.

Arbitrarily long composition

The chain rule can apply to composing multiple functions, not just two. For example, suppose A(x), B(x), C(x) and D(x) are four different functions, and define f to be their composition:
f(x)=A(B(C(D(x))))
Using the dfdx notation for the derivative, we can apply the chain rule as:
dfdx=ddxA(B(C(D(x)))=dAdBdBdCdCdDdDdx
Using f notation, we get more of a snowman aesthetic:
f(x)=A(B(C(D(x))))B(C(D(x)))C(D(x))D(x)

Example 4:

Suppose f(x)=sin(ex2+x).
We think of f as being the composition of
A(x)=sin(x)B(x)=exC(x)=x2+x
Where the derivative of each function is
A(x)=cos(x)B(x)=exC(x)=2x+1
According to the chain rule, the derivative of the composition is
f(x)=A(B(C(x)))B(C(x))C(x)=cos(ex2+x)ex2+x(2x+1)

Want to join the conversation?

  • piceratops ultimate style avatar for user Mevlan Isufi
    I just finished this tutorial about the Chain Rule by watching all videos and solving all given problems; and now im confused at this overview. At the very first Introduction they mention "We also know how to take the derivative of their product:". I watched all videos and solved tens of problems and never heard or faced any problem like that. Looks like they will introduce it in next tutorials about "Taking Derivatives" or what? Please HELP !
    (8 votes)
    Default Khan Academy avatar avatar for user
  • duskpin tree style avatar for user mebble
    Is there a more detailed lesson on the derivative of |x|?
    (7 votes)
    Default Khan Academy avatar avatar for user
    • piceratops ultimate style avatar for user Just Keith
      Note that f(x) = |x| is not differentiable at x=0
      The easiest way to do this is by rewriting |x|
      |x| = √(x²) (this is the principal square root only, do not simplify at this point)
      d/dx √(x²)
      = d/dx (x²)^(½)
      = ½ (x²)^(−½) ∙ d/dx (x²)
      = ½ (x²)^(−½) ∙ (2x)
      Rearranging:
      = ½ (2x)∙ (x²)^(−½)
      =(x)∙ (x²)^(−½)
      = (x)÷(x²)^(−½)
      = x ÷ |x|
      This is a piecewise function:
      f'(x) =  −1, for x < 0
      1, for x > 0
      f'(x) is undefined at x=0
      (15 votes)
  • male robot hal style avatar for user klimax
    On the last example, we can treat x^2+x as a function. But why we cannot treat 2 in x^2 as a function?
    (6 votes)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user Grant
      While you can treat "2" as a function, namely the constant function f(x) = 2 that outputs 2 for all inputs, raising one function to the power of another like f(x)^g(x) is different from composing functions, as in f(g(x)). For example, the chain rule cannot be used to take the derivative of x^x.
      (1 vote)
  • purple pi purple style avatar for user Mary Shultz
    It appears that examples one and two are the same.
    (5 votes)
    Default Khan Academy avatar avatar for user
  • leaf green style avatar for user miles marcuson
    I'm appalled by this violent abuse of notation. What did that derivative ever do to you?
    (5 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user MaHmoud ImBabi
    if u=f(x^2-y^2,2xy) , find (partial^2u/partial x^2)
    let r=x^2-y^2
    t=2xy
    how can i get this partial ??
    (2 votes)
    Default Khan Academy avatar avatar for user
  • starky ultimate style avatar for user DeepShankarPratap
    I want to how to differentiate :y=√cosx+√cosx+√cosx+....∞ prove dy∕dx= sinx/1-2y.
    I wanna know how to differentiate infinite series.?HELP!!
    (1 vote)
    Default Khan Academy avatar avatar for user
    • duskpin ultimate style avatar for user Don Eckford
      First check your final expression it needs parenthesis to be readable.
      Both cos(x) and sqrt(x) have infinite series representation.
      You can take the derivative into a series term by term.
      But it looks like you can rewrite your series using some form of e^(ln(g(x))) or the like where g(x) is your original series.
      I suggest rewriting using lim (n-> inf) g(x)
      Then use facts like e^a * e^b = e^(a+b)
      and ln(a* b* c*) = ln a + ln b + ln (c)
      and for any power series that you can write down taking the derivative of the term by term
      is equivalent to integrating the derivative (look in the section)" operations on power series"
      (4 votes)
  • leaf blue style avatar for user Борислав Николов
    In the Practice: Differentiate composite functions I have a problem. I can't understand when 'v' is the outside part and when 'u' is the inside part of the function. In every exercise they change and I am getting confused.
    (1 vote)
    Default Khan Academy avatar avatar for user
    • male robot johnny style avatar for user Vishal Pal
      For that purpose there is a rule of thumb.
      ILATE

      I - Inverse trigonometric(sin^-1 , cos^-1 , etc.
      L - Logarithmic (log)
      A - Arithmatic (x^n , n is a real no.)
      T - Trigonometric (sin, cos , etc.)
      E - Exponential ( a^x)


      The function coming first (from left to right ) is taken to be 'u' and other one is taken to be 'v'.

      Hope that helps :)
      (3 votes)
  • aqualine ultimate style avatar for user Martin Xia
    A(e^(x^2+x))=sin(e^(x^2+x))
    B(e^x)=e^(x^2+x)=(e^x)^(x+1)
    C(x)=e^x
    then,
    f'(x)=cos(e^(x^2+x))*e^(x^2+x)*(x+1)
    Why?
    (2 votes)
    Default Khan Academy avatar avatar for user
  • female robot grace style avatar for user wengi
    Just a quick question about something barely related to this subject.
    In example 3, at some point we get
    f(x) = √(x²) = (x²)^½

    Wouldn't we then be able to expand (x²)^½ in that way :

    (x²)^½ --> x^(2/2) --> x^1 --> x

    Somewhere along the way the |x| is turned into a simple x.

    What is wrong with my logic ?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • duskpin sapling style avatar for user Vu
      Normally we could and would do that. But since f(x)=|x| is a piecewise function, f(x)=|x| {-x for x<0 ; x for x>0}, we want to keep it √(x²) as a one-piece function for our purpose of taking its derivative.
      (1 vote)