Dove's LibraryDove's Library

2.7 - Composition of Functions

Overview

Composing functions means feeding the output of one function into another. It lets you build new functions out of simpler ones, connect quantities that aren't directly related by one formula, and break complicated functions into pieces. Composition also sets up inverse functions in Topic 2.8.

What composition means

If ff and gg are functions, the composite function f∘gf \circ g (read “ff composed with gg” or “ff of gg”) is defined by
(f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x))
Work from the inside out: gg acts first, and its output becomes the input of ff.
2.7 - Composition of Functions

The domain of a composite function

For f(g(x))f(g(x)) to exist, two things must be true:
  1. xx is in the domain of gg.
  1. g(x)g(x) is in the domain of ff.
So the domain of f∘gf \circ g is restricted to the inputs of gg whose outputs ff can accept.
For example, let f(x)=xf(x) = \sqrt{x} and g(x)=x−3g(x) = x - 3. Then f(g(x))=x−3f(g(x)) = \sqrt{x - 3}. The function gg accepts any xx, but ff only accepts inputs that are at least 0, so we need x−3≥0x - 3 \geq 0. The domain of f∘gf \circ g is x≥3x \geq 3.

Evaluating composite functions

You can find values of f∘gf \circ g from any representation of ff and gg: equations, tables, graphs, or words. The process is always the same: find the output of gg, then use it as the input of ff.

Example 1: From equations

Let f(x)=x2−1f(x) = x^2 - 1 and g(x)=2x+3g(x) = 2x + 3. Find f(g(−1))f(g(-1)) and g(f(−1))g(f(-1)).
First composition. Start inside, with gg:
g(−1)=2(−1)+3=1g(-1) = 2(-1) + 3 = 1f(g(−1))=f(1)=12−1=0f(g(-1)) = f(1) = 1^2 - 1 = 0
Second composition. Now ff goes first:
f(−1)=(−1)2−1=0f(-1) = (-1)^2 - 1 = 0g(f(−1))=g(0)=2(0)+3=3g(f(-1)) = g(0) = 2(0) + 3 = 3
Answer: f(g(−1))=0f(g(-1)) = 0 and g(f(−1))=3g(f(-1)) = 3. Same two functions, same input, different order, different answers.

Example 2: From a table

Use the table to find each value.
xx
0
1
2
3
4
f(x)f(x)
2
4
1
6
0
g(x)g(x)
3
0
4
1
2
(a) f(g(0))f(g(0)): the table gives g(0)=3g(0) = 3, so f(g(0))=f(3)=6f(g(0)) = f(3) = 6.
(b) g(f(0))g(f(0)): the table gives f(0)=2f(0) = 2, so g(f(0))=g(2)=4g(f(0)) = g(2) = 4.
(c) f(f(2))f(f(2)): the table gives f(2)=1f(2) = 1, so f(f(2))=f(1)=4f(f(2)) = f(1) = 4.
(d) g(f(3))g(f(3)): the table gives f(3)=6f(3) = 6, but 6 isn't an input in the table for gg. So g(f(3))g(f(3)) can't be found from this table. This is the domain rule in action: the output of the inside function has to be an input the outside function accepts.

Example 3: From graphs

The graphs of ff and gg are shown. Find f(g(3))f(g(3)), g(f(3))g(f(3)), and f(g(6))f(g(6)).
2.7 - Composition of Functions
(a) From the graph of gg, g(3)=2g(3) = 2. From the graph of ff, f(2)=6f(2) = 6. So f(g(3))=6f(g(3)) = 6.
(b) From the graph of ff, f(3)=5f(3) = 5. From the graph of gg, g(5)=4g(5) = 4. So g(f(3))=4g(f(3)) = 4.
(c) From the graph of gg, g(6)=1g(6) = 1. From the graph of ff, f(1)=4f(1) = 4. So f(g(6))=4f(g(6)) = 4.

Order matters

