An atom is stable when its outer energy level is filled with electrons
Atoms are made of protons and neutrons making up the nucleus and electrons orbiting in energy shells around the nucleus.
each energy shell has a maximum amount of electrons it can contain within the shell. outer energy level is the outermost energy level of the atom. the electrons that fill the outermost energy shell are called valence electrons.
Atoms that have incomplete energy shells where the shell doesn't contain the maximum number of electrons it can hold, then the atom tends to gain electrons from other atoms to completely fill the outer shell or donate the electrons in the outer shell so that the shell inner to the outermost shell becomes the new outermost energy shell which is already complete.
Once the outermost energy shell is complete, the atom is said to be stable.