To know that, you need to learn quantum mechanics a little bit. Sub-shells are orbitals, determined by quantum numbers in Schrodinger's equations. n is the principal quantum number that determines the shell. l has something to do with angular momentum, m is the magnetic angular quantum number.
In general, l must be less than n, while m must be equal to or less than l. In the first shell n=1 as it is the first shell, l only =0. In the second shell where n=2, l=0 or 1, so m=+1 or -1 or 0. For each set of parameters there is one orbital and in one orbital there are two electrons. Thus in first shell there is only on orbital possible, thus 2 electrons.
I hope this would help you with your question.