Often when discussing composite functions, whilst the notation fog(x) is more convenient to write, the notation f(g(x)) is easier to understand.
Using the second notation, we can clearly see that in our "machine examples", we have the following case:
Domain of g Range of g Domain of f Range of f
input----------->transition------------->transition--------->output
From this, we can clearly see two things:
1. If the numbers coming out of g aren't defined in f's domain, then the composition cannot exist. I.e, the

2. The domain of our composition must be the domain of g.
The range is slightly harder - if the range of g is exactly equal to the domain of f, then the range of f must not have changed, and so the range of the composition is simply the range of f. If the range of g, however, is not exactly equal to f (i.e., is only a subset of f's domain), then you must draw f using the range of g as its domain to find the new range of the composition.