Answer
For a given value of principal quantum number $n$, the the values of orbital quantum number $l$ are ranging from $0$ to $(n-1)$
For a given value of $l$, there are $(2l+1)$ possible values of magnetic quantum number $m_l$.
For each $m_l$, there are two possible values for the spin quantum number $m_s$ (spin up and spin down).
Thus, there are $2(2l+1)$ states for each value of $l$.
$\therefore$ Total number for given $n$ is
$N=\sum_0^{(n-1)}2(2l+1)$
or, $N=2\sum_0^{(n-1)}(2l+1)$
$N=2\Big [2\sum_0^{(n-1)}l+\sum_0^{(n-1)}1\Big]$
$N=2\Big [2\times\frac{n(n-1)}{2}+n\Big]$
$N=2\Big [n^2-n+n\Big]$
$N=2n^2$
Work Step by Step
For a given value of principal quantum number $n$, the the values of orbital quantum number $l$ are ranging from $0$ to $(n-1)$
For a given value of $l$, there are $(2l+1)$ possible values of magnetic quantum number $m_l$.
For each $m_l$, there are two possible values for the spin quantum number $m_s$ (spin up and spin down).
Thus, there are $2(2l+1)$ states for each value of $l$.
$\therefore$ Total number for given $n$ is
$N=\sum_0^{(n-1)}2(2l+1)$
or, $N=2\sum_0^{(n-1)}(2l+1)$
$N=2\Big [2\sum_0^{(n-1)}l+\sum_0^{(n-1)}1\Big]$
$N=2\Big [2\times\frac{n(n-1)}{2}+n\Big]$
$N=2\Big [n^2-n+n\Big]$
$N=2n^2$