It just depend on the definition of the number operator. In a Hilbert space H, one starts from the algebra [a,a∗]=1
for a pair of operators
a,a∗ defined in some invariant domain
D⊂H also assuming that there is a unique vector, in
D, denoted by
|0⟩ such that
a|0⟩=0.
Only exploitong (i) the commutation rules above, (ii) the definition of |0⟩ and (iii) the fact that a∗ is the adjoint of a, at least when working in D, one easily sees that D must contains an infinite orthonormal set of vectors of the form
|n⟩:=(a∗)n√n!|0⟩n=0,1,2,…
n here just denotes how many times a∗ acts on |0⟩ in the formula above to produce |n⟩ up to normalization coefficients.
From the given definition, it turns out that
a|n⟩=√n|n−1⟩anda∗|n⟩=√n+1|n+1⟩.
The meaning of that n depends on physical context. In elementary QM, this machinery is used to compute the spectrum of the Hamiltonian operator of the harmonic oscillator. In that case n denotes an eigenvalue and En=ℏω(n+12). In QFT there is a more sophisticated construction and, in fact np denotes the number of particles with a certain value of the four momentum p and there are operatores ap,a∗p for each p. (This construction, in QFT, can be readapted to a generic state not necessarily with defined momentum and relies upon the notion of Fock-Hilbert space space.)
The number operator N is just defined as the operator such that N|n⟩=n|n⟩
whatever is the meaning of
n. As the vectors
|n⟩ form a Hilbert basis in
H (or in a closed subspace which can be considered the true physical Hilbert space of the system),
N turns out to be self-adjoint with pure point spectrum and thus is a proper quantum observable whose (eigen)values are the numbers
n.
Using the commutation rules of a and a∗ as well as the definition of |0> one easily sees that N|n⟩=a∗a|n⟩.
In fact a∗a|n⟩=a∗√n|n−1⟩=√na∗|n−1⟩=√n√(n−1)+1|(n−1)+1⟩=n|n⟩
=N|n⟩.
Since the vectors |n⟩ form a basis, essentially by linearity, we can equivalently write N=a∗a.