AP · Precalculus · Composition and Inverse Functions

Composition of Functions

15 min readUpdated November 30, 2026FreeAP Precalculus, Exponential and Logarithmic Functions

A composite function feeds the output of one function into another: (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)), where gg acts first and ff acts second. You evaluate it from the inside out, whether the functions are given as formulas, tables or graphs. Order matters, because f(g(x))f(g(x)) and g(f(x))g(f(x)) are usually different, and the identity function I(x)=xI(x) = x leaves any function unchanged.

Quick check

  1. If f(x)=x2−3f(x) = x^2 - 3, what is f(−2)f(-2)?Show answerHide answer

    f(−2)=(−2)2−3=4−3=1f(-2) = (-2)^2 - 3 = 4 - 3 = 1.

  2. If f(x)=2x+5f(x) = 2x + 5, what is f(a+1)f(a + 1)?Show answerHide answer

    f(a+1)=2(a+1)+5=2a+7f(a + 1) = 2(a + 1) + 5 = 2a + 7. The whole input a+1a + 1 replaces xx.

  3. If g(3)=5g(3) = 5 and f(5)=12f(5) = 12, what is f(g(3))f(g(3))?Show answerHide answer

    1212. First g(3)=5g(3) = 5, then f(5)=12f(5) = 12.

Know these already? Jump to the practice questions

What you'll be able to do

  • Evaluate f(g(a))f(g(a)) when ff and gg are given by formulas, tables or graphs.
  • Explain why f(g(x))f(g(x)) and g(f(x))g(f(x)) are usually different functions.
  • Write a composite function as a single formula.
  • Rewrite a given function as a composition of an inner and an outer function.
  • Describe what composing with the identity function does.

Key terms

Composite function

The function f∘gf \circ g defined by (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)): the output of gg becomes the input of ff.

In plain English
Do gg, then do ff to the result.
Don't write
"(f∘g)(x)=f(x)⋅g(x)(f \circ g)(x) = f(x) \cdot g(x)"; the circle means composition, not multiplication.

Inner and outer function

In f(g(x))f(g(x)), gg is the inner function, applied first, and ff is the outer function, applied second.

In plain English
The inner function is the one in the middle of the brackets.
Don't write
"ff is applied first because it is written first"; the function next to xx goes first.

Identity function

The function I(x)=xI(x) = x, which returns every input unchanged. Its graph is the line y=xy = x.

In plain English
The "do nothing" function.
Don't write
"I(x)=1I(x) = 1"; that is a constant function, not the identity.

How do you evaluate f(g(a))?

Learn this: (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)). Work from the inside out: find g(a)g(a) first, then use that number as the input to ff.

From formulas: with f(x)=x2−3f(x) = x^2 - 3 and g(x)=2x+1g(x) = 2x + 1, g(2)=5g(2) = 5, so f(g(2))=f(5)=22f(g(2)) = f(5) = 22.

From a table: find the inner value in one row, then look it up again in the other row.

xx0011223344
f(x)f(x)3344002211
g(x)g(x)2200441133

For f(g(1))f(g(1)), the gg row gives g(1)=0g(1) = 0, and then the ff row gives f(0)=3f(0) = 3.

From a graph: read g(a)g(a) off the graph of gg, then put it into ff. The figure "The graph of y = g(x), made of a segment from (−2, 3) to (0, −1) and a segment from (0, −1) to (4, 3)" gives g(−1)=1g(-1) = 1, so with f(x)=x2−3f(x) = x^2 - 3, f(g(−1))=f(1)=−2f(g(-1)) = f(1) = -2.

Key idea

Inside first: the output of the inner function is the input of the outer function.

Check yourself

Using the table, find g(f(0))g(f(0)).
Show answerHide answer

11. The ff row gives f(0)=3f(0) = 3, and the gg row gives g(3)=1g(3) = 1.

Why does the order matter, and when does it not?

