My algebra textbook says that if the bases in an exponential equation are the same, then we can "cancel out" the bases and set the exponents equal to each other and then solve for $x$.
For example:
$2^{3x-8} = 2^4$
$3x-8 = 4$
$x = 4$
My question is twofold:
One, why are we allowed to "cancel out" the bases and set the exponents equal to each other when the bases are the same?
Two, why can't this method be done when the bases are NOT the same?
We are allowed to cancel out the bases because exponential function is injective, indeed for any injective function $f(x)$ by definition
$$f(x_1)=f(x_2) \implies x_1=x_2$$
In the case of exponential function injectivity is guaranteed by the fact that exponental function $f(x)=a^x$ is strictly increasing for $a>1$ (or strictly decreasing for $0<a<1$).
If the base are different it is not the case since in general $a^x\neq b^x$ for $a\neq b$.
When basis are not the same we can convert one to proceed in the same way, that is for example
$$4^{f(x)}=7^{g(x)} \iff 4^{f(x)}=(4^{\log_4 7})^{g(x)}=4^{g(x)\log_4 7}$$
To give an example for which the cancellation doesn't work let consider
$$\sin (f(x))=\sin (g(x)) \not \Rightarrow f(x)=g(x)$$
indeed $\sin x$ function is not injective on its natural domain $\mathbb{R}$.