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