Where fg can fail
fg(x) means f(g(x)): x goes into g first, and the output of g goes into f. So every output g can give must be a number f accepts.
Take , whose domain is , and g(x) = x − 3, which accepts every number. At x = 1, g gives 1 − 3 = −2, and is not a real number. As written, fg does not exist.
The condition
fg exists exactly when the range of g lies inside the domain of f: range of domain of f.
Only the range of g matters, not its domain: f never sees the x values, only what g makes of them.
To make fg exist here, restrict g. On , g(x) = x − 3 gives every value , and every one of those is in the domain of f.
The range of g on is . It starts at the same point as the domain of f and runs the same way, so it lies inside it.
The domain and range of fg
With g restricted, fg. Its domain is the domain of g, , because x goes into g first.
Its range comes out of f: as x runs from 3 upward, x − 3 runs from 0 upward, and so does its square root. The range of fg is .
The other order
gf. Now the outputs of f go into g. The range of f is , and g accepts every number, so gf exists on the whole domain of f, .
Its range is : starts at 0, and g takes 3 away. One composite can exist while the other does not, so check each order separately.
A composite that always exists
Take again and . The range of g is , which lies inside , so fg exists for every x.
With , the range of g is , and fg exists for when .
The usual slips
Reading the domain of as . The expression under the root must be at least 0, so and .
Checking the domain of g instead of its range. What reaches f is the outputs of g.
Mixing up the order. fg feeds g into f and needs the range of g inside the domain of f; gf needs the range of f inside the domain of g.