Take f(x)=x2f(x) = x^2 and g(x)=x+3g(x) = x + 3. Then f(g(x))=(x+3)2f(g(x)) = (x + 3)^2, which adds 33 and then squares, while g(f(x))=x2+3g(f(x)) = x^2 + 3, which squares and then adds 33. At x=1x = 1 these give 1616 and 44. So composition is not commutative: in general f(g(x))≠g(f(x))f(g(x)) \neq g(f(x)).

This links to transformations. With g(x)=x+3g(x) = x + 3 inside, f(x+3)f(x + 3) shifts the graph of ff left 33 units. With gg outside, f(x)+3f(x) + 3 shifts it up 33 units. The same function gg gives a horizontal change on the inside and a vertical change on the outside.

The identity function is the main exception. Because I(x)=xI(x) = x hands back its input,

f(I(x))=f(x)andI(f(x))=f(x)f(I(x)) = f(x) \quad \text{and} \quad I(f(x)) = f(x)

so composing with II in either order leaves ff unchanged, much as multiplying by 11 leaves a number unchanged. When f(g(x))=xf(g(x)) = x and g(f(x))=xg(f(x)) = x, each function undoes the other; that is the idea behind the note on Inverse Functions.

Check yourself

For f(x)=2xf(x) = 2x and g(x)=x−5g(x) = x - 5, write f(g(x))f(g(x)) and g(f(x))g(f(x)).
Show answerHide answer

f(g(x))=2(x−5)=2x−10f(g(x)) = 2(x - 5) = 2x - 10 and g(f(x))=2x−5g(f(x)) = 2x - 5. They differ, so the order matters.

How do you write a composite as one formula?

Replace every xx in the outer function with the whole inner expression, in brackets, then simplify. For f(x)=x2−3xf(x) = x^2 - 3x and g(x)=2x+1g(x) = 2x + 1:

f(g(x))=(2x+1)2−3(2x+1)=4x2+4x+1−6x−3=4x2−2x−2f(g(x)) = (2x + 1)^2 - 3(2x + 1) = 4x^2 + 4x + 1 - 6x - 3 = 4x^2 - 2x - 2

The brackets matter: the 33 multiplies all of 2x+12x + 1, not just 2x2x. Check by substituting a value: at x=2x = 2, g(2)=5g(2) = 5 and f(5)=25−15=10f(5) = 25 - 15 = 10, and 4(4)−2(2)−2=104(4) - 2(2) - 2 = 10 too.

Compositions often produce exponential functions in new forms. With f(x)=3xf(x) = 3^x and g(x)=2x−1g(x) = 2x - 1, f(g(x))=32x−1f(g(x)) = 3^{2x - 1}, which the exponent rules turn into 13⋅9x\frac{1}{3} \cdot 9^x (see the note on Working with Exponential Expressions).

Examiner's eye

Marks are lost when brackets are left off the inner function. Write f(2x+1)f(2x + 1) with (2x+1)(2x + 1) in every place xx appeared.

Check yourself

For f(x)=x−4f(x) = x - 4 and g(x)=x2g(x) = x^2, write g(f(x))g(f(x)) as one formula.
Show answerHide answer

g(f(x))=(x−4)2=x2−8x+16g(f(x)) = (x - 4)^2 = x^2 - 8x + 16.

How do you split a function into inner and outer parts?

Ask what you would do to xx first when you compute the function. That first step is the inner function gg, and what is done to its result is the outer function ff.

h(x)h(x)Inner g(x)g(x)Outer f(x)f(x)
(3x−5)4(3x - 5)^43x−53x - 5x4x^4
2x22^{x^2}x2x^22x2^x
x+7−1\sqrt{x + 7} - 1x+7x + 7x−1\sqrt{x} - 1
5x−2\dfrac{5}{x - 2}x−2x - 25x\dfrac{5}{x}

Always check by composing back: for the first row, f(g(x))=(3x−5)4f(g(x)) = (3x - 5)^4, as required.

