Note that $R(AB)\subseteq R(A)$ always holds: if $x$ is any vector, then $AB(x) = A(Bx)\in R(A)$.
Thus, if $\mathrm{rank}(AB)=\mathrm{rank}(A)$, then that means that $\dim(R(AB))=\dim(R(A))$; since $R(AB)\subseteq R(A)$, equality of dimensions suffices to conclude that $R(AB)=R(A)$, because we are in finite dimension. Conversely, if $R(AB)=R(A)$, then they necessarily have the same dimension, hence the ranks of $AB$ and of $A$ must be equal.
(Yes: if $V$ is finite dimensional, and $W\leq V$, then $W=V$ if and only if $\dim(W)=\dim(V)$: if $\dim(W)=\dim(V)$, then take a basis for $W$; then this already has the right number of elements to be a basis for $V$, and since it is linearly independent, it spans $V$; since it also spans $W$, we have $V=W$. Conversely, if $V=W$, then $\dim(V)=\dim(W)$. This does not work if $\dim(V)$ is infinite, and also does not work if you don't know that $W$ is contained in $V$; but if you have both conditions, it does.)
Similarly, $N(B)\subseteq N(AB)$, since $Bx=0$ implies $ABx=0$. Thus: $\begin{align*} N(B)=N(AB) &\iff \dim(N(B))=\dim(N(AB))\\ &\iff \mathrm{null}(B)=\mathrm{null}(AB)\\ &\iff n-\mathrm{null}(B) = n-\mathrm{null}(AB)\\ &\iff \mathrm{rank}(B) = \mathrm{rank}(AB) \end{align*}$ with the last equivalence by the Rank-Nullity Theorem.