For elements in the first period of the periodic table (hydrogen and helium), a full outer shell contains two electrons. Hydrogen has one electron and is most stable when it gains one more electron to fill its outer shell. Helium has two electrons and is already stable with a full outer shell.
For elements in the second period of the periodic table (lithium through neon), a full outer shell contains eight electrons. Lithium has one valence electron and is most stable when it loses one electron to achieve a full outer shell. Beryllium has two valence electrons and is most stable when it loses two electrons to achieve a full outer shell. Boron has three valence electrons and is most stable when it loses three electrons to achieve a full outer shell, and so on, until neon, which has a full outer shell with eight electrons and is therefore stable.
For elements in the third period of the periodic table (sodium through argon), a full outer shell also contains eight electrons. The pattern of gaining or losing electrons to achieve a full outer shell continues, with sodium having one valence electron and being most stable when it loses one electron, magnesium having two valence electrons and being most stable when it loses two electrons, and so on, until argon, which has a full outer shell with eight electrons and is therefore stable.
This pattern continues for elements in subsequent periods of the periodic table, with the number of valence electrons required for a full outer shell increasing as the atomic number increases. The noble gases (group 18 elements), which have a full outer shell with eight electrons (except for helium, which has two), are the most stable elements and do not tend to react with other elements.