A decomposition is not unique. For example, (3x−5)4(3x - 5)^4 is also f(g(x))f(g(x)) with g(x)=(3x−5)2g(x) = (3x - 5)^2 and f(x)=x2f(x) = x^2. Any split that composes back to hh is correct, but splitting at the first operation is usually the most useful.

Check yourself

Write h(x)=(x2+1)3h(x) = (x^2 + 1)^3 as f(g(x))f(g(x)).
Show answerHide answer

g(x)=x2+1g(x) = x^2 + 1 and f(x)=x3f(x) = x^3. Then f(g(x))=(x2+1)3f(g(x)) = (x^2 + 1)^3.

Which method fits the question?

The question gives youDo this
A number, such as f(g(2))f(g(2))Inside out: find g(2)g(2), then ff of that
Tables or a graphRead the inner value, then look it up for the outer function
"Write f(g(x))f(g(x))"Substitute g(x)g(x), in brackets, for every xx in ff, then simplify
A single h(x)h(x) to splitThe first operation on xx is the inner function

Worked example 1: Composing from a table

Question: Use the table of ff and gg in the section on evaluating, where f(0),f(1),f(2),f(3),f(4)f(0), f(1), f(2), f(3), f(4) are 3,4,0,2,13, 4, 0, 2, 1 and g(0),g(1),g(2),g(3),g(4)g(0), g(1), g(2), g(3), g(4) are 2,0,4,1,32, 0, 4, 1, 3. Find (a) f(g(2))f(g(2)), (b) g(f(2))g(f(2)), (c) f(g(f(4)))f(g(f(4))).

What tells you the method

Every value is a lookup, so work from the innermost function outward.

  1. Step 1: Part (a).

    g(2)=4g(2) = 4, then f(4)=1f(4) = 1.

    Why

    gg is inside, so it is read first.

  2. Step 2: Part (b).

    f(2)=0f(2) = 0, then g(0)=2g(0) = 2.

    Why

    Now ff is inside; the order has swapped.

  3. Step 3: Part (c).

    f(4)=1f(4) = 1, then g(1)=0g(1) = 0, then f(0)=3f(0) = 3.

    Why

    With three layers, keep working outward one lookup at a time.

Check it

Parts (a) and (b) give 11 and 22, different results for the same input, as the order rule predicts.

Answer

(a) f(g(2))=1f(g(2)) = 1. (b) g(f(2))=2g(f(2)) = 2. (c) f(g(f(4)))=3f(g(f(4))) = 3.

Worked example 2: Both orders as formulas

Question: Let f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x−2g(x) = 3x - 2. Write f(g(x))f(g(x)) and g(f(x))g(f(x)) as single formulas, and evaluate both at x=1x = 1.

What tells you the method

"write as single formulas" means substitute and expand.

  1. Step 1: Find f(g(x))f(g(x)).

    f(3x−2)=(3x−2)2+1=9x2−12x+4+1=9x2−12x+5f(3x - 2) = (3x - 2)^2 + 1 = 9x^2 - 12x + 4 + 1 = 9x^2 - 12x + 5.

    Why

    g(x)g(x), in brackets, replaces xx in ff.

  2. Step 2: Find g(f(x))g(f(x)).

    g(x2+1)=3(x2+1)−2=3x2+1g(x^2 + 1) = 3(x^2 + 1) - 2 = 3x^2 + 1.

    Why

    Now f(x)f(x) replaces xx in gg.

  3. Step 3: Evaluate at x=1x = 1.

    f(g(1))=9−12+5=2f(g(1)) = 9 - 12 + 5 = 2 and g(f(1))=3+1=4g(f(1)) = 3 + 1 = 4.

    Why

    This confirms the two orders give different functions.

Check it

Inside out, g(1)=1g(1) = 1 and f(1)=2f(1) = 2; also f(1)=2f(1) = 2 and g(2)=4g(2) = 4. Both match.

Answer

f(g(x))=9x2−12x+5f(g(x)) = 9x^2 - 12x + 5 and g(f(x))=3x2+1g(f(x)) = 3x^2 + 1; at x=1x = 1 they equal 22 and 44.

