Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Composition






Functions Within Functions

Some processes happen in stages. Convert a temperature from Celsius to Fahrenheit, then from Fahrenheit to Rankine. Apply a discount to a price, then add tax to the result. Each stage is a function, and the stages chain together — the output of one becomes the input of the next.

This chaining is composition. Given functions ff and gg, the composition f∘gf \circ g applies gg first, then feeds the result into ff. The output of gg becomes the input of ff, creating a single combined process from two separate ones.

Key Terms

Core

Composition of Functions— (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)), output of gg becomes input of ff
Inverse Function— composing a function with its inverse yields the identity: f(f−1(x))=xf(f^{-1}(x)) = x

Supporting

Function— the building blocks being chained
Domain— the domain of f∘gf \circ g requires xx in the domain of gg and g(x)g(x) in the domain of ff
One-to-One Function— required for a function to have an inverse, which composition can verify


See All Function Definitions →


What is Function Composition

Many rules come in two steps, and keeping them as two separate functions means carrying the middle value by hand.
"Triple the number and subtract 2, then square the result and add 1" is one process, but written as two functions you must work out the first answer, write it down, and feed it to the second. It is like an assembly line where each station hands its part to the next: what matters is the finished product, not the part in between.
The definition
The composition of ff with gg, written f∘gf \circ g, is the function that sends xx to f(g(x))f(g(x)): apply gg first, then apply ff to its output.
If gg takes an input xx and produces g(x)g(x), and ff then takes g(x)g(x) and produces f(g(x))f(g(x)), the composition f∘gf \circ g captures this two-step process as a single function:
Composition of Functions
(f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x))
Learn more about this formula: Composition of Functions →
Read it inside out: gg is written on the right, but it acts first.
f ∘ g is a function in its own right — one input, one output — built from two others.
Function composition connects two functions in sequence: the output of the first becomes the input of the second. The result is a new function that combines both operations.
-10-5510-55f(g(x)) = (sin x)²g(f(x)) = sin(x²)
f(x) = x², g(x) = sin x: f(g(x)) = (sin x)²

The output of the inner function feeds the outer one: every value sin x is squared, so the composite curve is the sine wave with its negative halves folded up. Swap the order and g(f(x)) = sin(x²) is a wave that speeds up as x grows; the two composites are different functions. Compare the two orders for any pair on the function composition explorer.

The function gg acts first, transforming the original input. The function ff acts second, transforming the intermediate result. The final output depends on both functions working in sequence.
Composition differs fundamentally from arithmetic. Adding functions combines their outputs at the same input: (f+g)(x)=f(x)+g(x)(f + g)(x) = f(x) + g(x). Composing functions chains their operations: (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)). The input to ff in composition is not xx but g(x)g(x).
With g(x) = 3x − 2 and f(x) = x² + 1, each input passes through g and then through f.
The middle column is the value handed from gg to ff; the last column is (f∘g)(x)(f \circ g)(x).
xg(x) = 3x − 2f(g(x)) = g(x)² + 1
0−25
112
2417
410101
The definition promised a single function, and it delivers one: the two steps collapse into one rule.
Substituting g(x)g(x) into ff gives (f∘g)(x)=(3x−2)2+1=9x2−12x+5(f \circ g)(x) = (3x - 2)^2 + 1 = 9x^2 - 12x + 5, a formula with no middle step at all. It gives the same outputs as the two-step chain.
xtwo steps: f(g(x))one rule: 9x² − 12x + 5
050 − 0 + 5 = 5
129 − 12 + 5 = 2
21736 − 24 + 5 = 17
4101144 − 48 + 5 = 101
Two limits on the definition: the order is fixed, and not every x gets through.
The order of the two functions is part of the definition, not a detail.
Here g∘fg \circ f sends 44 to g(17)=49g(17) = 49, not 101101 — see non-commutativity. And xx belongs to f∘gf \circ g only if g(x)g(x) is something ff accepts, which the section on the domain of composite functions works through.
Composition creates new functions with potentially different domains, ranges, and properties than either component.
The rest of the page covers the notation, evaluating compositions at a point and algebraically, the domain, the order, longer chains, composing a function with itself, decomposing, inverses and reading compositions off graphs.

Composition Notation

Notation

Composition Notation

