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$.
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$