Reading the notation
gof means "first apply f, then apply g to the result", read right to left: (g∘f)(x)=g(f(x)). Likewise fog(x)=f(g(x)). There's no reason these have to match.
Worked example
f,g:R→R are given by g(x)=x1/3 and f(x)=8x3. Find gof and fog.
Solution, gof: substitute f(x) into g:
gof(x)=g(8x3)=(8x3)1/3=81/3⋅x=2xfog: substitute g(x) into f:
fog(x)=f(x1/3)=8(x1/3)3=8xSo gof(x)=2x but fog(x)=8x, a clean reminder that composition order matters.