One operation, three spellings: the ring, the nested parentheses, and the juxtaposition some texts risk. The order rule — right side acts first — is the whole game, and all three forms appear among the function symbols.
f(x)f(x), the letter conventions and substitution come from function notation; the domain restrictions a composition inherits are written with domain notation.
f∘gf \circ g
f composed with g; f after g
The hollow ring is the composition operator: f∘gf \circ g is one new function, built by feeding gg's output to ff. Read right-to-left — gg sits second but acts first; "f after g" is the reading that encodes the order.
CasesIterates hide the ring: in dynamics f2f^2 means f∘ff \circ f — while the squared shorthand sin⁡2θ\sin^2\theta squares the value; the superscript's meaning flips by field, so careful texts write f∘ff \circ f out.
Do not confuseThe multiplication dot. f∘gf \circ g and f⋅gf \cdot g differ by hollowness alone — one chains rules, the other multiplies outputs; and the ring is not the degree mark °°, which rides superscript on a number.
f(g(x))f(g(x))
f of g of x
The self-explaining spelling: nesting shows the order — evaluate inside out, g(x)g(x) first, then ff of the result. (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)) is the bridge between the two forms.
CasesAt a point the nesting becomes a two-step computation — (f∘g)(4)(f \circ g)(4) runs g(4)g(4) then ff of it, the drill of Evaluating Compositions at a Point below; spoken aloud, "f of g of x" preserves both order and sequence.
Do not confuseg(f(x))g(f(x)). Same letters, opposite machine — f∘gf \circ g and g∘fg \circ f are generally different functions, as the 101≠49101 \neq 49 example below demonstrates; the notation is order-critical.
fg(x)fg(x)
f g of x — ambiguous
The risky spelling: some texts drop the ring and juxtapose, trusting context to rule out multiplication. Best avoided in elementary work — the same string means the product in function arithmetic, where (fg)(x)=f(x)⋅g(x)(fg)(x) = f(x) \cdot g(x).
CasesWhere it is standard: operator theory and abstract algebra compose by juxtaposition routinely, because composition is the only product those settings have.
Do not confuseA product. fg(x)fg(x) read as f(x)⋅g(x)f(x) \cdot g(x) versus f(g(x))f(g(x)) — two different numbers from one string; the ring or the nest costs one symbol and removes the ambiguity entirely.
DownloadPNG2×PDF
Notation · Cheat sheet
Function Notation at a Glance
The marks from the notation cards across the function pages: how each is read and what it means. Every group links to the full card on its page.
Basics
f(x)f(x)
f of x
ff names the rule, f(x)f(x) its output; never f times x.
g(t),  P(n)g(t), \; P(n)
g of t; P of n
Any letter can name a function; tt hints at time, nn at counting.
f(x+1)f(x + 1)
f of x plus one
Whatever is in the brackets replaces xx everywhere.
Domain
[2,5)[2, 5)
two included, five excluded
Square bracket in, round bracket out.
{x∣x≥0}\{x \mid x \geq 0\}
all x such that
Set-builder: the variable, then the test it must pass.
(a,b)∪(c,d)(a, b) \cup (c, d)
a union of intervals
For domains in separate pieces, as (−∞,−1)∪(1,∞)(-\infty, -1) \cup (1, \infty).
Range
{y∣y≥0}\{y \mid y \geq 0\}
all y such that
The same grammar on the output side.
f:R→Rf: \mathbb{R} \to \mathbb{R}
f from R to R
Domain, then codomain; the range may be smaller.
{2,5,7}\{2, 5, 7\}
exactly these outputs
A finite range listed in braces.
Function arithmetic
(f+g)(x)(f + g)(x)
f plus g, of x
Equals f(x)+g(x)f(x) + g(x); the same for f−gf - g.
(fg)(x)(fg)(x)
f times g, of x
Equals f(x) g(x)f(x)\,g(x).
(fg)(x)\left(\frac{f}{g}\right)(x)
f over g, of x
Equals f(x)g(x)\frac{f(x)}{g(x)}, only where g(x)≠0g(x) \neq 0.
CompositionThis page
f∘gf \circ g
f after g
Feed the output of gg into ff; read right to left.
f(g(x))f(g(x))
f of g of x
The same thing, evaluated inside out.
fg(x)fg(x)
ambiguous
Could mean a product; avoid it for composition.
Inverse functions
f−1(x)f^{-1}(x)
f inverse of x
The function that undoes ff: f−1(f(x))=xf^{-1}(f(x)) = x.
1f(x),  (f(x))−1\frac{1}{f(x)}, \; (f(x))^{-1}
one over f of x
The reciprocal: a different thing.
Dom(f),  Ran(f)\text{Dom}(f), \; \text{Ran}(f)
domain and range of f
They swap: Dom(f−1)=Ran(f)\text{Dom}(f^{-1}) = \text{Ran}(f).
Piecewise functions
{2xx<05x≥0\begin{cases} 2x & x < 0 \\ 5 & x \geq 0 \end{cases}
defined by cases
Use the row whose condition holds.
x<1,  x≥1x < 1, \; x \geq 1
split at the boundary
Each cut point belongs to exactly one row.
∙,  ∘\bullet, \; \circ
solid dot, open dot
On a graph: endpoint included, endpoint excluded.
Transformations
af(b(x−h))+ka f(b(x - h)) + k
the four-knob form
Outside letters move it vertically, inside letters horizontally.
f(x−h)f(x - h)
f of x minus h
Shifts right by hh: the sign goes the opposite way.
−f(x)-f(x) vs f(−x)f(-x)
two mirrors
Flip across the xx-axis against flip across the yy-axis.
Same marks, different job
f−1f^{-1} vs 1f\frac{1}{f}The inverse function against the reciprocal.
f(x)f(x)The brackets apply ff; they never mean multiplication.
(2,5)(2, 5)An open interval in a domain; a point in the plane on a graph.
the bar ∣\midSuch that, inside set braces; given, inside P(⋅)P(\cdot); divides, between integers.
Function Notation at a Glance·/functions/basicsLearn Math Class

Evaluating Compositions at a Point

To find (f∘g)(a)(f \circ g)(a) for a specific input aa, work from the inside out:

Step 1: Evaluate the inner function: compute g(a)g(a).

Step 2: Evaluate the outer function at that result: compute f(g(a))f(g(a)).

Example
Let f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x−2g(x) = 3x - 2. Find (f∘g)(4)(f \circ g)(4).
Step 1: g(4)=3(4)−2=10g(4) = 3(4) - 2 = 10
Step 2: f(10)=102+1=101f(10) = 10^2 + 1 = 101
Therefore (f∘g)(4)=101(f \circ g)(4) = 101.

Pitfall: Multiplying instead of composing
Reading ∘\circ as a product gives f(4)⋅g(4)=17⋅10=170f(4) \cdot g(4) = 17 \cdot 10 = 170. Composition feeds the output of gg into ff: (f∘g)(4)=f(g(4))=f(10)=101(f \circ g)(4) = f(g(4)) = f(10) = 101.

Example
Now find (g∘f)(4)(g \circ f)(4) — the composition in the opposite order.
Step 1: f(4)=42+1=17f(4) = 4^2 + 1 = 17
Step 2: g(17)=3(17)−2=49g(17) = 3(17) - 2 = 49
Therefore (g∘f)(4)=49(g \circ f)(4) = 49.

The two results differ: 101≠49101 \neq 49. The order of composition matters — f∘gf \circ g and g∘fg \circ f are generally different functions.
(f o g)(4) = 101 and (g o f)(4) = 49(f ∘ g)(4)410101g3x − 2fx² + 1inner g first, then f(g ∘ f)(4)41749fx² + 1g3x − 2inner f first, then gWork from the inside out — and the order matters: 101 ≠ 49
Inside out, in both orders

The section's two evaluations side by side. For (f ∘ g)(4) the input goes through g first, 3(4) − 2 = 10, and that 10 is what f receives: 10² + 1 = 101. Swap the order and f acts first: 4² + 1 = 17, then g gives 3(17) − 2 = 49. Same two functions, same input, different results.

The middle value never appears in the answer, but it decides it: 10 in one order, 17 in the other.

Finding Composite Functions Algebraically

To find the formula for (f∘g)(x)(f \circ g)(x), substitute the entire expression for g(x)g(x) into ff wherever ff has its input variable.

Let f(x)=x2−4f(x) = x^2 - 4 and g(x)=2x+1g(x) = 2x + 1. Find (f∘g)(x)(f \circ g)(x).

Start with f(x)=x2−4f(x) = x^2 - 4. Replace every xx with g(x)=2x+1g(x) = 2x + 1:

Finding Composite Functions Algebraically
f(g(x))=(2x+1)2−4f(g(x)) = (2x + 1)^2 - 4

Expand and simplify:

Finding Composite Functions Algebraically
(2x+1)2−4=4x2+4x+1−4=4x2+4x−3(2x + 1)^2 - 4 = 4x^2 + 4x + 1 - 4 = 4x^2 + 4x - 3

So (f∘g)(x)=4x2+4x−3(f \circ g)(x) = 4x^2 + 4x - 3.

Now find (g∘f)(x)(g \circ f)(x). Start with g(x)=2x+1g(x) = 2x + 1. Replace xx with f(x)=x2−4f(x) = x^2 - 4:

Finding Composite Functions Algebraically
g(f(x))=2(x2−4)+1=2x2−8+1=2x2−7g(f(x)) = 2(x^2 - 4) + 1 = 2x^2 - 8 + 1 = 2x^2 - 7

So (g∘f)(x)=2x2−7(g \circ f)(x) = 2x^2 - 7.

The two composite functions are different, confirming that composition is not commutative.

Pitfall: Distributing to the first term only
Expanding 2(x2−4)+12(x^2 - 4) + 1 as 2x2−4+12x^2 - 4 + 1 doubles only the first term and gives 2x2−32x^2 - 3. The 22 multiplies all of f(x)f(x): 2x2−8+1=2x2−72x^2 - 8 + 1 = 2x^2 - 7, and indeed g(f(0))=g(−4)=−7g(f(0)) = g(-4) = -7.

In both directions the inner formula goes in as a single unit. The outer function acts on all of it at once — ff squares the whole of 2x+12x + 1 before subtracting 44, and gg doubles the whole of x2−4x^2 - 4 before adding 11. The substitution is therefore written with brackets first and expanded only afterwards, and the expanded result is a new function of xx.

For step-by-step results on your own pair of functions, use the composition calculator on Functions Explorer.

Domain of Composite Functions

The domain of a composite function f∘gf \circ g is not simply the intersection of the two domains. Formally:

Domain of a Composition
Dom(f∘g)={x∈Dom(g):g(x)∈Dom(f)}\text{Dom}(f \circ g) = \{x \in \text{Dom}(g) : g(x) \in \text{Dom}(f)\}
Learn more about this formula: Domain of a Composition →


Two conditions must be satisfied:

1. xx must be in the domain of gg — the inner function must be able to process the input.

2. g(x)g(x) must be in the domain of ff — the output of gg must be a valid input for ff.

Example
Let f(x)=xf(x) = \sqrt{x} with domain [0,∞)[0, \infty) and g(x)=x−3g(x) = x - 3 with domain (−∞,∞)(-\infty, \infty).
For (f∘g)(x)=x−3(f \circ g)(x) = \sqrt{x - 3}:
Condition 1: gg accepts all real xx — no restriction here.
Condition 2: ff requires g(x)≥0g(x) \geq 0, so x−3≥0x - 3 \geq 0, meaning x≥3x \geq 3.
The domain of f∘gf \circ g is [3,∞)[3, \infty).

Example
Let f(x)=1/xf(x) = 1/x with domain x≠0x \neq 0 and g(x)=x2−1g(x) = x^2 - 1.
For (f∘g)(x)=1x2−1(f \circ g)(x) = \dfrac{1}{x^2 - 1}:
Condition 1: gg accepts all real xx.
Condition 2: ff requires g(x)≠0g(x) \neq 0, so x2−1≠0x^2 - 1 \neq 0, meaning x≠±1x \neq \pm 1.
The domain of f∘gf \circ g is {x:x≠−1 and x≠1}\{x : x \neq -1 \text{ and } x \neq 1\}.

Pitfall: Reading the domain from the simplified formula
With f(x)=x2f(x) = x^2 and g(x)=xg(x) = \sqrt{x}, the formula f(g(x))=(x)2=xf(g(x)) = (\sqrt{x})^2 = x seems to accept every xx, but g(−4)g(-4) does not exist. Condition 1 removes all x<0x < 0, so the domain is [0,∞)[0, \infty).

In both examples condition 1 removed nothing, because the inner function was a polynomial that accepts every real number. When the inner function carries a restriction of its own — a square root, a fraction, a logarithm — condition 1 removes inputs before ff is ever reached. Both conditions together decide the domain, and they are applied to the two original functions, one step at a time.

The table below collects these worked examples side by side so the two-condition structure stands out at a glance.
DownloadPNG2×PDF
Layout
Composite (f ∘ g)(x)Condition 1: x in domain of gCondition 2: g(x) in domain of fDomain of f ∘ g
√(x − 3) (f = √x, g = x − 3)all real x — no restrictionneed x − 3 ≥ 0, so x ≥ 3[3, ∞)
1 ⁄ (x² − 1) (f = 1 ⁄ x, g = x² − 1)all real x — no restrictionneed x² − 1 ≠ 0, so x ≠ ±1(−∞, −1) ∪ (−1, 1) ∪ (1, ∞)
Domain of Composite FunctionsLearn Math Class
An input survives a composition only if every step accepts it: gg must take xx, and ff must take g(x)g(x).

Non-Commutativity

RULE
Composition is not commutative: f∘gf \circ g does not generally equal g∘fg \circ f.

The order of the functions determines the result.

Example
Let f(x)=x+5f(x) = x + 5 and g(x)=x2g(x) = x^2.
(f∘g)(x)=f(g(x))=f(x2)=x2+5(f \circ g)(x) = f(g(x)) = f(x^2) = x^2 + 5
(g∘f)(x)=g(f(x))=g(x+5)=(x+5)2=x2+10x+25(g \circ f)(x) = g(f(x)) = g(x + 5) = (x + 5)^2 = x^2 + 10x + 25

These are different functions with different graphs and different values at most inputs. Only at specific points might they coincide by accident.

Non-commutativity reflects the asymmetry of chained processes. Converting Celsius to Fahrenheit means multiplying by 1.81.8 and then adding 3232, which sends 100100 to 212212; adding 3232 first and then multiplying gives (100+32)⋅1.8=237.6(100 + 32) \cdot 1.8 = 237.6, a wrong reading.

Did you know: 2x+12x + 1 and 3x+23x + 2 commute
Both send −1-1 to −1-1, and both orders give 6x+56x + 5. Two linear functions with slopes other than 11 commute exactly when they share a fixed point, the input each one leaves unchanged.

In rare cases, f∘g=g∘ff \circ g = g \circ f. When both functions are shifts x+px + p and x+qx + q, for example, or when one function is the identity. But these are special cases, not the general rule.

Linear functions show how narrow these cases are. For f(x)=ax+bf(x) = ax + b and g(x)=cx+dg(x) = cx + d, the two orders give (f∘g)(x)=acx+ad+b(f \circ g)(x) = acx + ad + b and (g∘f)(x)=acx+bc+d(g \circ f)(x) = acx + bc + d. The slopes always agree, so everything rests on the two constant terms, and for most choices of aa, bb, cc, dd they differ.

The table below sets f∘gf \circ g and g∘fg \circ f side by side for this pair to make the asymmetry concrete.
DownloadPNG2×PDF
Layout
CompositionSubstitutionSimplified formulaValue at x = 1
f ∘ g (g acts first)f(g(x)) = f(x²) = (x²) + 5x² + 56
g ∘ f (f acts first)g(f(x)) = g(x + 5) = (x + 5)²x² + 10x + 2536
Non-CommutativityLearn Math Class

Composing More Than Two Functions

Composition extends to three or more functions. The principle remains the same: evaluate from the innermost function outward.

For three functions ff, gg, and hh:

Composing More Than Two Functions
(f∘g∘h)(x)=f(g(h(x)))(f \circ g \circ h)(x) = f(g(h(x)))

The function hh acts first on xx, producing h(x)h(x). Then gg acts on that result, producing g(h(x))g(h(x)). Finally ff acts, producing f(g(h(x)))f(g(h(x))).

Example
Let f(x)=x2f(x) = x^2, g(x)=x+1g(x) = x + 1, and h(x)=2xh(x) = 2x. Find (f∘g∘h)(3)(f \circ g \circ h)(3).
Step 1: h(3)=6h(3) = 6
Step 2: g(6)=7g(6) = 7
Step 3: f(7)=49f(7) = 49
So (f∘g∘h)(3)=49(f \circ g \circ h)(3) = 49.

The algebraic formula:

Composing More Than Two Functions
h(x)=2xh(x) = 2x
Composing More Than Two Functions
g(h(x))=2x+1g(h(x)) = 2x + 1
Composing More Than Two Functions
f(g(h(x)))=(2x+1)2=4x2+4x+1f(g(h(x))) = (2x + 1)^2 = 4x^2 + 4x + 1

Composition is associative: grouping does not affect the result, though order still matters.

Composition Associativity
(f∘g)∘h=f∘(g∘h)(f \circ g) \circ h = f \circ (g \circ h)
Learn more about this formula: Composition Associativity →

The example of this section, one function at a time. Press Next to carry out one step at a time.
DownloadPNG2×PDF
(f∘g∘h)(3)(f \circ g \circ h)(3) with f(x)=x2f(x) = x^2, g(x)=x+1g(x) = x + 1, h(x)=2xh(x) = 2xStep 1 of 3
Step
(f∘g∘h)(3)(f \circ g \circ h)(3) with f(x)=x2f(x) = x^2, g(x)=x+1g(x) = x + 1, h(x)=2xh(x) = 2x
1
The innermost function acts first
h(3)=6h(3) = 6
2
The next function acts on that result
g(6)=7g(6) = 7
3
The outermost function acts last
f(7)=49f(7) = 49
Three functions, from the inside out·/functions/compositionLearn Math Class
Any chain runs from the innermost function outward: regrouping the brackets is harmless, reordering the functions is not.

Composition with Itself

A function can be composed with itself. The notation f∘ff \circ f means applying ff twice in succession, and (f∘f)(x)=f(f(x))(f \circ f)(x) = f(f(x)).

Let f(x)=2xf(x) = 2x. Then:

Composition with Itself
f(f(x))=f(2x)=2(2x)=4xf(f(x)) = f(2x) = 2(2x) = 4x

Applying ff twice multiplies by 44. Applying three times gives f(f(f(x)))=8xf(f(f(x))) = 8x. Each application doubles the input.

Let f(x)=x2f(x) = x^2. Then:

Composition with Itself
f(f(x))=f(x2)=(x2)2=x4f(f(x)) = f(x^2) = (x^2)^2 = x^4

Squaring twice yields the fourth power.

The notation f2f^2 sometimes denotes f∘ff \circ f, meaning ff composed with itself — not ff squared as a multiplication. Context determines the meaning. When clarity is needed, write f∘ff \circ f or f(f(x))f(f(x)) explicitly.

Did you know: Every step doubles the error
Writing x=sin⁡2θx = \sin^2\theta turns 4x(1−x)4x(1 - x) into sin⁡22θ\sin^2 2\theta, so each step doubles the angle, and with it any error in the starting value. A computer's 16-digit start is used up after about 50 steps; from there its iterates no longer track the true ones.

Iterated composition leads to sequences and dynamical systems. Starting with x0x_0, define x1=f(x0)x_1 = f(x_0), x2=f(x1)=f(f(x0))x_2 = f(x_1) = f(f(x_0)), and so on. The behavior of these iterates reveals long-term dynamics of the function.

A rule as simple as f(x)=4x(1−x)f(x) = 4x(1 - x) shows how far this can go. It sends every number in [0,1][0, 1] back into [0,1][0, 1], so it can be applied again and again: starting from x0=0.3x_0 = 0.3, the iterates are 0.840.84, 0.53760.5376, 0.99434…0.99434\ldots, 0.02249…0.02249\ldots, and they never settle into a repeating pattern.
-10-5510-55f(g(x)) = x⁴g(f(x)) = x⁴
f composed with itself

Applying the same rule twice gives a new curve, f(f(x)), drawn beside f: the second application acts on the outputs of the first. Repeating a function is how iteration and recursion begin. See how the shape changes with each extra application on the function composition explorer.

Composition with itself is the simplest case of iterating a rule.

Decomposing Functions

Decomposition reverses composition: given a function hh, express it as h=f∘gh = f \circ g for simpler functions ff and gg.

Example
Consider h(x)=x2+1h(x) = \sqrt{x^2 + 1}. This function squares the input, adds one, then takes the square root. Identify the inner and outer operations:
Inner function: g(x)=x2+1g(x) = x^2 + 1
Outer function: f(x)=xf(x) = \sqrt{x}
Check: f(g(x))=f(x2+1)=x2+1=h(x)f(g(x)) = f(x^2 + 1) = \sqrt{x^2 + 1} = h(x). ✓

Example
Consider h(x)=(3x−7)5h(x) = (3x - 7)^5. The structure is: form 3x−73x - 7, then raise to the fifth power.
Inner function: g(x)=3x−7g(x) = 3x - 7
Outer function: f(x)=x5f(x) = x^5
Check: f(g(x))=(3x−7)5=h(x)f(g(x)) = (3x - 7)^5 = h(x). ✓

Decomposition is not unique. The function h(x)=(x+1)2h(x) = (x + 1)^2 can be written as f∘gf \circ g with f(x)=x2f(x) = x^2 and g(x)=x+1g(x) = x + 1, or as f∘gf \circ g with f(x)=(x+1)2f(x) = (x + 1)^2 and g(x)=xg(x) = x (trivial decomposition). Choose the decomposition that serves the purpose — simplifying analysis, enabling substitution in calculus, or revealing structure.

The table below collects the worked decompositions covered above with their inner and outer parts and a verification step.
DownloadPNG2×PDF
Layout
Composite h(x)Inner g(x)Outer f(x)Verify f(g(x))
√(x² + 1)x² + 1√x√(x² + 1) ✓
(3x − 7)⁵3x − 7x⁵(3x − 7)⁵ ✓
(x + 1)²x + 1x²(x + 1)² ✓
Decomposing FunctionsLearn Math Class

Composition and Inverse Functions

Composition provides the defining property of inverse functions. If f−1f^{-1} is the inverse of ff, then:

Composition and Inverse Functions
(f∘f−1)(x)=f(f−1(x))=x(f \circ f^{-1})(x) = f(f^{-1}(x)) = x

Composition and Inverse Functions
(f−1∘f)(x)=f−1(f(x))=x(f^{-1} \circ f)(x) = f^{-1}(f(x)) = x

Each composition yields the identity function — the function that returns its input unchanged.

Let f(x)=2x+3f(x) = 2x + 3 and f−1(x)=x−32f^{-1}(x) = \dfrac{x - 3}{2}. Verify:

Composition and Inverse Functions
f(f−1(x))=f(x−32)=2⋅x−32+3=(x−3)+3=x✓f(f^{-1}(x)) = f\left(\frac{x - 3}{2}\right) = 2 \cdot \frac{x - 3}{2} + 3 = (x - 3) + 3 = x \checkmark

Composition and Inverse Functions
f−1(f(x))=f−1(2x+3)=(2x+3)−32=2x2=x✓f^{-1}(f(x)) = f^{-1}(2x + 3) = \frac{(2x + 3) - 3}{2} = \frac{2x}{2} = x \checkmark
The two compositions above, split at each equals sign, with the reason for every step.
DownloadPNG2×PDF
Provef(x)=2x+3f(x) = 2x + 3 and f−1(x)=x−32f^{-1}(x) = \dfrac{x - 3}{2} are inverses
1
f(f−1(x))=f(x−32)f(f^{-1}(x)) = f\left(\frac{x - 3}{2}\right)
substitutePut f−1(x)f^{-1}(x) into ff
2
=2⋅x−32+3= 2 \cdot \frac{x - 3}{2} + 3
apply fff doubles and adds 33
3
=(x−3)+3= (x - 3) + 3
cancelThe 22s cancel
4
=x= x
first checkThe first composition yields the identity
5
f−1(f(x))=f−1(2x+3)f^{-1}(f(x)) = f^{-1}(2x + 3)
substitutePut f(x)f(x) into f−1f^{-1}
6
=(2x+3)−32= \frac{(2x + 3) - 3}{2}
apply inversef−1f^{-1} subtracts 33 and halves
7
=2x2=x= \frac{2x}{2} = x
second checkThe second composition yields the identity as well
f∘f−1=f−1∘f=If \circ f^{-1} = f^{-1} \circ f = I
Each composition yields the identity function, the function that returns its input unchanged.
Checking an inverse pair by compositionLearn Math Class
Each composition undoes the other function's operations in reverse order, which is why both chains collapse to xx.
Pitfall: Taking the inverse as a reciprocal
Using 12x+3\frac{1}{2x + 3} for f−1(x)f^{-1}(x) fails the check: at x=0x = 0 it gives 13\frac{1}{3}, and f(13)=23+3=113f\left(\frac{1}{3}\right) = \frac{2}{3} + 3 = \frac{11}{3}, not 00. The −1-1 marks the inverse function, f−1(x)=x−32f^{-1}(x) = \frac{x - 3}{2}.

This verification method confirms that two functions are inverses. If either composition fails to produce xx, the functions are not inverses.

In practice the check rejects a wrong candidate quickly: a single input that does not come back unchanged is enough. A formula that passes both compositions for every xx in the domain is the inverse, since a function has only one.

RULE
The identity function I(x)=xI(x) = x is the compositional equivalent of the number 11 in multiplication: f∘I=I∘f=ff \circ I = I \circ f = f for any function ff.

Inverses compose to produce this neutral element.
-10-5510-55f(g(x)) = e^(ln x) = xg(f(x)) = ln(eˣ) = x
f(x) = eˆx, g(x) = ln x: f(g(x)) = x

Composed in either order the two curves collapse onto the line y = x: the logarithm undoes the exponential and the exponential undoes the logarithm, which is the defining property of an inverse pair drawn out. The only trace of the pair is the domain restriction x > 0 inherited from ln. Check any candidate pair the same way on the function composition explorer.

A pair that composes to the identity in both orders is inverse; one order alone is not enough.

Graphical Composition

Composing functions graphically requires reading values from two graphs in sequence.

To find (f∘g)(a)(f \circ g)(a) from graphs of ff and gg:

Step 1: On the graph of gg, locate x=ax = a on the horizontal axis. Read the corresponding yy-value; this is g(a)g(a).

Step 2: On the graph of ff, locate x=g(a)x = g(a) on the horizontal axis. Read the corresponding yy-value; this is f(g(a))=(f∘g)(a)f(g(a)) = (f \circ g)(a).

The output of gg becomes the input for ff. Each composition evaluation requires two graph readings.

Building the entire graph of f∘gf \circ g from graphs of ff and gg is labor-intensive. For each xx-value, perform the two-step reading. The result is a new curve whose shape depends on both component functions.

Graphical composition is most useful for specific point evaluations or for understanding conceptually how the functions interact. For detailed graphing, algebraic methods are more efficient.
(f o g)(0) read from two graphsstep 1 · graph of g(x) = 3x − 2step 2 · graph of f(x) = x² + 1g(0) = −2input 0input −2f(−2) = 5output of g becomes the input of f(f ∘ g)(0) = f(g(0)) = f(−2) = 5
Two graph readings, one composition

To find (f ∘ g)(0) from graphs: on the graph of g, go from x = 0 to the curve and read g(0) = −2. That output is the next input — find −2 on the x-axis of f's graph, go up to the curve and read f(−2) = 5. Every point of f ∘ g takes this pair of readings.

If g(a) falls outside the part of f's graph you can see — or outside f's domain — the composition cannot be read there.

Applications of Composition

Composition models processes that occur in stages, where the output of one stage feeds into the next.

Unit conversions often chain. To convert Celsius to Kelvin, add 273.15273.15. To convert Kelvin to Rankine, multiply by 1.81.8. The composition converts Celsius directly to Rankine:

Applications of Composition
R(C)=1.8(C+273.15)=1.8C+491.67R(C) = 1.8(C + 273.15) = 1.8C + 491.67

Pricing calculations chain. A 20%20\% discount applies first: g(p)=0.8pg(p) = 0.8p. Then 8%8\% tax applies: f(x)=1.08xf(x) = 1.08x. The final price:

Applications of Composition
f(g(p))=1.08(0.8p)=0.864pf(g(p)) = 1.08(0.8p) = 0.864p

Here the order does not matter, since both steps are scalings: 0.8(1.08p)=1.08(0.8p)0.8(1.08p) = 1.08(0.8p). It would matter with a fixed-amount discount such as p−10p - 10.

Growth models chain. If population depends on resources, and resources depend on time, then population depends on time through composition.

In each case, composition captures the sequential nature of the process. The intermediate quantity — Kelvin, discounted price, resource level — may never be explicitly calculated, but it mediates the relationship between initial input and final output.

Formula Summary

This summary gathers the formulas of composition in the order the page builds them. Each row names a formula with a line on where it comes from and a link to its section, states it, and says what it gives.

It opens with the definition, where one function feeds its output to the next, and the rule for the domain of a composition, which keeps only the inputs both steps accept. A chain of three functions and the grouping rule follow, then a function composed with itself. The last two rows compose a function with its inverse in both orders, and both return the input.
DownloadPNG2×PDF
FormulaStatementWhat it gives
CompositionThe output of gg becomes the input of ff, as what is function composition explains.(f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x))one function that applies gg first and ff second
Domain of a compositionNot the plain intersection of the two domains; domain of composite functions checks both conditions.Dom(f∘g)={x∈Dom(g):g(x)∈Dom(f)}\text{Dom}(f \circ g) = \{x \in \text{Dom}(g) : g(x) \in \text{Dom}(f)\}the inputs that both steps accept
Three functionsHere hh acts first, then gg, then ff, as composing more than two functions shows.(f∘g∘h)(x)=f(g(h(x)))(f \circ g \circ h)(x) = f(g(h(x)))a chain worked from the innermost function outward
AssociativityGrouping does not change the result, though the order still does, from composing more than two functions.(f∘g)∘h=f∘(g∘h)(f \circ g) \circ h = f \circ (g \circ h)the same function under either grouping
Composition with itselfSome books write it f2f^2, which here does not mean ff squared; see composition with itself.(f∘f)(x)=f(f(x))(f \circ f)(x) = f(f(x))the result of applying ff twice
Function after its inverseComposing a function with its inverse gives the identity function, from composition and inverse functions.(f∘f−1)(x)=f(f−1(x))=x(f \circ f^{-1})(x) = f(f^{-1}(x)) = xthe input back, unchanged
Inverse after the functionBoth orders must return xx before two functions count as inverses, as composition and inverse functions checks.(f−1∘f)(x)=f−1(f(x))=x(f^{-1} \circ f)(x) = f^{-1}(f(x)) = xthe input back in the other order too
Composition formulas·All function formulasLearn Math Class
Every formula here is read from the inside out: the function written closest to the input acts first. That habit settles the order in a chain, finds the domain of a composition, and turns the two inverse rows into a quick test of whether two functions undo each other.

