Composition of Functions (gof and fog)

Reading the notation

gofgof means "first apply ff, then apply gg to the result", read right to left: (g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x)). Likewise fog(x)=f(g(x))fog(x) = f(g(x)). There's no reason these have to match.

A quick numerical check: with f(x)=x+1f(x) = x + 1 and g(x)=x2g(x) = x^2, gof(2)=g(3)=9gof(2) = g(3) = 9 but fog(2)=f(4)=5fog(2) = f(4) = 5.

When a composition is defined

For f:A→Bf: A \to B and g:B→Cg: B \to C, the composition gof:A→Cgof: A \to C is defined because every output of ff is a valid input for gg. In general, gofgof exists only when the range of ff sits inside the domain of gg.

Example: take f(x)=xf(x) = \sqrt{x} (defined for x≥0x \geq 0) and g(x)=x−4g(x) = x - 4.

  • gof(x)=x−4gof(x) = \sqrt{x} - 4, defined for every x≥0x \geq 0.
  • fog(x)=x−4fog(x) = \sqrt{x - 4}, defined only for x≥4x \geq 4, because ff can't accept the negative outputs gg produces when x<4x < 4.

Same two functions, different order, different domain.

Worked example

f,g:R→Rf,g: \mathbb{R} \to \mathbb{R} are given by g(x)=x1/3g(x) = x^{1/3} and f(x)=8x3f(x) = 8x^3. Find gofgof and fogfog.

Solution, gof: substitute f(x)f(x) into gg:

gof(x)=g(8x3)=(8x3)1/3=81/3⋅x=2xgof(x) = g(8x^3) = (8x^3)^{1/3} = 8^{1/3} \cdot x = 2x

fog: substitute g(x)g(x) into ff:

fog(x)=f(x1/3)=8(x1/3)3=8xfog(x) = f(x^{1/3}) = 8(x^{1/3})^3 = 8x

So gof(x)=2xgof(x) = 2x but fog(x)=8xfog(x) = 8x, a clean reminder that composition order matters.

Worked example: a function that undoes itself

If f(x)=4x+36x−4f(x) = \dfrac{4x+3}{6x-4} for x≠23x \neq \dfrac{2}{3}, show that fof(x)=xfof(x) = x.

Solution: Substitute f(x)f(x) into itself, then multiply the top and bottom by 6x−46x - 4:

fof(x)=4(4x+36x−4)+36(4x+36x−4)−4=16x+12+18x−1224x+18−24x+16=34x34=xfof(x) = \dfrac{4\left(\dfrac{4x+3}{6x-4}\right) + 3}{6\left(\dfrac{4x+3}{6x-4}\right) - 4} = \dfrac{16x + 12 + 18x - 12}{24x + 18 - 24x + 16} = \dfrac{34x}{34} = x

So ff is its own inverse: applying it twice gets you back where you started.

Checking an inverse with composition

A function gg is the inverse of ff exactly when both compositions give back the input: gof(x)=xgof(x) = x and fog(x)=xfog(x) = x.

Example: for f(x)=2x+3f(x) = 2x + 3, the candidate inverse is g(x)=x−32g(x) = \dfrac{x - 3}{2}. Checking both orders:

gof(x)=(2x+3)−32=x,fog(x)=2(x−32)+3=xgof(x) = \dfrac{(2x+3) - 3}{2} = x, \qquad fog(x) = 2\left(\dfrac{x-3}{2}\right) + 3 = x

Properties worth knowing

IfThen
ff and gg are both one-onegofgof is one-one
ff and gg are both ontogofgof is onto
gofgof is one-oneff is one-one (but gg need not be)
gofgof is ontogg is onto (but ff need not be)
Any three functionsh∘(g∘f)=(h∘g)∘fh \circ (g \circ f) = (h \circ g) \circ f

Composition is associative, as the last row says, but not commutative: gofgof and fogfog usually differ, as the first two examples on this page show. They agree in special cases, such as a function and its own inverse.

Common mistakes

  • Reading gofgof left to right. The function nearest xx acts first: in g(f(x))g(f(x)) that's ff.
  • Confusing composition with multiplication. fog(x)fog(x) is f(g(x))f(g(x)), not f(x)⋅g(x)f(x) \cdot g(x).
  • Ignoring the domain. Simplifying fog(x)=x−4fog(x) = \sqrt{x - 4} is only half the answer. State that it needs x≥4x \geq 4.
  • Checking only one order for an inverse. For functions on restricted domains, gof(x)=xgof(x) = x can hold while fog(x)=xfog(x) = x fails. Check both.

Where this comes up in exams

The composition of functions is listed in the sets, relations and functions units of both the JEE Main 2026 and JEE Advanced 2026 syllabi.

Checked against JEE (Main) 2026 syllabus (NTA) and JEE (Advanced) 2026 syllabus. Syllabi can change from year to year, so confirm with the latest official notification for your exam.

Continue learning

Composition is exactly how you'd verify that a candidate inverse function actually undoes the original: check that both compositions give back xx.