Let $x_1,\ldots,x_r$ be a basis for $\mathrm{Im}(B)\cap\mathrm{null}(A)$. For each $x_i$, let $y_i$ be a vector such that $B(y_i)=x_i$. Note that $y_1,\ldots,y_n$ are linearly independent, since their images are linearly independent.
Moreover, $\mathrm{span}(y_1,\ldots,y_n)\cap\mathrm{null}(B)=\{\mathbf{0}\}$: if $\alpha_1y_1+\cdots+\alpha_ny_n\in\mathrm{null}(B)$, then its image under $B$ equals $\mathbf{0}$, but it also equals $\alpha_1x_1+\cdots+\alpha_nx_n$, and by the linear independence of the $x_i$, this means $\alpha_1=\cdots=\alpha_n=0$.
Let $z_1,\ldots,z_m$ be a basis for $\mathrm{null}(B)$. By the observation above, we have that $y_1,\ldots,y_n,z_1,\ldots,z_m$ are linearly independent. Note that all of these vectors lie in $\mathrm{null}(AB)$ (the $z_i$ because they lie in $\mathrm{null}(B)$, the $y_i$ because $B(y_i)\in\mathrm{null}(A)$). Thus, $\dim\mathrm{null}(AB)\leq n+m$.
I claim that in fact $\mathrm{null}(AB)=\mathrm{span}(y_1,\ldots,y_n,z_1,\ldots,z_m)$. Indeed, let $w\in\mathrm{null}(AB)$. Then $B(w)\in\mathrm{null}(A)$, so there exist $\alpha_1,\ldots,\alpha_n$ such that
$$B(w) = \alpha_1x_1 + \cdots + \alpha_nx_n = \alpha_1B(y_1)+\cdots+\alpha_nB(y_n) = B(\alpha_1y_1+\cdots +\alpha_ny_n).$$
Therefore, $w-(\alpha_1y_1+\cdots +\alpha_ny_n)\in\mathrm{null}(B)$, so there exist scalars $\beta_1,\ldots,\beta_m$ such that
$$\begin{align*}
w-(\alpha_1y_1+\cdots+\alpha_ny_n) &= \beta_1z_1+\cdots+\beta_mz_m\\
w &= \alpha_1y_1+\cdots+\alpha_ny_n+\beta_1z_1+\cdots + \beta_mz_m
\end{align*}$$
which means that $w\in\mathrm{span}(y_1,\ldots,y_n,z_1,\ldots,z_m)$.
Therefore $\dim(\mathrm{null}(AB)) = n+m$.
Now, $\dim(\mathrm{null}(B)) = m$ since $z_1,\ldots,z_m$ are a basis for $\mathrm{null}(B)$. And $n\leq \dim(\mathrm{null}(A))$, since $x_1,\ldots,x_n$ are a basis for $\mathrm{null}(A)\cap \mathrm{Im}(B)$, which is a subspace of $\mathrm{null}(A)$. Therefore,
$$\dim(\mathrm{null}(AB))= n+m =\dim(\mathrm{null}(A)\cap\mathrm{Im}(B))+\dim(\mathrm{null}(B)\leq \dim(\mathrm{null}(A)) + \dim(\mathrm{null}(B)),$$
which yields the desired inequality.