An ionic bond forms between a metal atom and a non-metal atom when electrons are transferred from one atom to the other. The metal atom loses its outer electrons and becomes a positively charged ion called a cation. The non-metal atom gains those electrons and becomes a negatively charged ion called an anion. Each ion ends up with a full outer shell, like a noble gas.
In sodium chloride, a sodium atom (2.8.1) transfers its one outer electron to a chlorine atom (2.8.7). The sodium ion has the configuration 2.8 and the chloride ion has 2.8.8. The oppositely charged ions attract each other strongly, and this electrostatic attraction is the ionic bond. In magnesium oxide, a magnesium atom (2.8.2) transfers two electrons to an oxygen atom (2.6), so the ions are Mg2+ and O2-.
A dot and cross diagram shows only the outer shells. The electrons from one atom are drawn as dots and the electrons from the other atom are drawn as crosses, so you can see where each electron came from. After the transfer, each ion is drawn inside square brackets with its charge at the top right.