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 f and g, the composition f∘g applies g first, then feeds the result into f. The output of g becomes the input of f, creating a single combined process from two separate ones.
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 f with g, written f∘g, is the function that sends x to f(g(x)): apply g first, then apply f to its output.
If g takes an input x and produces g(x), and f then takes g(x) and produces f(g(x)), the composition f∘g captures this two-step process as a single function:
Read it inside out: g 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.
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 g acts first, transforming the original input. The function f 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). Composing functions chains their operations: (f∘g)(x)=f(g(x)). The input to f in composition is not x but 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 g to f; the last column is (f∘g)(x).
x
g(x) = 3x − 2
f(g(x)) = g(x)² + 1
0
−2
5
1
1
2
2
4
17
4
10
101
The definition promised a single function, and it delivers one: the two steps collapse into one rule.
Substituting g(x) into f gives (f∘g)(x)=(3x−2)2+1=9x2−12x+5, a formula with no middle step at all. It gives the same outputs as the two-step chain.
x
two steps: f(g(x))
one rule: 9x² − 12x + 5
0
5
0 − 0 + 5 = 5
1
2
9 − 12 + 5 = 2
2
17
36 − 24 + 5 = 17
4
101
144 − 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∘f sends 4 to g(17)=49, not 101 — see non-commutativity. And x belongs to f∘g only if g(x) is something f 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), the letter conventions and substitution come from function notation; the domain restrictions a composition inherits are written with domain notation.
f∘g
f composed with g; f after g
The hollow ring is the composition operator: f∘g is one new function, built by feeding g's output to f. Read right-to-left — g sits second but acts first; "f after g" is the reading that encodes the order.
CasesIterates hide the ring: in dynamics f2 means f∘f — while the squared shorthandsin2θ squares the value; the superscript's meaning flips by field, so careful texts write f∘f out.
Do not confuseThe multiplication dot. f∘g and f⋅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 of g of x
The self-explaining spelling: nesting shows the order — evaluate inside out, g(x) first, then f of the result. (f∘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) runs g(4) then f 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)). Same letters, opposite machine — f∘g and g∘f are generally different functions, as the 101=49 example below demonstrates; the notation is order-critical.
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).
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) read as f(x)⋅g(x) versus f(g(x)) — two different numbers from one string; the ring or the nest costs one symbol and removes the ambiguity entirely.
Now find (g∘f)(4) — the composition in the opposite order.
Step 1: f(4)=42+1=17
Step 2: g(17)=3(17)−2=49
Therefore (g∘f)(4)=49.
The two results differ: 101=49. The order of composition matters — f∘g and g∘f are generally different functions.
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), substitute the entire expression for g(x) into f wherever f has its input variable.
Let f(x)=x2−4 and g(x)=2x+1. Find (f∘g)(x).
Start with f(x)=x2−4. Replace every x with g(x)=2x+1:
Finding Composite Functions Algebraically
f(g(x))=(2x+1)2−4
Expand and simplify:
Finding Composite Functions Algebraically
(2x+1)2−4=4x2+4x+1−4=4x2+4x−3
So (f∘g)(x)=4x2+4x−3.
Now find (g∘f)(x). Start with g(x)=2x+1. Replace x with f(x)=x2−4:
Finding Composite Functions Algebraically
g(f(x))=2(x2−4)+1=2x2−8+1=2x2−7
So (g∘f)(x)=2x2−7.
The two composite functions are different, confirming that composition is not commutative.
Pitfall: Distributing to the first term only
Expanding 2(x2−4)+1 as 2x2−4+1 doubles only the first term and gives 2x2−3. The 2 multiplies all of f(x): 2x2−8+1=2x2−7, and indeed g(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 — f squares the whole of 2x+1 before subtracting 4, and g doubles the whole of x2−4 before adding 1. The substitution is therefore written with brackets first and expanded only afterwards, and the expanded result is a new function of x.
For step-by-step results on your own pair of functions, use the composition calculator on Functions Explorer.
1. x must be in the domain of g — the inner function must be able to process the input.
2. g(x) must be in the domain of f — the output of g must be a valid input for f.
Example
Let f(x)=x with domain [0,∞) and g(x)=x−3 with domain (−∞,∞).
For (f∘g)(x)=x−3:
Condition 1: g accepts all real x — no restriction here.
Condition 2: f requires g(x)≥0, so x−3≥0, meaning x≥3.
The domain of f∘g is [3,∞).
Example
Let f(x)=1/x with domain x=0 and g(x)=x2−1.
For (f∘g)(x)=x2−11:
Condition 1: g accepts all real x.
Condition 2: f requires g(x)=0, so x2−1=0, meaning x=±1.
The domain of f∘g is {x:x=−1 and x=1}.
Pitfall: Reading the domain from the simplified formula
With f(x)=x2 and g(x)=x, the formula f(g(x))=(x)2=x seems to accept every x, but g(−4) does not exist. Condition 1 removes all x<0, so the domain is [0,∞).
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 f 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.
An input survives a composition only if every step accepts it: g must take x, and f must take g(x).
Non-Commutativity
RULE
Composition is not commutative: f∘g does not generally equal g∘f.
The order of the functions determines the result.
Example
Let f(x)=x+5 and g(x)=x2.
(f∘g)(x)=f(g(x))=f(x2)=x2+5
(g∘f)(x)=g(f(x))=g(x+5)=(x+5)2=x2+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.8 and then adding 32, which sends 100 to 212; adding 32 first and then multiplying gives (100+32)⋅1.8=237.6, a wrong reading.
Did you know: 2x+1 and 3x+2 commute
Both send −1 to −1, and both orders give 6x+5. Two linear functions with slopes other than 1 commute exactly when they share a fixed point, the input each one leaves unchanged.
In rare cases, f∘g=g∘f. When both functions are shifts x+p and x+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+b and g(x)=cx+d, the two orders give (f∘g)(x)=acx+ad+b and (g∘f)(x)=acx+bc+d. The slopes always agree, so everything rests on the two constant terms, and for most choices of a, b, c, d they differ.
The table below sets f∘g and g∘f side by side for this pair to make the asymmetry concrete.
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∘f means applying f twice in succession, and (f∘f)(x)=f(f(x)).
Let f(x)=2x. Then:
Composition with Itself
f(f(x))=f(2x)=2(2x)=4x
Applying f twice multiplies by 4. Applying three times gives f(f(f(x)))=8x. Each application doubles the input.
Let f(x)=x2. Then:
Composition with Itself
f(f(x))=f(x2)=(x2)2=x4
Squaring twice yields the fourth power.
The notation f2 sometimes denotes f∘f, meaning f composed with itself — not f squared as a multiplication. Context determines the meaning. When clarity is needed, write f∘f or f(f(x)) explicitly.
Did you know: Every step doubles the error
Writing x=sin2θ turns 4x(1−x) into sin22θ, 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 x0, define x1=f(x0), x2=f(x1)=f(f(x0)), 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) shows how far this can go. It sends every number in [0,1] back into [0,1], so it can be applied again and again: starting from x0=0.3, the iterates are 0.84, 0.5376, 0.99434…, 0.02249…, and they never settle into a repeating pattern.
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 h, express it as h=f∘g for simpler functions f and g.
Example
Consider h(x)=x2+1. This function squares the input, adds one, then takes the square root. Identify the inner and outer operations:
Inner function: g(x)=x2+1
Outer function: f(x)=x
Check: f(g(x))=f(x2+1)=x2+1=h(x). ✓
Example
Consider h(x)=(3x−7)5. The structure is: form 3x−7, then raise to the fifth power.
Inner function: g(x)=3x−7
Outer function: f(x)=x5
Check: f(g(x))=(3x−7)5=h(x). ✓
Decomposition is not unique. The function h(x)=(x+1)2 can be written as f∘g with f(x)=x2 and g(x)=x+1, or as f∘g with f(x)=(x+1)2 and g(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.
This verification method confirms that two functions are inverses. If either composition fails to produce x, 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 x in the domain is the inverse, since a function has only one.
RULE
The identity function I(x)=x is the compositional equivalent of the number 1 in multiplication: f∘I=I∘f=f for any function f.
Inverses compose to produce this neutral element.
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) from graphs of f and g:
Step 1: On the graph of g, locate x=a on the horizontal axis. Read the corresponding y-value; this is g(a).
Step 2: On the graph of f, locate x=g(a) on the horizontal axis. Read the corresponding y-value; this is f(g(a))=(f∘g)(a).
The output of g becomes the input for f. Each composition evaluation requires two graph readings.
Building the entire graph of f∘g from graphs of f and g is labor-intensive. For each x-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.
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.15. To convert Kelvin to Rankine, multiply by 1.8. The composition converts Celsius directly to Rankine:
Applications of Composition
R(C)=1.8(C+273.15)=1.8C+491.67
Pricing calculations chain. A 20% discount applies first: g(p)=0.8p. Then 8% tax applies: f(x)=1.08x. The final price:
Applications of Composition
f(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). It would matter with a fixed-amount discount such as p−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.
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.
The value (f∘g)(a) is computed as f(a)⋅g(a): both functions are evaluated at the same input and their outputs are multiplied.
Start
With f(x)=x2+1 and g(x)=3x−2, f(4)=17 and g(4)=10,
Wrong turn
Error here
So (f∘g)(4) is given as 17⋅10=170.
Right path
g acts first and its output becomes the input of f. g(4)=3(4)−2=10, then f(10)=102+1=101, so (f∘g)(4)=101.
Why it happensThe ring ∘ looks like the multiplication dot, and the product (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) appears in the working for (f∘g)(4), the chain was never formed.
2Composing in the wrong order
The symbol f∘g is read from left to right, so f is applied first and g second. That computes g∘f instead.
Wrong turn
Error here
For (f∘g)(4) with the same f and g, first f(4)=17, then g(17)=3(17)−2=49.
Right path
First g(4)=10, then f(10)=101. The value 49 is (g∘f)(4), a different composition.
Why it happensThe written order is f then g, but the order of action is g then f; the notation reads from right to left.
How to checkRewrite the symbol in nested form, f(g(4)). The innermost brackets are evaluated first, so g 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−4 and g(x)=2x+1,
Wrong turn
Error here
g(f(x))=2x2−4+1=2x2−3.
Right path
g(f(x))=2(x2−4)+1=2x2−8+1=2x2−7.
Why it happensThe substitution is done in the head, the brackets are never written, and the 2 lands only on the first term it meets.
How to checkEvaluate at one point step by step. f(0)=−4 and g(−4)=−8+1=−7; the right formula gives −7 at x=0, the wrong one gives −3.
4Reading the domain from the simplified formula
The domain of f∘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)=x2 and g(x)=x, f(g(x))=(x)2=x,
Wrong turn
Error here
So the domain is given as all real numbers.
Right path
Condition 1 requires x in the domain of g, so x≥0. Condition 2 adds nothing, since f accepts every real number. The domain is [0,∞): at x=−4 the first step, g(−4)=−4, is not a real number, so the input never reaches f.
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∘f, written f2 in some texts, is computed as f(x)⋅f(x), the square of the output, instead of applying f twice.
Start
For f(x)=2x,
Wrong turn
Error here
(f∘f)(x)=(2x)2=4x2.
Right path
f(f(x))=f(2x)=2(2x)=4x. At x=3, f(3)=6 and f(6)=12, which matches 4x=12, while 4x2 gives 36.
Why it happensf2 is used for both meanings, and squaring is the meaning met first, with numbers and with sin2θ.
How to checkCompute f(f(a)) for one number a step by step and compare it with the formula.
6Taking the inverse as a reciprocal
The symbol f−1 is read as f1, so the reciprocal of the output is taken as the inverse function and put into the composition check.
Start
For f(x)=2x+3,
Wrong turn
Error here
The candidate is 2x+31. Then f(2x+31)=2x+32+3, which is not x; at x=0 it equals 32+3=311.
Right path
The inverse undoes f step by step, f−1(x)=2x−3, and f(f−1(x))=(x−3)+3=x for every x.
Why it happensFor numbers a−1=a1, 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; 311=0 rejects the reciprocal at once.
Each slip breaks the chain of a composition. In (f∘g)(x) the output of g becomes the input of f: nothing is multiplied, g goes first, the whole of f(x) replaces x in g, the domain is read from the original functions, f∘f applies f twice rather than squaring it, and an inverse undoes f 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.
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) mean f(f(x)) or f(x) squared?
+
It depends on the field, so read the context. In iteration and dynamics f2 means f∘f: for f(x)=2x that is f(f(x))=4x. In trigonometry sin2θ means (sinθ)2, the square of the output, and read that way the same f would give 4x2. Careful texts avoid the clash by writing f∘f or f(f(x)) in full.Read more →
When do two linear functions commute?
+
When they share a fixed point, provided neither slope is 1. For f(x)=ax+b and g(x)=cx+d both orders have slope ac, so only the constants ad+b and bc+d can differ. The functions 2x+1 and 3x+2 both send −1 to −1, and both orders give 6x+5. Two shifts x+p and x+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% discount and an 8% tax are both scalings, so either order gives 0.864p. With 10 off instead, discounting first gives 1.08(p−10)=1.08p−10.8, while taxing first gives 1.08p−10. The price is 0.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) on a computer go wrong?
+
Because every step doubles the error. Writing x=sin2θ turns 4x(1−x) into sin22θ, so each application doubles the angle, and any error in the starting value doubles with it. A computer keeps about 16 significant digits and 250 is roughly 1015, so after about 50 steps the computed iterates no longer track the true ones, even though each single step is accurate.Read more →