This video nicely explains your question.
The essence is that paulis exclusion principle states that two electrons(or generally fermions) cannot occupy the same quantum state.
This is because electrons are fundamentally indistinguishable,but their wavefunctions are not. So there must be some quantum factors which allows to distinguish between their quantum states. In general we say that quantum properties of electrons can be conveyed by some numbers which we call the quantum numbers of that electron.
The distinguishablity in the first shell electrons is assured by spin quantum number. They can have $+1/2$ or $-1/2$ spin. So, there are 2 electrons in the first shell. But in the second shell,there are additional quantum numbers like azimuthal quantum number and magnetic quantum number, that can vary which allows for upto 8 electons in a single shell.
So,why are 8 electrons stable? because the protons and electrons attract each other.so,the atom in which all electrons are maximum filled is the most stable system.