Composition of functions

Take two machines that transform numbers. The first machine, ff, eats an input and spits out f(x)f(x). Feed that output straight into a second machine, gg, and out comes g(f(x))g(f(x)). Chaining functions this way — output of one becomes input of the next — is composition of functions, written g∘fg \circ f. It sits in the NCERT Relations and Functions chapter right after one-one and onto functions. A quick scope note before you invest time here: under the current CBSE Class 12 syllabus (2025-26), composition of functions is not examinable — it was rationalised down to informal, non-formative treatment in Class 11. It still appears in the printed textbook and in older question banks, so it's covered here for completeness and because it quietly underpins ideas like inverse functions. Treat what follows as background reading rather than exam-critical prep; your marks in this chapter come from types of relations and one-one/onto functions.

The core insight

The composite (g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x)) chains two functions so the output of the inner one feeds the outer one, and — because order changes which function acts first — g∘fg \circ f and f∘gf \circ g are generally different functions with possibly different domains.

The core idea

Given two functions f:A→Bf : A \to B and g:B→Cg : B \to C, the codomain of ff must match the domain of gg for the composite to be defined. The composite function g∘f:A→Cg \circ f : A \to C is defined by

(g∘f)(x)=g(f(x))for all x∈A,(g \circ f)(x) = g(f(x)) \quad \text{for all } x \in A,

where: ff is the inner function (applied first), gg is the outer function (applied second), AA is the domain of ff, BB is the shared codomain-of-ff/domain-of-gg, and CC is the codomain of gg. Read g∘fg \circ f from right to left: "first ff, then gg." A few facts worth carrying forward without formal proof:

  • Not commutative. g∘fg \circ f and f∘gf \circ g are generally different functions — sometimes one of the two isn't even defined.
  • Associative. (h∘g)∘f=h∘(g∘f)(h \circ g) \circ f = h \circ (g \circ f) whenever every composite involved is defined, so a chain of three functions can be bracketed either way.
  • Preserves one-one and onto. If ff and gg are both one-one, g∘fg \circ f is one-one; if both are onto, g∘fg \circ f is onto.

The picture below shows the chain of sets and how a single input xx threads through both machines.

Figure
Three sets A B and C linked by function f from A to B then function g from B to C with a sample input x mapped through f of x to g of f of x
Composition g∘f chains f then g A B C x f of x g of f of x f g g∘f goes straight from A to C

The domain of a composite function

Knowing the composite formula is half the story — the harder, exam-style subtlety is figuring out where it is actually valid. A wrong guess here is the single most common slip in this topic, so it deserves a careful derivation: we work out the general rule that pins down the domain of any composite function f∘gf \circ g, showing why simply intersecting the domains of ff and gg separately is not enough, and why you must instead trace which outputs of the inner function are allowed to land inside the outer function's domain.

Step 1. Start from the definition (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)). For the right-hand side to even be computable, two things must independently hold — g(x)g(x) must exist, and then ff must accept the value g(x)g(x) produces.

Step 2. The first requirement is simply that xx lies in the domain of gg, since otherwise g(x)g(x) is not defined and there is nothing to feed forward.

Step 3. The second requirement is that the output g(x)g(x), not xx itself, must lie in the domain of ff. This is the step people skip: they check whether xx is a valid input to ff, but ff never sees xx directly — it only ever sees g(x)g(x).

Step 4. Combining both conditions gives the domain of the composite as {x∈Dom(g):g(x)∈Dom(f)}\{x \in \text{Dom}(g) : g(x) \in \text{Dom}(f)\}. This set can be smaller than the domain of gg alone (extra values get filtered out by the second condition) but it can never contain any xx outside the domain of gg (the first condition is a hard floor). Applying this to f(x)=xf(x) = \sqrt{x} with domain [0,∞)[0,\infty) and g(x)=x−4g(x) = x - 4 with domain R\mathbb{R}: every real xx passes Step 2, but Step 3 demands x−4≥0x - 4 \ge 0, i.e. x≥4x \ge 4, so the composite domain shrinks to [4,∞)[4, \infty).

