Skip to content
  • Open the math solver
  • Ask the AI tutor
  • Find an AP course
  • Create a quiz
  • Open the calculator
  • Graphing Calculator
  • Browse all calculators
  • Read math guides
↑ ↓Enter to open · Esc to close
Solve a problem

Precalculus

Function Composition: How to Find and Use f(g(x))

By MathSolver Pro Editorial Team · Published

Composing functions means feeding the output of one function into another. It is how complicated formulas are built from simple pieces, and recognising those pieces is essential for inverses and for the chain rule in calculus.

What composition means

Given two functions ff and gg, the composition f∘gf \circ g, read f composed with g or f of g, is the function that first applies gg and then applies ff to the result:

(f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x))

The order is the part that confuses people. The function written on the right, closest to xx, acts first. Think of an assembly line: xx enters machine gg, the product g(x)g(x) moves on to machine ff, and f(g(x))f(g(x)) comes out. For this to work, every output of gg that you use must be an acceptable input of ff.

Composition is different from multiplication. The product (fg)(x)(fg)(x) means f(x)⋅g(x)f(x) \cdot g(x), which multiplies two outputs, while (f∘g)(x)(f \circ g)(x) substitutes one function into the other. The small circle symbol is what tells them apart.

Composing two formulas

To find f(g(x))f(g(x)), take the formula for ff and replace every xx in it with the whole expression g(x)g(x), in brackets. Then simplify.

Example 1: f(x)=2x+3f(x) = 2x + 3 and g(x)=x2g(x) = x^2

  1. f(g(x))=f(x2)=2x2+3f(g(x)) = f(x^2) = 2x^2 + 3.
  2. g(f(x))=g(2x+3)=(2x+3)2=4x2+12x+9g(f(x)) = g(2x + 3) = (2x + 3)^2 = 4x^2 + 12x + 9.
  3. At x=2x = 2: f(g(2))=f(4)=11f(g(2)) = f(4) = 11, while g(f(2))=g(7)=49g(f(2)) = g(7) = 49.

The two orders give completely different functions. Composition is not commutative in general: f∘gf \circ g and g∘fg \circ f are usually different, and you should never assume they are equal. It is associative, though, so f∘(g∘h)=(f∘g)∘hf \circ (g \circ h) = (f \circ g) \circ h, and a chain of three functions can be computed from the inside out.

Example 2: composing a function with itself

  1. For f(x)=2x+3f(x) = 2x + 3, find (f∘f)(x)=f(f(x))(f \circ f)(x) = f(f(x)).
  2. Substitute f(x)f(x) into ff: f(2x+3)=2(2x+3)+3=4x+9f(2x + 3) = 2(2x + 3) + 3 = 4x + 9.
  3. Check at x=1x = 1: f(1)=5f(1) = 5 and f(5)=13f(5) = 13, and 4(1)+9=134(1) + 9 = 13.

Always put brackets around the inner function when you substitute. Without them, g(2x+3)g(2x + 3) for g(x)=x2g(x) = x^2 easily becomes 2x+322x + 3^2, which is wrong.

Evaluating compositions from numbers and tables

Often you need only a single value. Work from the inside out: evaluate the inner function first, then use that result as the input of the outer function. It is not necessary to find the composed formula.

Suppose a table gives g(1)=4g(1) = 4, g(2)=0g(2) = 0, g(3)=2g(3) = 2 and f(0)=5f(0) = 5, f(2)=−1f(2) = -1, f(4)=3f(4) = 3. Then f(g(1))=f(4)=3f(g(1)) = f(4) = 3, f(g(2))=f(0)=5f(g(2)) = f(0) = 5, and f(g(3))=f(2)=−1f(g(3)) = f(2) = -1. If the table had no value for ff at the number produced by gg, that composition would simply be undefined at that input.

Graphs work the same way. To find f(g(3))f(g(3)) from two graphs, read g(3)g(3) off the graph of gg, then find that value on the x-axis of the graph of ff and read the output.

The domain of a composition

The domain of f∘gf \circ g contains exactly the inputs xx that satisfy two conditions: xx is in the domain of gg, and g(x)g(x) is in the domain of ff. Simplifying the composed formula can hide the first condition, so find the domain from the original pieces.

