Since you have g(f(x)), x MUST be in the domain of f in order for f(x) to be defined- that is, the domain of g(f) is a subset of the domain of f.
Then, however, f(x) must be such that g(f(x)) is defined. Start with the domain of f and delete those values for which g(f(x)) is not defined. Exactly how you do that depends on the specific values of f and g.
In your original example, the domains of both g and f are 'all real numbers' so the domain of g(f) is also 'all real numbers'.
If you had g(x)= sqrt(x), f(x)= 3x- 1, the domain of f is all real numbers but the domain of g is only non-negative numbers. For what x is 3x-1>= 0?
Conversely, if g(x)= 3x-1, f(x)= sqrt(x), The domain of f is non-negative numbers. Since g(x) is defined for all x, g(f(x)) is defined for all numbers for which f is defined: non-negative numbers.