Actually, that shell model of 2, 8, 18 etc. is only a summary of what is going on, and I'm afraid the real picture is a bit more complicated. The populations of electron shells stem from a phenomenon in quantum mechanics known as the Pauli Exclusion Principle, which says that two fermions (a type of particle that includes electrons) cannot share the same energy state unless they have different spins. Only two different spins are possible, so only two electrons can occupy one state. We also need to consider a property of the electrons in an atom called orbital angular momentum ##l##, and the z-component of orbital angular momentum, denoted ##m_l##.
In the first shell, ##l = 0##, and quantum mechanics says that ##m_l = 0## also. The energy states are labelled by the values of ##m_l##, so as we only have one value of ##m_l## here, that means one energy state and so from the exclusion principle we have two electrons in the first shell.
In the second shell, ##l = 1##, and quantum mechanics gives us ##m_l = -1, 0, 1##. So now we have 3 values of ##m_l##, and therefore 3 energy states. As before, we put two electrons in each state, giving six in this shell.
For the third shell, ##l=2## and ##m_l = -2, -1, 0, 1, 2##; perhaps now you can see the pattern. This means we have 5 energy states, so 10 electrons in total for this shell if we put two in each state.
As you can see, the picture derived from quantum mechanics looks a bit more complicated than the first model, but it doesn't mean you should throw your model away. I will now introduce a quantity ##n##, known as the principal quantum number. It is a positive integer, related to ##l## by ##l < n##, where ##l## is also an integer as we see above. The lowest value of ##n## is 1, and this corresponds to the lowest value of ##l## i.e. ##0##. As there are only two electrons corresponding to this value, this gives us the 2 electrons in the first shell as predicted by the more basic model.
Next, we have ##n = 2##, but we see from the relation with ##l## that this means ##l = 0## and ##l = 1## are both allowed for this value of ##n##. This means that in addition to the 3 states (and therefore 6 electrons) coming from ##l = 1##, we can have another two electrons in a second ##l = 0## state. Putting these together, we get
2 + 6 = 8 electrons in the next shell, agreeing with the simpler model.
Moving up to ##n = 3##, ##l = 0, 1, 2##, so you now get two electrons from ##l = 0##, six electrons from ##l = 1## and ten electrons from ##l = 2##. Put these together and you have 18 electrons in this shell, again in agreement with the simpler model.
I hope I've managed to explain this clearly enough, but if it all seems a bit daunting, the simple model works fine, and you may just have to wait until you learn quantum mechanics
