Hint:
$$
\mathbf{A}^{2} = \mathbf{A}
\quad
\Leftrightarrow
\quad
\mathbf{A}^{2} - \mathbf{A} = \mathbf{0}_{n\times n}
\quad
\Leftrightarrow
\quad
\mathbf{A} \left(\mathbf{A}-\mathbf{I}\right) = \mathbf{0}_{n\times n}.
$$
Let $\mathbf{B} = (\mathbf{A} - \mathbf{I})$.
The above implies that every vector in the range of $\mathbf{B}$ lies in the nullspace of $\mathbf{A}$. Can you take it from there?
Edit: I am expanding the answer because it seems we need to clarify a few things.
Why is it that the range of $\mathbf{B}$ lies in the nullspace of $\mathbf{A}$?
Let $\mathbf{w}$ be any vector in the range of $\mathbf{B}$, $\mathcal{R}(\mathbf{B})$. This means that we can write $\mathbf{w}$ as a linear combination of the columns of $\mathbf{B}$, i.e., there exists a $\mathbf{c}$ such that $\mathbf{w}=\mathbf{B}\mathbf{c}$. But,
$$
\mathbf{A}\mathbf{w}
=\mathbf{A}\mathbf{B}\mathbf{c}
= \mathbf{0}_{n\times n} \mathbf{c}
= \mathbf{0},
$$
which implies that $\mathbf{w}$ belongs to the nullspace of $\mathbf{A}$, $\mathcal{N}(\mathbf{A})$.
Hence, we have shown that
$$
\mathbf{w} \in \mathcal{R}(\mathbf{B})
\quad
\Rightarrow
\quad
\mathbf{w} \in \mathcal{N}(\mathbf{A}),
$$
or equivalently,
$$
\mathcal{R}(\mathbf{B}) \subseteq \mathcal{N}(\mathbf{A}).
$$
The above implies that
$$
\text{nullity}(\mathbf{A}) \ge \text{rank}(\mathbf{B})=\text{rank}(\mathbf{A}-\mathbf{I}).
$$
But we are not quite done yet, since we want to show that the two sides are actually equal.
I am assuming that you should be familiar with the Rank-Nullity Theorem. How can you use that to show the other side of the inequality.
Edit 2: (This is the point where hints start looking a lot like an answer!)
The Rank-Nullity Theorem theorem says that
$$
n = \text{rank}(\mathbf{A}) + \text{nullity}(\mathbf{A})
\quad
\Rightarrow
\quad
\text{nullity}(\mathbf{A}) = n - \text{rank}(\mathbf{A}).
$$
What can you say about $\text{rank}(\mathbf{A} - \mathbf{I})$ with respect to $\text{rank}(\mathbf{A})$? How can you get it into the picture? (Remember! we are trying to show that $\text{nullity}(\mathbf{A}) \le \text{rank}(\mathbf{A} - \mathbf{I})$ because we have already shown the reverse inequality.)
Edit 3:
We have already shown that
$\text{nullity}(\mathbf{A}) \ge \text{rank}(\mathbf{A}-\mathbf{I})$.
To show that the relation holds with equality, it suffices to show that
$$
\text{nullity}(\mathbf{A}) \le \text{rank}(\mathbf{A}-\mathbf{I}).
$$
We have already seen that
$$
\text{nullity}(\mathbf{A}) = n - \text{rank}(\mathbf{A}).
$$
Hence, to show the desired result, it suffices to show that
$$
n - \text{rank}(\mathbf{A}) \le \text{rank}(\mathbf{A}−\mathbf{I}).
$$
One way to argue about this, possibly not the best, is the following.
Let $\mathbf{B} = \mathbf{A} - \mathbf{I}$. By the rank-nullity theorem, we know that
$$
\text{rank}(\mathbf{B})
+
\text{nullity}(\mathbf{B}) = n.
$$
Now, the nullspace of $\mathbf{B}$, $\mathcal{N}(\mathbf{B})$, consists of all vectors $\mathbf{w}$ such that $\mathbf{B}\mathbf{w}=\mathbf{0}$, or equivalently:
$$
\mathbf{w} \in \mathcal{N}(\mathbf{B})
\quad
\Leftrightarrow
\quad
(\mathbf{A}-\mathbf{I})\mathbf{w} = \mathbf{0}
\quad
\Leftrightarrow
\quad
\mathbf{A}\mathbf{w} = \mathbf{w}.
$$
These vectors $\mathbf{w}$ are clearly just a subset of the range of $\mathbf{A}$.
In other words,
$$
\mathbf{w} \in \mathcal{N}(\mathbf{B})
\quad
\Rightarrow
\quad
\mathcal{R}(\mathbf{A}),
$$
and in turn,
$
\mathbf{w} \in \mathcal{N}(\mathbf{B})
\subseteq
\mathcal{R}(\mathbf{A}).
$
We conclude that $\text{nullity}(\mathbf{B}) \le \text{rank}(\mathbf{A})$ and finally,
$$
\text{rank}(\mathbf{B})
= n-\text{nullity}(\mathbf{B})
\ge n-\text{rank}(\mathbf{A}),
$$
which is the desired inequality
$$
\text{rank}(\mathbf{A}-\mathbf{I}) \ge n-\text{rank}(\mathbf{A}).
$$