The number operator is defined as

N^=a^†a^\boxed{\hat{N}=\hat{a}^\dagger\hat{a}}

where a^\hat{a} is the lowering/annihilation operator and a^†\hat{a}^\dagger is the raising/creation operator Note the commutations

[H^,a^]=ℏω [a^†a^,a^]=ℏω [a^†,a^] a^=−ℏω a^[\hat{H}, \hat{a}] = \hbar\omega\,[\hat{a}^\dagger\hat{a}, \hat{a}] = \hbar\omega\,[\hat{a}^\dagger, \hat{a}]\,\hat{a} = -\hbar\omega\,\hat{a}

and

[H^,a^†]=+ℏω a^†[\hat{H}, \hat{a}^\dagger] = +\hbar\omega\,\hat{a}^\dagger