Worked example 3: An exponential composite

Question: Let h(x)=5⋅23x+1h(x) = 5 \cdot 2^{3x + 1}. (a) Write h(x)=f(g(x))h(x) = f(g(x)), where gg is linear and ff is exponential. (b) Rewrite h(x)h(x) in the form a⋅bxa \cdot b^x.

What tells you the method

The exponent 3x+13x + 1 is computed first, so it is the inner function.

  1. Step 1: Split the function.

    g(x)=3x+1g(x) = 3x + 1 and f(x)=5⋅2xf(x) = 5 \cdot 2^x.

    Why

    Then f(g(x))=5⋅23x+1=h(x)f(g(x)) = 5 \cdot 2^{3x + 1} = h(x).

  2. Step 2: Split the exponent.

    23x+1=2⋅23x=2⋅8x2^{3x + 1} = 2 \cdot 2^{3x} = 2 \cdot 8^x.

    Why

    The product rule, then (23)x=8x(2^3)^x = 8^x.

  3. Step 3: Combine constants.

    h(x)=5⋅2⋅8x=10⋅8xh(x) = 5 \cdot 2 \cdot 8^x = 10 \cdot 8^x.

    Why

    The form a⋅bxa \cdot b^x has one constant in front.

Check it

At x=0x = 0, 5⋅21=105 \cdot 2^1 = 10 and 10⋅80=1010 \cdot 8^0 = 10.

Answer

(a) g(x)=3x+1g(x) = 3x + 1 and f(x)=5⋅2xf(x) = 5 \cdot 2^x. (b) h(x)=10⋅8xh(x) = 10 \cdot 8^x, so a=10a = 10 and b=8b = 8.

Your turn

Question: Let f(x)=xf(x) = \sqrt{x} and g(x)=x2+9g(x) = x^2 + 9. Find f(g(4))f(g(4)), and write g(f(x))g(f(x)) as a single formula for x≥0x \geq 0.

  1. Step 1:

    Inside first: g(4)=16+9=25g(4) = 16 + 9 = 25.

  2. Step 2: Your go: apply ff to 2525, then substitute x\sqrt{x} into gg.

Show the full solutionHide the solution

f(25)=25=5f(25) = \sqrt{25} = 5. For the formula, g(x)=(x)2+9=x+9g(\sqrt{x}) = (\sqrt{x})^2 + 9 = x + 9, which holds for x≥0x \geq 0, where x\sqrt{x} is defined.

Answer: f(g(4))=5f(g(4)) = 5, and g(f(x))=x+9g(f(x)) = x + 9 for x≥0x \geq 0.

Traps

Trap

Thinking f(g(2))f(g(2)) starts by finding f(2)f(2).

It seems right because ff is written first and you read left to right. But the input 22 goes into gg first, so you find g(2)g(2) and then apply ff to it.

Check yourself

With f(x)=x+1f(x) = x + 1 and g(x)=3xg(x) = 3x, which is f(g(2))f(g(2)): 77 or 99?
Show answerHide answer

77. g(2)=6g(2) = 6 and f(6)=7f(6) = 7. The value 99 is g(f(2))g(f(2)).

Trap

Thinking (f∘g)(x)(f \circ g)(x) means f(x)⋅g(x)f(x) \cdot g(x).

It seems right because the small circle looks like a multiplication dot. But ∘\circ means composition: (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)).

Check yourself

For f(x)=x+2f(x) = x + 2 and g(x)=4xg(x) = 4x, find (f∘g)(1)(f \circ g)(1).
Show answerHide answer

66, because g(1)=4g(1) = 4 and f(4)=6f(4) = 6. Multiplying would give 3×4=123 \times 4 = 12.

Trap

Thinking f(2x+1)f(2x + 1) for f(x)=x2−3xf(x) = x^2 - 3x is 2x+12−3⋅2x+12x + 1^2 - 3 \cdot 2x + 1.