Common Pitfalls

Six mistakes come up again and again when functions are composed. Four are marked where they happen in the sections above. Composing in the wrong order is the one that Evaluating Compositions at a Point and Non-Commutativity already show, and squaring instead of composing is the one that Composition with Itself points out. Here each is worked through in full, with the wrong and the right working side by side.
DownloadPNG2×PDF
1Multiplying instead of composing
The value (f∘g)(a)(f \circ g)(a) is computed as f(a)⋅g(a)f(a) \cdot g(a): both functions are evaluated at the same input and their outputs are multiplied.
Start
With f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x−2g(x) = 3x - 2, f(4)=17f(4) = 17 and g(4)=10g(4) = 10,
Wrong turn
Error here
So (f∘g)(4)(f \circ g)(4) is given as 17⋅10=17017 \cdot 10 = 170.
Right path
gg acts first and its output becomes the input of ff. g(4)=3(4)−2=10g(4) = 3(4) - 2 = 10, then f(10)=102+1=101f(10) = 10^2 + 1 = 101, so (f∘g)(4)=101(f \circ g)(4) = 101.
Why it happensThe ring ∘\circ looks like the multiplication dot, and the product (fg)(x)(fg)(x) of function arithmetic is built from the same two letters.
How to checkIn a composition only the inner function sees the original input. If f(4)f(4) appears in the working for (f∘g)(4)(f \circ g)(4), the chain was never formed.
2Composing in the wrong order
The symbol f∘gf \circ g is read from left to right, so ff is applied first and gg second. That computes g∘fg \circ f instead.
Wrong turn
Error here
For (f∘g)(4)(f \circ g)(4) with the same ff and gg, first f(4)=17f(4) = 17, then g(17)=3(17)−2=49g(17) = 3(17) - 2 = 49.
Right path
First g(4)=10g(4) = 10, then f(10)=101f(10) = 101. The value 4949 is (g∘f)(4)(g \circ f)(4), a different composition.
Why it happensThe written order is ff then gg, but the order of action is gg then ff; the notation reads from right to left.
How to checkRewrite the symbol in nested form, f(g(4))f(g(4)). The innermost brackets are evaluated first, so gg goes first.
3Distributing to the first term only
When the inner formula is substituted into the outer function, the outer function's operation is applied to only part of it, usually because the substituted expression is written without brackets.
Start
For f(x)=x2−4f(x) = x^2 - 4 and g(x)=2x+1g(x) = 2x + 1,
Wrong turn
Error here
g(f(x))=2x2−4+1=2x2−3g(f(x)) = 2x^2 - 4 + 1 = 2x^2 - 3.
Right path
g(f(x))=2(x2−4)+1=2x2−8+1=2x2−7g(f(x)) = 2(x^2 - 4) + 1 = 2x^2 - 8 + 1 = 2x^2 - 7.
Why it happensThe substitution is done in the head, the brackets are never written, and the 22 lands only on the first term it meets.
How to checkEvaluate at one point step by step. f(0)=−4f(0) = -4 and g(−4)=−8+1=−7g(-4) = -8 + 1 = -7; the right formula gives −7-7 at x=0x = 0, the wrong one gives −3-3.
4Reading the domain from the simplified formula
The domain of f∘gf \circ g is read from the final simplified formula, so the restriction of the inner function drops out of sight and condition 1 is never applied.
Start
For f(x)=x2f(x) = x^2 and g(x)=xg(x) = \sqrt{x}, f(g(x))=(x)2=xf(g(x)) = (\sqrt{x})^2 = x,
Wrong turn
Error here
So the domain is given as all real numbers.
Right path
Condition 1 requires xx in the domain of gg, so x≥0x \geq 0. Condition 2 adds nothing, since ff accepts every real number. The domain is [0,∞)[0, \infty): at x=−4x = -4 the first step, g(−4)=−4g(-4) = \sqrt{-4}, is not a real number, so the input never reaches ff.
Why it happensSimplifying removes the square root, and with it the visible sign that negative inputs are not allowed.
How to checkApply both conditions to the original functions before simplifying, and push one doubtful input through the inner function first.
5Squaring instead of composing with itself
The composition f∘ff \circ f, written f2f^2 in some texts, is computed as f(x)⋅f(x)f(x) \cdot f(x), the square of the output, instead of applying ff twice.
Start
For f(x)=2xf(x) = 2x,
Wrong turn
Error here
(f∘f)(x)=(2x)2=4x2(f \circ f)(x) = (2x)^2 = 4x^2.
Right path
f(f(x))=f(2x)=2(2x)=4xf(f(x)) = f(2x) = 2(2x) = 4x. At x=3x = 3, f(3)=6f(3) = 6 and f(6)=12f(6) = 12, which matches 4x=124x = 12, while 4x24x^2 gives 3636.
Why it happensf2f^2 is used for both meanings, and squaring is the meaning met first, with numbers and with sin⁡2θ\sin^2\theta.
How to checkCompute f(f(a))f(f(a)) for one number aa step by step and compare it with the formula.
6Taking the inverse as a reciprocal
The symbol f−1f^{-1} is read as 1f\frac{1}{f}, so the reciprocal of the output is taken as the inverse function and put into the composition check.
Start
For f(x)=2x+3f(x) = 2x + 3,
Wrong turn
Error here
The candidate is 12x+3\frac{1}{2x + 3}. Then f(12x+3)=22x+3+3f\left(\frac{1}{2x + 3}\right) = \frac{2}{2x + 3} + 3, which is not xx; at x=0x = 0 it equals 23+3=113\frac{2}{3} + 3 = \frac{11}{3}.
Right path
The inverse undoes ff step by step, f−1(x)=x−32f^{-1}(x) = \frac{x - 3}{2}, and f(f−1(x))=(x−3)+3=xf(f^{-1}(x)) = (x - 3) + 3 = x for every xx.
Why it happensFor numbers a−1=1aa^{-1} = \frac{1}{a}, and the same exponent on a function is read the same way.
How to checkRun the composition at one convenient input. An inverse returns that input unchanged; 113≠0\frac{11}{3} \neq 0 rejects the reciprocal at once.
Common pitfalls with composition·/functions/compositionLearn Math Class
Each slip breaks the chain of a composition. In (f∘g)(x)(f \circ g)(x) the output of gg becomes the input of ff: nothing is multiplied, gg goes first, the whole of f(x)f(x) replaces xx in gg, the domain is read from the original functions, f∘ff \circ f applies ff twice rather than squaring it, and an inverse undoes ff rather than taking its reciprocal. Pushing one number through the chain step by step catches each slip.