Composition is not commutative: f∘gf \circ g and g∘fg \circ f are usually different functions, so f(g(x))f(g(x)) and g(f(x))g(f(x)) usually give different values. Example 1 showed this (00 versus 33). Compare the formulas for f(x)=x2f(x) = x^2 and g(x)=x+3g(x) = x + 3:
f(g(x))=(x+3)2g(f(x))=x2+3f(g(x)) = (x + 3)^2 \qquad g(f(x)) = x^2 + 3
The first adds 3 and then squares. The second squares and then adds 3. At x=1x = 1, they give 1616 and 44.

The identity function

The function f(x)=xf(x) = x is the identity function: it returns whatever you give it. Composing any function gg with the identity changes nothing:
g(f(x))=f(g(x))=g(x)when f(x)=xg(f(x)) = f(g(x)) = g(x) \quad \text{when } f(x) = x
The identity function plays the same role for composition that 0 plays for addition (a+0=aa + 0 = a) and 1 plays for multiplication (a⋅1=aa \cdot 1 = a). This idea is the heart of inverse functions in Topic 2.8: a function and its inverse compose to give the identity.

Building composite functions

Substituting one formula into another

To write f(g(x))f(g(x)) as a formula, replace every xx in ff with the whole expression g(x)g(x). Use parentheses so nothing gets lost.

Example 4: Writing a composite formula

Let f(x)=2x2−x+1f(x) = 2x^2 - x + 1 and g(x)=x−4g(x) = x - 4. Write f(g(x))f(g(x)) in standard form.
f(g(x))=2(x−4)2−(x−4)+1f(g(x)) = 2(x - 4)^2 - (x - 4) + 1=2(x2−8x+16)−x+4+1= 2(x^2 - 8x + 16) - x + 4 + 1=2x2−16x+32−x+5= 2x^2 - 16x + 32 - x + 5=2x2−17x+37= 2x^2 - 17x + 37
Answer: f(g(x))=2x2−17x+37f(g(x)) = 2x^2 - 17x + 37. Quick check at x=4x = 4: g(4)=0g(4) = 0 and f(0)=1f(0) = 1, and the formula gives 2(16)−68+37=12(16) - 68 + 37 = 1. It matches.

Tables and graphs of a composite function

Without formulas, you can still build a table or graph of f∘gf \circ g: for each input xx, find f(g(x))f(g(x)) and record the pair (x,f(g(x)))(x, f(g(x))). Using the graphs from Example 3:
xx
0
1
2
3
4
5
6
g(x)g(x)
5
4
3
2
3
4
1
f(g(x))f(g(x))
2
4
5
6
5
4
4
Plotting the points (x,f(g(x)))(x, f(g(x))) gives a graph of f∘gf \circ g.

Connecting quantities through a middle quantity

Composition is useful when two quantities aren't linked by one formula but are both linked to a third quantity. If AA depends on BB and BB depends on CC, composing gives AA in terms of CC.

Example 5: Factory costs over time (AP-style)

A factory produces n(t)=40tn(t) = 40t items in tt hours. The cost of producing nn items is C(n)=500+12nC(n) = 500 + 12n dollars.
(a) Write the cost as a function of time. (b) Find and interpret C(n(5))C(n(5)). (c) Does n(C(t))n(C(t)) make sense?
Part (a). Substitute n(t)n(t) into CC:
C(n(t))=500+12(40t)=500+480tC(n(t)) = 500 + 12(40t) = 500 + 480t
Part (b).
C(n(5))=500+480(5)=2900C(n(5)) = 500 + 480(5) = 2900
In 5 hours the factory makes n(5)=200n(5) = 200 items, and producing them costs $2,900.
Part (c). No. The output of CC is a cost in dollars, but nn expects an input in hours. The output of the inside function has to be the kind of input the outside function uses. This is another reason order matters.

Decomposing functions

