Consider the following problem:
We have two vector spaces $U, V$; a linear transformation $T: U \rightarrow V$ and we want to represent it by a matrix. Since this process has an idea that can be easily grasped, it is common to omit the details, although they can be somewhat confusing if you try to do it in full extension. We proceed in doing the full process formally:
Definition: Given two vector spaces $U, V$, of finite dimensions $n$ and $m$ respectively; a linear transformation $T: U \rightarrow V$; a basis $\{e_j\}$ of U and a basis $\{f_i\}$ of V, we define the matrix associated to T, the domain basis $\{e_j\}$ and the codomain $\{f_i\}$ as the matrix with coefficients $a_{ij}$, where $a_{ij}$ are the numbers such that:
$$\displaystyle T(e_j)=\sum_{i=1}^m a_{ij}f_i$$
(note that everything is well-defined, since we are talking about bases)
We denote this matrix by ${}_{f_i}M^{T}_{e_j}$.
Definition: Let $\{e_j\}$ and $\{\bar{e_j}\}$ be bases of $U$. The change of basis B from $\{e_j\}$ to $\{\bar{e_j}\}$ is the linear transformation that takes $\{e_j\}$ to $\{\bar{e_j}\}$ . The matrix ${}_{e_j}M^{B}_{e_j}$ is called change of basis matrix.
Theorem 1: ${}_{f_i}M^{T}_{\bar{e_j}}={}_{f_i}M^{T}_{e_j}.{}_{e_j}M^{B}_{e_j}$.
Proof: $\displaystyle T(e_j)=\sum_{i=1}^m a_{ij}f_i$
Let $\displaystyle \bar{e_j}=\sum_{i=1}^n b_{ij} e_i$.
Then: $\displaystyle T(\bar{e_j})=T(\sum_{i=1}^n b_{ij} e_i)=\sum_{i=1}^n b_{ij} T(e_i)=
\sum_{i=1}^n b_{ij} \sum_{k=1}^m a_{ki}f_k=\sum_{k=1}^m (\sum_{i=1}^n a_{ki} b_{ij})f_k=\sum_{i=1}^m (\sum_{k=1}^n a_{ik} b_{kj})f_i$
Since $\displaystyle \sum_{k=1}^n a_{ik} b_{kj}$ is the coefficient $c_{ij}$ of the product of matrices, and the matrix $b_{ij}$ is clearly the change of basis matrix from $\{e_j\}$ to $\{\bar{e_j}\}$, the result follows. $\blacksquare$
The following lemma and corollary will be useful:
Lemma: Given $T_1: U \rightarrow V$, $T_2: V \rightarrow W$, let $T:=T_2 \circ T_1$. Then:
$${}_{g_i}M^{T}_{e_k}={}_{g_i}M^{T_2}_{f_j}.{}_{f_j}M^{T_1}_{e_k}$$
Proof: Similar computation as above. $\blacksquare$
Corollary: ${}_{e_j}M^{T}_{e_j}=({}_{e_j}M^{T^{-1}}_{e_j})^{-1}$
Proof: Take $T_1=T$ and $T_2=T^{-1}$ in the lemma above. $\blacksquare$
Now, we come to the codomain problem of changing basis:
Theorem 2: ${}_{\bar{f_i}}M^{T}_{e_j}={}_{\bar{f_i}}M^{B^{-1}}_{\bar{f_i}}
{}_{\bar{f_i}}M^{T}_{e_j}$
Proof: $\displaystyle T(e_j)=\sum_{i=1}^m a_{ij}f_i$
Let $\displaystyle f_i=\sum_{k=1}^n b_{ki} \bar{f_k}$.
Then: $\displaystyle T(e_j)=\sum_{i=1}^m a_{ij}\sum_{k=1}^n b_{ki} \bar{f_k}=\sum_{i=1}^m \sum_{k=1}^n a_{ij} b_{ki} \bar{f_k}=
\sum_{k=1}^m \sum_{i=1}^n b_{ki} a_{ij} \bar{f_k}=\sum_{i=1}^m \sum_{k=1}^n b_{ik} a_{kj} \bar{f_i}$
Since $\displaystyle \sum_{k=1}^n b_{ik} a_{kj}$ is the coefficient $c_{ij}$ of the product of matrices, and the matrix $b_{ij}$ is clearly the change of basis matrix from $\{\bar{f_i}\}$ to $\{f_i\}$, the result follows. $\blacksquare$
Corollary: ${}_{\bar{f_i}}M^{T}_{e_j}=({}_{\bar{f_i}}M^{B}_{\bar{f_i}})^{-1}
{}_{\bar{f_i}}M^{T}_{e_j}$
Proof: Follows from the previous theorem and previous corollary. $\blacksquare$
Now, with Theorems 1 and 2, we arrive at:
Theorem (Pre-Change of Basis): Given a linear transformation from a vector space $U$ of dimension $n$ to itself, we have:
$${}_{\bar{e_j}}M^{T}_{\bar{e_j}}=({}_{\bar{e_j}}M^{B}_{\bar{e_j}})^{-1}.
{}_{e_j}M^{T}_{e_j}.{}_{e_j}M^{B}_{e_j}$$
Why "Pre-Change of Basis"? Note there is a pesky annoyance on the right side that shouldn't be there: $({}_{\bar{e_j}}M^{B}_{\bar{e_j}})^{-1}$ should be $({}_{e_j}M^{B}_{e_j})^{-1}$. How to fix this? Well, we don't fix. We prove it is fixed:
Lemma: Given $T:U \rightarrow U$ isomorphism,
$${}_{e_j}M^{T}_{e_j}={}_{T(e_j)}M^{T}_{T(e_j)}$$
where $T(e_j)$ should be understood as the basis of $U$ given by $\{T(e_j)\}_{j=1}^n$
Proof: $\displaystyle T(e_j)=\sum_{i=1}^m a_{ij}e_j$
and
$\displaystyle T(T(e_j))=\sum_{i=1}^m a_{ij}T(e_j)$ $\blacksquare$.
Now, we have the theorem:
Theorem: Given a linear transformation from a vector space $U$ of dimension $n$ to itself, we have:
$${}_{\bar{e_j}}M^{T}_{\bar{e_j}}=({}_{e_j}M^{B}_{e_j})^{-1}.
{}_{e_j}M^{T}_{e_j}.{}_{e_j}M^{B}_{e_j}$$
and, passing to its common form:
Theorem (Change of Basis): Given a linear transformation from a vector space $U$ of dimension $n$ to itself, we have:
$${}_{e_j}M^{T}_{e_j}={}_{e_j}M^{B}_{e_j}.{}_{\bar{e_j}}M^{T}_{\bar{e_j}}.({}_{e_j}M^{B}_{e_j})^{-1}$$
Note that in the case of a matrix with orthonormal basis of eigenvectors, the notation for this equality is commonly seen as:
$$A=P.D.P^{-1}$$