When atoms react, they tend to achieve an outer shell having eight electrons. Many of the representative elements (sodium and chlorine for instance) follow this rule when they form ions. In the ionic case they achieve the noble gas shell configuration by either a gain or loss of electrons.