When does the matrix equation $AXB = C$ have a solution? 
When is the matrix equation $$AXB = C$$ solvable for $X$? Assume non-square matrices $A$, $B$, $C$ and $X$ with compatible dimensions.

I need the answer in terms of relations between their rank/nullity/range spaces/null spaces etc. 
 A: We have the matrix equation in $\mathrm X \in \mathbb R^{n \times p}$
$$\mathrm A \mathrm X \mathrm B = \mathrm C$$
where $\mathrm A \in \mathbb R^{m \times n}$, $\mathrm B \in \mathbb R^{p \times q}$ and $\mathrm C \in \mathbb R^{m \times q}$ are given.
Left-multiplying by $\mathrm A^T$ and right-multiplying by $\mathrm B^T$, we obtain
$$\mathrm A^T \mathrm A \mathrm X \mathrm B \mathrm B^T = \mathrm A^T \mathrm C \mathrm B^T$$
If $\mathrm A$ has full column rank and $\mathrm B$ has full row rank, then $\mathrm A^T \mathrm A$ and $\mathrm B \mathrm B^T$ are invertible. Hence,
$$\hat{\mathrm X} := (\mathrm A^T \mathrm A)^{-1} \mathrm A^T \mathrm C \mathrm B^T (\mathrm B \mathrm B^T)^{-1}$$
is a candidate solution. Left-multiplying $\hat{\mathrm X}$ by $\mathrm A$ and right-multiplying it by $\mathrm B$, we obtain
$$\mathrm A \hat{\mathrm X} \mathrm B = \underbrace{\mathrm A (\mathrm A^T \mathrm A)^{-1} \mathrm A^T}_{=: \mathrm P_{\mathrm A}} \mathrm C \underbrace{\mathrm B^T (\mathrm B \mathrm B^T)^{-1} \mathrm B}_{=: \mathrm P_{\mathrm B^T}} = \mathrm P_{\mathrm A} \mathrm C \mathrm P_{\mathrm B^T}$$
where $\mathrm P_{\mathrm A}$ and $\mathrm P_{\mathrm B^T}$ are the projection matrices that project onto the column space of $\mathrm A$ and the row space of $\mathrm B$, respectively. If
$$\mbox{Im} (\mathrm C) \subseteq \mbox{Im} (\mathrm A) \qquad \qquad \qquad \mbox{Im} (\mathrm C^T) \subseteq \mbox{Im} (\mathrm B^T)$$
then
$$\mathrm P_{\mathrm A} \mathrm C \mathrm P_{\mathrm B^T} = \mathrm C$$
and the candidate solution $\hat{\mathrm X}$ is indeed a solution to the matrix equation $\mathrm A \mathrm X \mathrm B = \mathrm C$.