It seems right because you only swap xx for the new expression. But the whole expression replaces xx, so it needs brackets: (2x+1)2−3(2x+1)(2x + 1)^2 - 3(2x + 1).

Check yourself

For f(x)=5−xf(x) = 5 - x, write f(x+4)f(x + 4).
Show answerHide answer

5−(x+4)=1−x5 - (x + 4) = 1 - x. Without brackets you would get 5−x+4=9−x5 - x + 4 = 9 - x, which is wrong.

What's examined

Composition of functions is part of Unit 2 (Exponential and Logarithmic Functions) of the AP® Precalculus exam, in both the multiple-choice and free-response sections. Expect to evaluate composites from formulas, tables and graphs, write a composite as one formula, and split a function into inner and outer parts. All of it is done by hand. The same skill sets up inverse functions, which have their own note.

Practice questions

  1. Recall Let f(x)=2x+1f(x) = 2x + 1 and g(x)=x2g(x) = x^2. What is (f∘g)(3)(f \circ g)(3)?
    • A) 4949
    • B) 1919
    • C) 6363
    • D) 1616
Show answer

Answer: B) 1919

Marking points:

  • g(3)=9g(3) = 9, then f(9)=19f(9) = 19.
  • A is g(f(3))=72g(f(3)) = 7^2. C multiplies f(3)⋅g(3)=7×9f(3) \cdot g(3) = 7 \times 9. D adds f(3)+g(3)f(3) + g(3).
  1. Recall The table gives values of ff and gg: f(1)=3f(1) = 3, f(2)=4f(2) = 4, f(3)=1f(3) = 1, f(4)=2f(4) = 2, and g(1)=2g(1) = 2, g(2)=4g(2) = 4, g(3)=1g(3) = 1, g(4)=3g(4) = 3. Find f(g(3))f(g(3)) and g(f(3))g(f(3)).
xx11223344
f(x)f(x)33441122
g(x)g(x)22441133
Show answer

Answer: f(g(3))=3f(g(3)) = 3 and g(f(3))=2g(f(3)) = 2.

Marking points:

  • g(3)=1g(3) = 1, then f(1)=3f(1) = 3.
  • f(3)=1f(3) = 1, then g(1)=2g(1) = 2.
  1. Apply Let f(x)=x−4f(x) = x - 4 and g(x)=x2g(x) = x^2. Which expression is g(f(x))g(f(x))?
    • A) x2−4x^2 - 4
    • B) x2−16x^2 - 16
    • C) x3−4x2x^3 - 4x^2
    • D) x2−8x+16x^2 - 8x + 16
Show answer

Answer: D) x2−8x+16x^2 - 8x + 16

Marking points:

  • g(f(x))=(x−4)2=x2−8x+16g(f(x)) = (x - 4)^2 = x^2 - 8x + 16.
  • A is f(g(x))f(g(x)). B squares each term separately. C multiplies f(x)⋅g(x)f(x) \cdot g(x).
  1. Apply The graph of gg is made of two line segments, from (−2,3)(-2, 3) to (0,−1)(0, -1) and from (0,−1)(0, -1) to (4,3)(4, 3), as in the figure "The graph of y = g(x), made of a segment from (−2, 3) to (0, −1) and a segment from (0, −1) to (4, 3)". Let f(x)=2x−1f(x) = 2x - 1. Find f(g(0))f(g(0)) and g(f(2))g(f(2)).
Show answer

Answer: f(g(0))=−3f(g(0)) = -3 and g(f(2))=2g(f(2)) = 2.

