In short

The composite function (f \circ g)(x) = f(g(x)) is built by feeding the output of g into the input of f. The domain of f \circ g consists of all x in the domain of g such that g(x) lies in the domain of f. Composition is associative but generally not commutative: f \circ g \ne g \circ f in most cases.

A cloth merchant in Varanasi buys raw silk by weight. The price of raw silk depends on its grade, and the grade depends on the thread count per centimetre. So to get from thread count to price, you go through two steps: thread count \to grade \to price. Each step is a function. The combined process — thread count directly to price — is a composite function: the output of the first function becomes the input of the second.

This two-step chaining is everywhere. Converting Celsius to Fahrenheit and then Fahrenheit to Kelvin. Computing a student's percentage from raw marks and then converting percentage to a grade. Squaring a number and then taking its sine. In each case, you are not adding or multiplying two functions at the same input — you are piping one function's output into another function's input. That is composition.

The definition

Take two functions f and g. The composite function f \circ g (read "f composed with g," or "f of g") is defined by:

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

The process: start with x, apply g to get g(x), then apply f to that result to get f(g(x)).

Composition of Functions

Given f: B \to C and g: A \to B, the composite function f \circ g: A \to C is defined by

(f \circ g)(x) = f(g(x)) \quad \text{for all } x \in A \text{ such that } g(x) \in \text{domain of } f.

The notation matters. In f \circ g, g acts first and f acts second. The function written on the right is the one applied first. This is counterintuitive — it reads left-to-right but operates right-to-left. Hold on to this: in f \circ g, g goes first.

Pipeline diagram showing composition f of gAn input x enters a box labelled g, which outputs g(x). That output enters a box labelled f, which outputs f(g(x)). The whole pipeline is labelled f compose g. g f x g(x) f(g(x)) f ∘ g
Composition is a pipeline. The input $x$ flows through $g$ first, then the intermediate output $g(x)$ flows through $f$. The composite $f \circ g$ is the combined machine.

A concrete example: let f(x) = x^2 and g(x) = x + 3. Then:

(f \circ g)(x) = f(g(x)) = f(x+3) = (x+3)^2

And in the other order:

(g \circ f)(x) = g(f(x)) = g(x^2) = x^2 + 3

The results are different. (x+3)^2 = x^2 + 6x + 9 is not the same as x^2 + 3. This is the first important fact about composition: order matters.

Graphs showing f compose g is not equal to g compose fTwo parabolas on the same axes. One is y equals (x+3) squared, shifted 3 units left, representing f compose g. The other is y equals x squared plus 3, shifted 3 units up, representing g compose f. They are visibly different curves. x y 1 2 −1 −2 −3 3 9 (f∘g): (x+3)² (−3, 0) g∘f: x²+3 (0, 3)
The two compositions of $f(x) = x^2$ and $g(x) = x + 3$ produce different curves. $f \circ g$ (red) has vertex at $(-3, 0)$: the parabola is shifted left. $g \circ f$ (black) has vertex at $(0, 3)$: the parabola is shifted up. Composition is not commutative.

Domain of a composite function

The domain of f \circ g is not simply the domain of g. There are two conditions:

  1. x must be in the domain of g (otherwise g(x) is not defined).
  2. g(x) must be in the domain of f (otherwise f(g(x)) is not defined).
\text{Domain of } f \circ g = \{x \in D_g : g(x) \in D_f\}

Take f(x) = \sqrt{x} (domain [0, \infty)) and g(x) = 1 - x^2 (domain \mathbb{R}). Then:

(f \circ g)(x) = \sqrt{1 - x^2}

Condition 1: x \in \mathbb{R} (always satisfied). Condition 2: g(x) = 1 - x^2 \ge 0, which gives x^2 \le 1, i.e., -1 \le x \le 1.

Domain of f \circ g: [-1, 1].

Domain of f compose g shown as a filtered pipelineThree number lines. Top: domain of g is all reals. Middle: the output of g must land in the domain of f, which is 0 to infinity. Bottom: only x values in negative 1 to 1 produce g(x) values in the domain of f. This intersection is the domain of f compose g. D_g all of ℝ D_f 0 [0, ∞) D_{f∘g} −1 1 [−1, 1]
Finding the domain of $f \circ g$ where $f(x) = \sqrt{x}$ and $g(x) = 1 - x^2$. Start with the domain of $g$ (all reals), then filter to keep only those $x$ where $g(x)$ lands in the domain of $f$ (non-negative reals). The result is $[-1, 1]$.

Here is another example. Let f(x) = \frac{1}{x} (domain \mathbb{R} \setminus \{0\}) and g(x) = x - 5 (domain \mathbb{R}). Then (f \circ g)(x) = \frac{1}{x-5}. Condition 1: x \in \mathbb{R}. Condition 2: g(x) = x - 5 \ne 0, i.e., x \ne 5. Domain: \mathbb{R} \setminus \{5\}.