Example 3: f(x)=xf(x) = \sqrt{x} and g(x)=x−5g(x) = x - 5

  1. f(g(x))=x−5f(g(x)) = \sqrt{x - 5}. The input to the root must be at least zero, so the domain is [5,∞)[5, \infty).
  2. g(f(x))=x−5g(f(x)) = \sqrt{x} - 5. Here only x\sqrt{x} restricts the input, so the domain is [0,∞)[0, \infty).

Example 4: f(x)=1x−1f(x) = \dfrac{1}{x - 1} and g(x)=1xg(x) = \dfrac{1}{x}

  1. First condition: gg needs x≠0x \neq 0.
  2. Second condition: ff needs its input not equal to 1, so 1x≠1\frac{1}{x} \neq 1, which means x≠1x \neq 1.
  3. Simplify: f(g(x))=11x−1=11−xx=x1−xf(g(x)) = \frac{1}{\frac{1}{x} - 1} = \frac{1}{\frac{1 - x}{x}} = \frac{x}{1 - x}.
  4. The simplified formula only shows x≠1x \neq 1, but x=0x = 0 is also excluded because g(0)g(0) is undefined. Domain: all real numbers except 0 and 1.

A short example shows why this matters. If f(x)=x2f(x) = x^2 and g(x)=xg(x) = \sqrt{x}, then f(g(x))=(x)2=xf(g(x)) = (\sqrt{x})^2 = x, but only for x≥0x \ge 0. The formula xx alone suggests every real number works, which is false. The guide to domain and range covers the individual restrictions used here.

Decomposing a function

Decomposition runs the process backwards: given a complicated function hh, find simpler functions with h=f∘gh = f \circ g. Look for an inner expression that is being acted on by an outer operation.

  • h(x)=(3x−1)5h(x) = (3x - 1)^5: inner g(x)=3x−1g(x) = 3x - 1, outer f(u)=u5f(u) = u^5.
  • h(x)=x2+4h(x) = \sqrt{x^2 + 4}: inner g(x)=x2+4g(x) = x^2 + 4, outer f(u)=uf(u) = \sqrt{u}.
  • h(x)=esin⁡xh(x) = e^{\sin x}: inner g(x)=sin⁡xg(x) = \sin x, outer f(u)=euf(u) = e^u.
  • h(x)=1(x+2)2h(x) = \frac{1}{(x + 2)^2}: inner g(x)=x+2g(x) = x + 2, outer f(u)=1u2f(u) = \frac{1}{u^2}, or a three-step chain u=x+2u = x + 2, v=u2v = u^2, w=1vw = \frac{1}{v}.

Decompositions are not unique, but the most useful one usually has a simple inner function. Writing the inner part as uu is exactly the habit you will need for the chain rule and for substitution in integration.

Composition in calculus and inverses

Two major topics depend on composition. First, the chain rule differentiates a composition: the derivative of f(g(x))f(g(x)) is f′(g(x))⋅g′(x)f'(g(x)) \cdot g'(x). For (3x−1)5(3x - 1)^5 that gives 5(3x−1)4⋅3=15(3x−1)45(3x - 1)^4 \cdot 3 = 15(3x - 1)^4. The derivative rules guide covers this in depth.

Second, two functions are inverses exactly when composing them in either order returns the input: f(f−1(x))=xf(f^{-1}(x)) = x and f−1(f(x))=xf^{-1}(f(x)) = x on the appropriate domains. For f(x)=2x+3f(x) = 2x + 3 and f−1(x)=x−32f^{-1}(x) = \frac{x - 3}{2}, you get f(x−32)=x−3+3=xf\left(\frac{x - 3}{2}\right) = x - 3 + 3 = x. This is the standard way to verify an inverse, as explained in inverse functions.

A real-world example: discounts and coupons

A shop offers 20 percent off and you also have a coupon for 10 dollars off. Let d(p)=0.8pd(p) = 0.8p apply the discount to a price pp and c(p)=p−10c(p) = p - 10 apply the coupon. The order matters.

  • Coupon first, then discount: d(c(p))=0.8(p−10)=0.8p−8d(c(p)) = 0.8(p - 10) = 0.8p - 8.
  • Discount first, then coupon: c(d(p))=0.8p−10c(d(p)) = 0.8p - 10.
  • For a 50 dollar item, the first order costs 32 dollars and the second costs 30 dollars.

Applying the percentage first always saves 2 dollars here, because the coupon is not reduced by the percentage. Situations like this, where one process feeds into another, are compositions, and they show why the order of ff and gg is not just a technicality.

