On this page
Most students learn that fog and gof are usually different. Fewer learn that one of them may not exist at all, and that one quick check tells you which.
When is fog defined?
NCERT's Class 12 chapter on relations and functions defines composition only when the functions line up: if f: A → B and g: B → C, then gof: A → C is given by gof(x) = g(f(x)) for every x in A (NCERT Mathematics Part I, Chapter 1, Definition 8). Swap the roles and fog(x) = f(g(x)) needs g to feed into f. The working test is that the range of g must lie within the domain of f.
In plain words, g acts first and hands every output to f. If f cannot accept even one of them, f(g(x)) breaks there.
The OpenStax Precalculus 2e chapter on composition puts it in one line: "the range of the inside function (the first function to be evaluated) needs to be within the domain of the outside function."
Why can gof exist when fog does not?
The two orders ask different questions:
gof needs the range of f to sit inside the domain of g.
fog needs the range of g to sit inside the domain of f.
Nothing forces both at once. Here are three cases where only the first holds.
First, NCERT's own finite sets. In Example 15 of the same NCERT chapter, f: {2, 3, 4, 5} → {3, 4, 5, 9} has f(2) = 3, f(3) = 4 and f(4) = f(5) = 5, while g: {3, 4, 5, 9} → {7, 11, 15} has g(3) = g(4) = 7 and g(5) = g(9) = 11. The book works out gof(2) = 7, gof(3) = 7, gof(4) = 11 and gof(5) = 11.
Now try fog. The range of g is {7, 11}, and neither 7 nor 11 is in the domain of f, {2, 3, 4, 5}, so f(g(x)) has no value for any x.
Second, a square root after a shift. Take f(x) = √x with domain [0, ∞), and g(x) = x − 5 with domain all real numbers.
gof(x) = √x − 5. The range of f is [0, ∞), which sits inside the domain of g, so gof works for every x ≥ 0.
fog(x) = √(x − 5). The range of g includes negative numbers. At x = 1, g(1) = −4, and √(−4) is not a real number.
Third, a logarithm and a sine. Take f(x) = ln x with domain (0, ∞), and g(x) = sin x with range [−1, 1].
gof(x) = sin(ln x). Sine accepts every real number, so this works for every x > 0.
fog(x) = ln(sin x). The range of g includes 0 and negative numbers, which ln cannot take. At x = 3π/2, sin x = −1, and ln(−1) is undefined.
OpenStax states that second version directly: the domain of f(g(x)) is "the set of those inputs x in the domain of g for which g(x) is in the domain of f" (OpenStax Precalculus 2e, section 1.4).
How do you check whether fog is defined?
Before you write a formula:
Write the domain of f: what f is allowed to take.
Find the range of g: what g actually produces, not the domain of g.
Compare. If the range of g sits inside the domain of f, fog is defined on the whole domain of g.
If it does not, read the question. Either say fog is not defined on that domain, or restrict the inputs to those x where g(x) lands inside the domain of f.
Swap f and g to check gof. For more practice with restricted inputs, see how to find the domain of log(log x) and other nested functions.
Which mistakes cost marks here?
Reading fog as "f first". In NCERT's notation fog(x) = f(g(x)), so g acts first.
Comparing the domain of g with the domain of f, instead of the range of g.
Simplifying before checking. (√x)² looks like plain x, but the composite only accepts x ≥ 0.
The same care with domains shows up when you find the domain of f + g, f × g and f / g, and when you graph an inverse function by reflecting in y = x, since NCERT defines an inverse through gof and fog.
If a composition question keeps going wrong at the same step, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer. If the gap is in domain and range themselves, the lesson on each in the Fermi Concept Library is a good place to start.
Next time you see fog, find the range of g first. Everything else follows from that one comparison.