Properties of composition

Composition is not commutative

You already saw this with f(x) = x^2 and g(x) = x + 3: (f \circ g)(x) = (x+3)^2 while (g \circ f)(x) = x^2 + 3. In general, f \circ g \ne g \circ f.

There are special cases where f \circ g = g \circ f — for instance, when f and g are both linear functions of the form ax + b with the same slope a = 1 (pure translations), or when one of them is the identity function \text{id}(x) = x. But these are exceptions, not the rule.

The identity function

The function \text{id}(x) = x is the identity for composition:

f \circ \text{id} = f, \qquad \text{id} \circ f = f

This is immediate: f(\text{id}(x)) = f(x) and \text{id}(f(x)) = f(x).

The identity function is to composition what the number 1 is to multiplication and what 0 is to addition — the element that leaves everything unchanged.

Composition is associative

This is the deepest property. Given three functions f, g, h:

(f \circ g) \circ h = f \circ (g \circ h)

The parentheses do not matter. Whether you first compose f with g and then compose the result with h, or first compose g with h and then compose f with the result, you get the same function.

Diagram showing associativity of compositionThree function boxes h, g, f in a pipeline. Two different groupings are shown: first grouping h then g together, then applying f; or first grouping g then f together, then applying to h's output. Both produce the same final result. h g f f(g(h(x))) x g ∘ h f ∘ (g ∘ h) (f ∘ g) ∘ h f ∘ g both give the same result
Three functions in a pipeline. Grouping as $(f \circ g) \circ h$ or $f \circ (g \circ h)$ makes no difference — the data flows through the same three steps in the same order. This is associativity.

The proof is direct. For any x in the appropriate domain:

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

Both expressions evaluate to f(g(h(x))). Since the two functions agree at every input, they are the same function.

Because composition is associative, you can write f \circ g \circ h without ambiguity — it means "apply h first, then g, then f." The same extends to any number of functions: f_1 \circ f_2 \circ \cdots \circ f_n is well-defined regardless of how you group the parentheses.

Two worked examples

Example 1: Find $(f \circ g)(x)$ and $(g \circ f)(x)$ for $f(x) = 2x + 1$ and $g(x) = x^2 - 3$, and determine their domains

Step 1. Compute (f \circ g)(x) = f(g(x)). Substitute g(x) = x^2 - 3 into f:

f(g(x)) = f(x^2 - 3) = 2(x^2 - 3) + 1 = 2x^2 - 6 + 1 = 2x^2 - 5

Why: replace the input of f (which is x) with the entire expression g(x) = x^2 - 3.

Step 2. Determine the domain of f \circ g. Domain of g: \mathbb{R} (polynomial). For every x \in \mathbb{R}, g(x) = x^2 - 3 is a real number, which lies in the domain of f (\mathbb{R}). So domain of f \circ g is \mathbb{R}.

Why: both conditions (x in domain of g, and g(x) in domain of f) are satisfied for all real x.

Step 3. Compute (g \circ f)(x) = g(f(x)). Substitute f(x) = 2x + 1 into g:

g(f(x)) = g(2x+1) = (2x+1)^2 - 3 = 4x^2 + 4x + 1 - 3 = 4x^2 + 4x - 2

Why: replace the input of g with the expression f(x) = 2x + 1, then expand.

Step 4. Compare. (f \circ g)(x) = 2x^2 - 5 and (g \circ f)(x) = 4x^2 + 4x - 2. These are different quadratics — different leading coefficients, different linear terms, different constants.

Why: composition is not commutative. The order of application matters.

Result: (f \circ g)(x) = 2x^2 - 5 on \mathbb{R}. (g \circ f)(x) = 4x^2 + 4x - 2 on \mathbb{R}. They are not equal.

Graphs of f compose g and g compose f from Example 1Two parabolas. The first, f compose g equals 2x squared minus 5, has vertex at (0, negative 5) and opens upward. The second, g compose f equals 4x squared plus 4x minus 2, has vertex at (negative one half, negative 3) and opens upward more steeply. They are clearly different curves. x y 1 2 −1 −2 −5 5 f∘g: vertex (0, −5) g∘f: vertex (−½, −3)
The two compositions produce different parabolas. $f \circ g = 2x^2 - 5$ (red) has its vertex at $(0, -5)$. $g \circ f = 4x^2 + 4x - 2$ (black) has its vertex at $(-\frac{1}{2}, -3)$ and is steeper. Different functions, same ingredients.

The picture makes the non-commutativity vivid. The two parabolas have different vertices, different widths, and different shapes — even though they are built from the same two functions.

