The proof is not immediately obvious. We start by noting that $$\hat a|n\rangle = k|n-1\rangle$$for some constant ##k##, where we take ##k## to be real and positive by convention. Note that eigenstates are defined only up to a complex phase factor, so we need this convention.
Next, using $$\hat a^{\dagger}\hat a |n\rangle = n|n\rangle$$ and the normalisation of ##|n\rangle## we see that$$\langle n|\hat a^{\dagger}\hat a |n\rangle = \langle n| n|n\rangle = n$$Finally, we evaluate the LHS a different way: $$\langle n|\hat a^{\dagger}\hat a |n\rangle = \langle n|\hat a^{\dagger}k|n-1\rangle = k\langle n-1|\hat a|n\rangle^* = k\langle n-1|k|n-1\rangle^* = k^2$$using the normalisation of ##|n-1\rangle## and the important identity: $$\langle \psi |\hat X |\phi \rangle = \langle \phi |\hat X^{\dagger} |\psi \rangle^*$$which applies for all vectors and operators. That leads to the required equation $$k^2 = n$$