Going the other way, a complicated function can often be written as a composition of simpler ones. Find the “inside” expression that is being plugged into something and call it g(x)g(x). The operation done to it becomes ff. When a function is properly decomposed, the variable of ff replaces every copy of g(x)g(x).
h(x)h(x)
Inside: g(x)g(x)
Outside: f(x)f(x)
5x−2\sqrt{5x - 2}
5x−25x - 2
x\sqrt{x}
3x23^{x^2}
x2x^2
3x3^x
12x+1\frac{1}{2^x + 1}
2x+12^x + 1
1x\frac{1}{x}
(x2+1)3−4(x2+1)(x^2 + 1)^3 - 4(x^2 + 1)
x2+1x^2 + 1
x3−4xx^3 - 4x
The last row shows the rule: both copies of x2+1x^2 + 1 become xx in ff. Decompositions aren't unique. For example, 5x−2\sqrt{5x - 2} is also f(g(x))f(g(x)) with f(x)=x−2f(x) = \sqrt{x - 2} and g(x)=5xg(x) = 5x. Any pair that works is correct unless a question asks for a specific form.

Transformations as compositions

The transformations from Unit 1 are compositions with simple linear functions:
  • An additive transformation (a translation) is a composition with g(x)=x+kg(x) = x + k.
  • A multiplicative transformation (a dilation) is a composition with g(x)=kxg(x) = kx.
Whether gg goes inside or outside decides the direction:
Composition
Result
Effect on the graph of ff
f(g(x))f(g(x)) with g(x)=x+kg(x) = x + k
f(x+k)f(x + k)
Horizontal translation by −k-k
g(f(x))g(f(x)) with g(x)=x+kg(x) = x + k
f(x)+kf(x) + k
Vertical translation by kk
f(g(x))f(g(x)) with g(x)=kxg(x) = kx
f(kx)f(kx)
Horizontal dilation by a factor of 1∣k∣\frac{1}{|k|}
g(f(x))g(f(x)) with g(x)=kxg(x) = kx
kf(x)kf(x)
Vertical dilation by a factor of ∣k∣|k|
If k<0k < 0, the dilations also reflect the graph: over the yy-axis for f(kx)f(kx) and over the xx-axis for kf(x)kf(x). The pattern to remember: inside changes are horizontal, outside changes are vertical.

Example 6: A transformation as a chain of compositions

Write h(x)=5⋅2x−1+4h(x) = 5 \cdot 2^{x - 1} + 4 as a composition of f(x)=2xf(x) = 2^x with simple linear functions.
Follow what happens to xx, in order:
  1. Subtract 1: p(x)=x−1p(x) = x - 1. This shifts the graph right 1.
  1. Apply ff: f(p(x))=2x−1f(p(x)) = 2^{x - 1}.
  1. Multiply by 5: q(x)=5xq(x) = 5x. This stretches the graph vertically by a factor of 5.
  1. Add 4: r(x)=x+4r(x) = x + 4. This shifts the graph up 4.
h(x)=r(q(f(p(x))))=5⋅2x−1+4h(x) = r(q(f(p(x)))) = 5 \cdot 2^{x - 1} + 4

Common mistakes

  • Working outside in. In f(g(x))f(g(x)), gg goes first.
  • Treating composition as multiplication. f(g(x))f(g(x)) is not f(x)⋅g(x)f(x) \cdot g(x).
  • Dropping parentheses. With f(x)=x2f(x) = x^2 and g(x)=x−4g(x) = x - 4, f(g(x))=(x−4)2f(g(x)) = (x - 4)^2, not x2−4x^2 - 4.
  • Ignoring the domain. The output of the inside function must be in the domain of the outside function.
  • Assuming order doesn't matter. f(g(x))f(g(x)) and g(f(x))g(f(x)) are usually different.

AP® is a registered trademark of the College Board, which is not affiliated with Dove's Library and was not involved in the production of, and does not endorse, this website.

Providing free, high-quality AP notes to help students succeed, earn college credit, and reach their educational goals, ensuring everyone has access to the resources they need.

© 2026 Standard Learning Group, Inc., which operates Dove's Library. All rights reserved.