Common mistakes

  • Applying the functions in the wrong order: in f(g(x))f(g(x)), gg acts first.
  • Multiplying f(x)f(x) by g(x)g(x) instead of substituting.
  • Substituting without brackets, especially into powers and negative signs.
  • Finding the domain from the simplified formula only and missing values excluded by the inner function.
  • Assuming f∘g=g∘ff \circ g = g \circ f.

You can check both orders and their domains with the function composition calculator, which shows the substitution step explicitly.

Why composition is worth mastering

Almost every function you meet after algebra is built by composition. A formula for the temperature of a cooling drink, the position of a swinging pendulum or the value of an investment is typically a simple outer function, such as an exponential, a sine or a power, applied to a simpler inner expression. Being able to see that structure lets you predict the shape of a graph, find where a function is defined, and choose the right technique for derivatives and integrals.

Composition also explains graph transformations. Shifting the graph of ff three units to the right produces f(x−3)f(x - 3), which is ff composed with the inner function x−3x - 3. Stretching it vertically by a factor of 2 produces 2f(x)2f(x), which is the outer function 2u2u composed with ff. Seen this way, a transformation applied inside the brackets changes the input and acts horizontally, while one applied outside changes the output and acts vertically. That single observation explains why horizontal shifts seem to go the wrong way.

Practice problems with answers

Work these out on paper, then compare. Each uses one idea from the sections above.

  1. If f(x)=x2+1f(x) = x^2 + 1 and g(x)=x−3g(x) = x - 3, find f(g(x))f(g(x)). Answer: (x−3)2+1=x2−6x+10(x - 3)^2 + 1 = x^2 - 6x + 10.
  2. With the same functions, find g(f(x))g(f(x)). Answer: x2+1−3=x2−2x^2 + 1 - 3 = x^2 - 2.
  3. If f(x)=xf(x) = \sqrt{x} and g(x)=4−xg(x) = 4 - x, find the domain of f(g(x))f(g(x)). Answer: 4−x≥04 - x \ge 0, so (−∞,4](-\infty, 4].
  4. Decompose h(x)=ln⁡(x2+1)h(x) = \ln(x^2 + 1). Answer: inner x2+1x^2 + 1, outer ln⁡u\ln u.
  5. If f(x)=3x−2f(x) = 3x - 2, find f(f(2))f(f(2)). Answer: f(2)=4f(2) = 4 and f(4)=10f(4) = 10.

If your answer to the first problem was x2−2x^2 - 2, you applied the functions in the wrong order; that is the answer to the second problem. Mixing up the two orders is the most common error, and checking with a number such as x=0x = 0 catches it quickly: f(g(0))=f(−3)=10f(g(0)) = f(-3) = 10, while g(f(0))=g(1)=−2g(f(0)) = g(1) = -2.

Frequently asked questions

Which function do I apply first in f(g(x))?

The inner one, gg. Evaluate g(x)g(x) first, then use that result as the input of ff. The function closest to xx always acts first.

Is f(g(x)) the same as f(x) times g(x)?

No. f(g(x))f(g(x)) substitutes g(x)g(x) into ff, while f(x)g(x)f(x)g(x) multiplies the two outputs. For f(x)=x+1f(x) = x + 1 and g(x)=2xg(x) = 2x, f(g(x))=2x+1f(g(x)) = 2x + 1 but f(x)g(x)=2x2+2xf(x)g(x) = 2x^2 + 2x.

When does f(g(x)) equal g(f(x))?

Only in special cases, such as when one function is the inverse of the other, when one is the identity function, or for particular pairs like two linear functions through the origin. In general the two orders differ.

How do I find the domain of a composite function?

Start with the domain of the inner function, then remove any inputs whose inner output is not allowed in the outer function. Do this before simplifying, because simplifying can hide restrictions.

Can I compose more than two functions?

Yes. Compositions chain naturally, so f(g(h(x)))f(g(h(x))) applies hh, then gg, then ff. Work from the innermost function outwards, and check at each stage that the output is allowed as the next input.

MathSolver Pro Editorial Team

Math content and review

Our editorial team writes every guide to explain the reasoning behind each method, not just the answer. Each worked example is checked against the site's own solver engines and automated tests before it is published, and articles are revised whenever a method or an exam format changes.