Example 2: Find $(f \circ g)(x)$ and its domain for $f(x) = \frac{1}{x-2}$ and $g(x) = \sqrt{x}$

Step 1. Compute (f \circ g)(x) = f(g(x)). Substitute g(x) = \sqrt{x} into f:

f(g(x)) = f(\sqrt{x}) = \frac{1}{\sqrt{x} - 2}

Why: wherever f has x, replace it with \sqrt{x}.

Step 2. Apply condition 1: x must be in the domain of g. Since g(x) = \sqrt{x}, you need x \ge 0.

Why: the square root requires a non-negative input.

Step 3. Apply condition 2: g(x) must be in the domain of f. Since f requires its input \ne 2, you need \sqrt{x} \ne 2, i.e., x \ne 4.

Why: f has a denominator x - 2, and here the "input to f" is \sqrt{x}. So \sqrt{x} - 2 \ne 0.

Step 4. Combine the conditions. x \ge 0 and x \ne 4. In interval notation: [0, 4) \cup (4, \infty).

Why: intersect the two conditions. The domain is [0, \infty) with the single point 4 removed.

Result: (f \circ g)(x) = \frac{1}{\sqrt{x} - 2}, domain = [0, 4) \cup (4, \infty).

Graph of f compose g equals 1 over root x minus 2The curve y equals 1 over square root of x minus 2, for x from 0 to about 10. There is a vertical asymptote at x equals 4 where the denominator is zero. For x between 0 and 4 the curve is negative (below the x-axis). For x greater than 4 the curve is positive and decreasing. x y 1 4 7 10 1 2 −1 x = 4 (0, −½)
The composite function $\frac{1}{\sqrt{x}-2}$. The vertical asymptote at $x = 4$ is where $\sqrt{x} = 2$, making the denominator zero. For $0 \le x < 4$, $\sqrt{x} < 2$, so the denominator is negative and the function takes negative values. For $x > 4$, $\sqrt{x} > 2$, and the function is positive.

At x = 0, f(g(0)) = f(0) = \frac{1}{0-2} = -\frac{1}{2}. At x = 9, f(g(9)) = f(3) = \frac{1}{3-2} = 1. Both match the graph.

Common confusions

Interactive: explore composition

Interactive: f compose g where f(x) = x squared and g(x) = x + 1The curve (x+1) squared is plotted. A draggable point sits on the curve. The readouts show the input x, the intermediate value g(x) = x+1, and the final output f(g(x)) = (x+1) squared. x y 1 2 −1 −2 1 4 drag the red point
Drag the point along $(f \circ g)(x) = (x+1)^2$, where $f(x) = x^2$ and $g(x) = x + 1$. The readout shows each step: the input $x$, the intermediate value $g(x) = x + 1$, and the final output $f(g(x)) = (x+1)^2$. At $x = -1$, the intermediate is $0$ and the output is $0$. At $x = 0$, the intermediate is $1$ and the output is $1$.

The material above covers all of the composition content required for class 11 and most of JEE Main. The following sections explore two ideas that appear in JEE Advanced and beyond.

Decomposing functions

Composition also works in reverse: given a complicated function, you can break it into simpler parts. Take h(x) = \sqrt{x^2 + 1}. This is the composition f \circ g where g(x) = x^2 + 1 and f(t) = \sqrt{t}.

This decomposition is not unique. You could also write h = f \circ g with g(x) = x^2 and f(t) = \sqrt{t + 1}. Both decompositions are valid. The choice depends on what is useful — sometimes one decomposition makes a derivative easier to compute (this is exactly the chain rule in calculus).

Some standard decompositions:

Composite Inner g(x) Outer f(t)
\sin(3x+2) 3x + 2 \sin t
e^{x^2} x^2 e^t
(2x-1)^5 2x - 1 t^5
\log(\sin x) \sin x \log t

Composition and injectivity/surjectivity

Composition interacts with the key function properties in a structured way:

Self-composition and iteration

You can compose a function with itself: f \circ f, written f^2. More generally, f^n means f composed with itself n times:

f^n(x) = \underbrace{f(f(\cdots f}_{n \text{ times}}(x) \cdots ))

For f(x) = 2x: f^2(x) = 2(2x) = 4x, f^3(x) = 2(4x) = 8x, and in general f^n(x) = 2^n x.

For f(x) = x^2: f^2(x) = (x^2)^2 = x^4, f^3(x) = (x^4)^2 = x^8, and in general f^n(x) = x^{2^n}.

Self-composition appears in the study of dynamical systems, fixed points, and iterative algorithms — topics well beyond class 11, but the seed is planted here.

Where this leads next

You now know how to compose functions, find the domain of a composite, and work with the key properties — especially non-commutativity and associativity. Here is where this connects.