So yeah, one has in the number basis that the annihilator can be expressed as
$$ a = \sum_{k} \sqrt{k} ~|k-1\rangle\langle k|$$
The sum here just means that this covers all of your basis states. For a fermionic annihilator the basis is $|0\rangle,|1\rangle$ and this is the fantastically simple operator $a = |0\rangle\langle1|,$ but for bosons the sum goes from 0 to infinity we need this bigger idea of $|0\rangle\langle1| + \sqrt2 ~|1\rangle\langle 2| + \sqrt3 ~|2\rangle\langle3|\dots$.
This can kind of be looked at as a definition. If it were me I probably would not have been smart enough to use $\sqrt{k}$ and I would not have unlocked the great power of creation and annihilation operators!
Combined with the orthogonality property, $$\langle a |b\rangle = \begin{cases} 1& \text{if }a=b,\ 0&\text{otherwise} \end{cases}$$ we can see that $$a^\dagger a = \sum_{k\ell}\sqrt{k\ell}|k\rangle\langle k-1|\ell-1\rangle\langle\ell| = \sum_k \sqrt{k^2} ~|k\rangle\langle k |$$which as long as $k$ is nonnegative in the basis so that $\sqrt{k^2} = k,$ we recognize as the number operator $\hat n.$ Meanwhile the opposite is, $$ a a^\dagger = \sum_{k\ell}\sqrt{k\ell}|k-1\rangle\langle k|\ell\rangle\langle\ell-1| = \sum_k \sqrt{k^2} ~|k-1\rangle\langle k-1 |$$After renumbering we can identify this for bosons (number basis goes zero to infinity) as $\hat n + 1$, or for fermions (zero or one) as $|0\rangle\langle 0|$ which you could call $1 - \hat n$ as $\hat n = |1\rangle\langle 1|$ while the identity matrix $1=|0\rangle\langle0|+|1\rangle\langle1|.$ So eliminating the $\hat n$ the genius of the choice $\sqrt{k}$ was that we get the (anti-)commutation relations,$$ \begin{align} a a^\dagger - a^\dagger a &= \big[a, a^\dagger\big] ~= 1 &\text{ (bosons)},\ a a^\dagger + a^\dagger a &= \big{a, a^\dagger\big}=1 &\text{ (fermions)}. 66
\end{align} $$ The genius of the harmonic oscillator derivations, is surprisingly generic and applies even without the harmonic oscillator Hamiltonian. It is to recognize the boson case inside the canonical commutation relation,$$[\hat x, \hat p/\hbar] = i.$$The idea is that if I take a leap to form the non-Hermitian $\hat q = \hat x + i \hat p/\hbar$ then going through the motions I will find $$\big[\hat q, \hat q^\dagger\big] = [i\hat p/\hbar, \hat x] + [\hat x, -i\hat p/\hbar] = 2,$$ thus I can treat $\hat q/\sqrt{2}$ as a bosonic annihilator. Well, that does not precisely work because it turns out that the sum $\hat x + i \hat p/\hbar$ is invalid, the units are inconsistent. But this is a very small problem, if I have some length scale $\lambda$ that I take as conventional, then I can use the dimensionless configuration just fine, $$a = \frac{1}{\sqrt 2\lambda} \hat x + i \frac{\lambda}{\sqrt 2 \hbar} \hat p. 976