Let's complete the square
f(x) = x^2 + 6x + 8
y = x^2 + 6x + 8
y-8 = x^2 + 6x
y-8+9 = x^2+6x+9 .... see note below
y+1 = (x+3)^2
y = (x+3)^2-1
note: I added 9 to both sides due to taking half of the 6, and then squaring that result.
We'll restrict x such that
to ensure that this function is one-to-one.
Now we need to swap x and y, and solve for y to get the inverse
y = (x+3)^2 - 1
x = (y+3)^2 - 1
x+1 = (y+3)^2
(y+3)^2 = x+1
y+3 = sqrt(x+1)
y = sqrt(x+1)-3
g(x) = sqrt(x+1)-3 is the inverse
The graph is shown below. The original function is in red. The inverse is in blue. The inverse is the result of reflecting the red curve over the dashed line y = x. So this explains why x and y swap places. Consequently, the domain and range also swap as well.