What you are looking at
Each atom is drawn as a Bohr model: a nucleus with its electrons on rings (shells). Electrons that start on the metal atom are crosses and those that start on the non-metal atom are dots, so you can follow every electron that moves. Press Transfer electrons and the outer electrons cross over one at a time. The ions then appear in square brackets with their charges, and finally they pull together. Turn the view by dragging the stage, or switch to the flat, exam-style drawing with 2D.
Electrons move across
A sodium atom (2,8,1) has one electron in its outer shell, while a chlorine atom (2,8,7) is one short of eight. When they react, that single electron moves from sodium to chlorine. Sodium is left as 2,8 and chlorine becomes 2,8,8, so both ions have the arrangement of a noble gas:
The ions are not neutral any more. The sodium ion keeps its 11 protons yet holds just 10 electrons, giving a charge of 1+, written Na⁺. Chlorine ends with 17 protons and 18 electrons: Cl⁻.
Charges from the group
You can read the charge from the periodic table. Metals in Group 1 lose one electron and form 1+ ions, Group 2 metals form 2+ ions, non-metals in Group 6 gain two electrons to form 2− ions, and Group 7 non-metals form 1− ions. Aluminium in Group 3 forms Al³⁺, which some courses leave out. The sim tags each compound with where it sits in your course.
Formulae from charges
Every electron one atom loses is gained by another, so the total charge must be zero. In calcium chloride one Ca²⁺ needs two Cl⁻, so in the sim each calcium atom passes one electron to the chlorine on its left and one to the chlorine on its right:
The Formula card adds up the charges for you, such as +2 + 2 × (−1) = 0 for CaCl₂, or 2 × (+3) + 3 × (−2) = 0 for Al₂O₃. To find a formula yourself, pick the smallest numbers of each ion that make the charges cancel.
From ions to a giant lattice
What holds the ions together is the electrostatic pull between opposite charges, and that pull acts in every direction. So the ions do not pair off: each one gathers oppositely charged ions all around it. For sodium chloride the sim ends with a small block of 4 Na⁺ and 4 Cl⁻, still a 1 : 1 ratio. Lithium fluoride, potassium chloride, magnesium oxide and calcium oxide have the same arrangement. The other compounds pack differently, so only one formula unit is drawn for them. Ion sizes in the block are in proportion to their measured radii: a chloride ion is much bigger than a sodium ion.
Common mistakes
To see how the shells fill and why each atom forms the ion it does, try the electron shells in 3D simulation. The full sodium chloride lattice, and why it conducts only when molten or dissolved, is in the giant structures in 3D simulation. For atoms that share electrons instead, see the covalent molecules in 3D simulation.