Marking points:

  • g(0)=−1g(0) = -1, so f(−1)=2(−1)−1=−3f(-1) = 2(-1) - 1 = -3.
  • f(2)=3f(2) = 3; on the segment from (0,−1)(0, -1) to (4,3)(4, 3), g(x)=x−1g(x) = x - 1, so g(3)=2g(3) = 2.
  1. Apply Let h(x)=5x+2h(x) = \sqrt{5x + 2}. Which pair of functions gives h(x)=f(g(x))h(x) = f(g(x))?
    • A) f(x)=xf(x) = \sqrt{x} and g(x)=5x+2g(x) = 5x + 2
    • B) f(x)=5x+2f(x) = 5x + 2 and g(x)=xg(x) = \sqrt{x}
    • C) f(x)=xf(x) = \sqrt{x} and g(x)=5xg(x) = 5x
    • D) f(x)=5xf(x) = \sqrt{5x} and g(x)=x+2g(x) = x + 2
Show answer

Answer: A) f(x)=xf(x) = \sqrt{x} and g(x)=5x+2g(x) = 5x + 2

Marking points:

  • 5x+25x + 2 is computed first, so it is the inner function, and the square root is the outer one.
  • B gives 5x+25\sqrt{x} + 2, the reverse order. C gives 5x\sqrt{5x}, missing the 22. D gives 5x+10\sqrt{5x + 10}.
  1. Exam-style Let f(x)=4⋅3xf(x) = 4 \cdot 3^x and g(x)=2x−1g(x) = 2x - 1. (a) Write f(g(x))f(g(x)) in the form a⋅bxa \cdot b^x. (b) Find g(f(1))g(f(1)).
Show answer

Answer: (a) f(g(x))=43⋅9xf(g(x)) = \frac{4}{3} \cdot 9^x, so a=43a = \frac{4}{3} and b=9b = 9. (b) g(f(1))=23g(f(1)) = 23.

Marking points:

  • f(g(x))=4⋅32x−1=4⋅3−1⋅(32)x=43⋅9xf(g(x)) = 4 \cdot 3^{2x - 1} = 4 \cdot 3^{-1} \cdot (3^2)^x = \frac{4}{3} \cdot 9^x.
  • f(1)=12f(1) = 12, so g(12)=24−1=23g(12) = 24 - 1 = 23.
  1. Exam-style Let f(x)=x2−2xf(x) = x^2 - 2x and g(x)=x+kg(x) = x + k, where kk is a constant. If f(g(x))=x2+4x+3f(g(x)) = x^2 + 4x + 3 for all xx, what is the value of kk?
    • A) −1-1
    • B) 22
    • C) 33
    • D) 44
Show answer

Answer: C) 33

Marking points:

  • f(x+k)=(x+k)2−2(x+k)=x2+(2k−2)x+k2−2kf(x + k) = (x + k)^2 - 2(x + k) = x^2 + (2k - 2)x + k^2 - 2k.
  • Matching xx terms: 2k−2=42k - 2 = 4, so k=3k = 3; the constant 9−6=39 - 6 = 3 also matches.
  • A solves only k2−2k=3k^2 - 2k = 3 and fails the xx term. B ignores the −2x-2x in ff. D reads the coefficient 44 as kk.

Key points

Recall, then reveal

Say the main points from memory first, then check them.

Show key pointsHide key points
  • f(g(x))f(g(x)) means apply gg first, then ff; evaluate from the inside out with formulas, tables or graphs.
  • Swapping the order usually changes the result, so f∘gf \circ g and g∘fg \circ f are different functions.
  • To write a composite as one formula, put the inner expression in brackets wherever xx appears in the outer function.
  • To split h(x)h(x), the first operation on xx is the inner function; check by composing back.
  • The identity I(x)=xI(x) = x changes nothing: f(I(x))=I(f(x))=f(x)f(I(x)) = I(f(x)) = f(x).

Figures

A graph made of two straight segments. The first runs down from (−2, 3) to (0, −1). The second runs up from (0, −1) through (2, 1) to (4, 3). (open full size in a new tab)
The graph of y = g(x), made of a segment from (−2, 3) to (0, −1) and a segment from (0, −1) to (4, 3)

Keep learning

Explore AP Precalculus tutoring →

View the full Precalculus syllabus →

More in this unit

Exponential and Logarithmic Functions

All Composition and Inverse Functions notes

Part of Novark's AP Precalculus notes