Composition Tasks at a Glance

Composition shows up in a wide range of tasks — evaluating at a point, finding a formula, determining a domain, decomposing a complex expression, verifying inverses. The procedures share the same inside-out evaluation logic but the deliverable differs from task to task. The table below collects every task covered above with what's given, the procedure to follow, and an example of the result — useful as a checklist when a problem invokes composition and the right approach isn't immediately obvious.
DownloadPNG2×PDF
Layout
TaskGivenProcedureExample result
Evaluate at a pointf, g, input acompute g(a), then apply f to the result(f ∘ g)(4) = 101
Find composite formulaformulas for f and gsubstitute g(x) into f wherever f's input appears; simplify4x² + 4x − 3
Find domainf, g and their domainsrequire x in dom(g) AND g(x) in dom(f); intersect[3, ∞)
Test commutativityf and gcompute both f ∘ g and g ∘ f; compare formulasx² + 5 ≠ x² + 10x + 25
Chain three or moref, g, h, …evaluate innermost first, then work outward(f ∘ g ∘ h)(3) = 49
Compose with itselfa single fsubstitute f(x) into f wherever its input appearsf(x) = 2x ⇒ f(f(x)) = 4x
Decomposea single h(x)identify the outer operation; what it acts on is the inner√(x² + 1) = √x ∘ (x² + 1)
Verify inversesf and candidate f⁻¹check that both f(f⁻¹(x)) and f⁻¹(f(x)) reduce to xboth compositions = x ⇒ confirmed
Composition Tasks at a GlanceLearn Math Class

