The number of electrons in an atom is equal to the number of protons (Atomic number of an element)
Well for example take calcium, its atomic number is 20 (Electrons=protons)
we have 4 orbits (For begineers)
which are called k l m n
But forget about this for now,
in the first orbit the maximum number of electrons placed is 2
so,
2
in the second orbit it can take up to eight as well as the third and the fourth so it would be:
2 8 8 2
(Ran out of electrons to fill the 4th orbit(N)) When this atom gets in chemical reaction, it will lose 2 electrons and have a +2 above it so it has an outermost level shell (Valency electrons) = 8