A composite function sends the output of one function into another. In f composed with g, apply g first and then f. The composition symbol records the order of those steps. It does not ask you to multiply the two outputs.
Apply the inner function before the outer function
Take f to be the rule that doubles its input and adds 1. Let g square its input. Applying g to 3 gives 9. Applying f to 9 gives 19. In the reverse order, f first gives 7 and g then gives 49. Both computations are allowed, but they give different results.
The same distinction holds when the input is a variable. Replacing the input of f by the entire expression for g squares x before doubling. Replacing the input of g by the expression for f squares the whole sum instead. Keep the parentheses until you know which operations apply to which terms.
An allowed first input can still lead to an invalid second input
Let g subtract 4, and let f take a real square root. The rule g can take any real input, but its output must be nonnegative for f. The composition therefore starts at x equal to 4. At that endpoint, g gives zero and the square root is zero. For x equal to 3, g gives negative one and the composition has no real value.
This is why the domain comes from both rules. Check the input of the inner function first. Then check whether its output belongs to the domain of the outer function.