Skills You Should Learn

Each skill opens its step-by-step method page. Skills marked "On this page" are taught above.
Taught on this page
More functions methods
Derivative techniques

Function Composition FAQ

Which function is applied first in f(g(x))?

+
The inner one. Work outward from the input: g acts on x first, and f then acts on whatever g produced. The notation reads right to left, which feels backwards compared with the written order and is the single most common source of composition mistakes.Read more →

Does f2(x)f^2(x) mean f(f(x))f(f(x)) or f(x)f(x) squared?

+
It depends on the field, so read the context. In iteration and dynamics f2f^2 means f∘ff \circ f: for f(x)=2xf(x) = 2x that is f(f(x))=4xf(f(x)) = 4x. In trigonometry sin⁡2θ\sin^2\theta means (sin⁡θ)2(\sin\theta)^2, the square of the output, and read that way the same ff would give 4x24x^2. Careful texts avoid the clash by writing f∘ff \circ f or f(f(x))f(f(x)) in full.Read more →

When do two linear functions commute?

+
When they share a fixed point, provided neither slope is 11. For f(x)=ax+bf(x) = ax + b and g(x)=cx+dg(x) = cx + d both orders have slope acac, so only the constants ad+bad + b and bc+dbc + d can differ. The functions 2x+12x + 1 and 3x+23x + 2 both send −1-1 to −1-1, and both orders give 6x+56x + 5. Two shifts x+px + p and x+qx + q always commute, though they have no fixed point.Read more →

Does it matter whether a discount or the tax is applied first?

+
Not for a percentage discount, but it does for a fixed amount off. A 20%20\% discount and an 8%8\% tax are both scalings, so either order gives 0.864p0.864p. With 1010 off instead, discounting first gives 1.08(p−10)=1.08p−10.81.08(p - 10) = 1.08p - 10.8, while taxing first gives 1.08p−101.08p - 10. The price is 0.800.80 lower when the discount comes first, because the tax is then charged on the smaller amount.Read more →

Why does iterating 4x(1−x)4x(1 - x) on a computer go wrong?

+
Because every step doubles the error. Writing x=sin⁡2θx = \sin^2\theta turns 4x(1−x)4x(1 - x) into sin⁡22θ\sin^2 2\theta, so each application doubles the angle, and any error in the starting value doubles with it. A computer keeps about 16 significant digits and 2502^{50} is roughly 101510^{15}, so after about 50 steps the computed iterates no longer track the true ones, even though each single step is accurate.Read more →