# Why does the composition of functions $g(f(x))$ require the codomain of $f$, and not its image, be the same as the domain of $g$?

As the question title states, for a composition of functions $f(g(x))$ I was taught that the domain of $g$ has to be the same as the codomain of $f$. Why? Can't you say that the image of $f$ and the domain of g must be the same? Perhaps when I was taught it was simply poorly worded and should have been that the domain of $g$ must be a subset of the codomain of $f$? Surely only every point produced by the map $f$, ie $f$'s image, needs to be then mapped by $g$.

• $gof(x)=g(f(x))$ thus we have to have $f(X)\subseteq$ domain$g$ – R.N Nov 26 '15 at 12:27
• It is necessary that the image of $f$ is contained in the domain of $g$, and sufficient that the codomain of $f$ is equal to the domain of $g$. – Christian Blatter Nov 26 '15 at 13:00

When you have a composition of function written as $f(g(x))$ this is equivalent to
$x \rightarrow g(x) \rightarrow f(g(x))$
applying $g$ and then $f$ on the image of $g$. This operation makes sense only when the image of $g$ is contained in the domain of $f$