Worked example

Let f(x)=xf(x) = \sqrt{x} with domain [0,∞)[0,\infty), and g(x)=x−4g(x) = x - 4 with domain R\mathbb{R} — the same pair used above. Earlier we found (f∘g)(x)=x−4(f\circ g)(x) = \sqrt{x-4} with domain [4,∞)[4,\infty). Now find (g∘f)(x)(g \circ f)(x) and its domain, and compare.

Step 1. Apply the definition with ff as the inner function: (g∘f)(x)=g(f(x))=g(x)(g \circ f)(x) = g(f(x)) = g(\sqrt{x}).

Step 2. Substitute x\sqrt{x} into g(t)=t−4g(t) = t - 4: (g∘f)(x)=x−4(g \circ f)(x) = \sqrt{x} - 4.

Step 3. Find the domain using the rule from the derivation. First, xx must lie in the domain of ff, so x≥0x \ge 0. Second, the output f(x)=xf(x) = \sqrt{x} must lie in the domain of gg, which is all of R\mathbb{R} — so this second condition places no extra restriction.

Step 4. The domain of g∘fg \circ f is therefore just [0,∞)[0, \infty), unlike the domain of f∘gf \circ g, which was the smaller set [4,∞)[4, \infty). So (g∘f)(x)=x−4(g \circ f)(x) = \sqrt{x} - 4 with domain [0,∞)[0, \infty), while (f∘g)(x)=x−4(f \circ g)(x) = \sqrt{x - 4} with domain [4,∞)[4, \infty) — same two functions, opposite order, genuinely different formulas and different domains. This is the clearest possible illustration that composition is not commutative in either its rule or its domain.

Common traps

  • Writing g∘fg \circ f but computing f(g(x))f(g(x)) instead of g(f(x))g(f(x)) — the function on the right of ∘\circ always acts first.
  • Assuming f∘g=g∘ff \circ g = g \circ f; as the worked example shows, both the formula and the domain can differ.
  • Checking whether xx is a valid input to the outer function instead of checking whether the inner function's output is a valid input to it — this is the exact mistake Step 3 of the derivation guards against.
  • Forgetting that the composite's domain can never exceed the inner function's domain, even if the algebra after simplification looks defined everywhere.

Ask the tutor: Want to see how composition sets up the definition of an inverse function, or try a few more domain-of-composite problems? Ask the AI tutor to work through them with you.

Why does the codomain of f have to match the domain of g for g∘f to make sense

Because (g∘f)(x)=g(f(x))(g\circ f)(x) = g(f(x)) literally feeds the output of ff into gg. If ff can produce a value that gg has no rule for, g(f(x))g(f(x)) is meaningless for that xx. In practice, for real-valued functions this usually just means checking that the outputs ff actually produces land inside wherever gg is defined — exactly the domain-of-composite rule from the derivation above.

Is composition of functions the same as multiplying two functions together

No — multiplying gives (fg)(x)=f(x)⋅g(x)(fg)(x) = f(x)\cdot g(x), a single new value formed by multiplying two numbers, while composing gives (g∘f)(x)=g(f(x))(g\circ f)(x) = g(f(x)), where one function's output becomes the other's input. They can even have different domains: multiplication only needs both f(x)f(x) and g(x)g(x) to exist, while composition additionally needs f(x)f(x) to be an acceptable input for gg.

If this topic is not examinable in CBSE Class 12, why bother learning it well

Two reasons. First, some schools, coaching materials and older question banks still use it, so recognising it avoids confusion. Second, it is the quiet backbone of ideas you'll meet if you continue with mathematics — inverse functions are defined using composition (f−1∘f=identityf^{-1}\circ f = \text{identity}), and later topics in calculus and beyond routinely chain functions together, so a working intuition here pays off even without direct exam marks.

Before this

Where this leads