It's a matter of quantum numbers: the Pauli exclusion principle tells us that no two electrons can have the same quantum numbers. As there are four of them (n,l,m,m
s) in each orbital we'll only find two of them with different spin quantum numbers (m
s, whose conventional values are +1/2 and -1/2).
Just a brief overview on the meanings of the quantum numbers: n is the so-called "principal quantum number" and tells us the energy level of the electron, the energy of our electron can be roughly exstimated comparing the E=l+n values of different orbitals. l tells us the different "shapes" of the orbitals and its values go from 0 to n-1 (e.g. for n=4 we'll have 0 (s orbitals) 1 (p orbitals) 2 (d orbitals) 3 (f orbitals)). m is the number which provides information about the different directions of the orbitals and goes from -l to +l (e.g. for l=2 (d orbitals) m=-2,-1,0,1,2: five orbitals so 10 electrons in the d-sublevel). The spin quantum number is the orientation of the electron's rotation and it's usually represented with small arrows pointing up or down when we write the Aufbau (or electronic configuration) of the atom.
Now you can easily understand why in the first level we'll only have 2 electrons (n=1, l=0, m=0, m
s=±1/2) while in the second one there are 8 of them (2 in the s-sublevel (the same reasoning I used with n=1) and 6 (n=2, l=1, m=-1,0,+1) in the p-sublevel).
There is also a general rule that tells us the total number of electrons in the first n levels (N=2n
2), which you can try to demonstrate as an exercise. Here is a sort of demonstration for all who are interested in it.
For a generic level we can write:
So if we want to find the sum of the electrons in the first N levels we'll have to write:
Using the known relation (easily demonstrated too using induction principle):
we get: