In order to form bonds atoms need to be stable. An atom is stable when its outer shell is complete, which means when it has 2 or 8 electrons. Noble gases are very stable and do not react with other elements, because their outer shell is complete. You can see them on the far right (in grey) of the periodic table:
The atoms of the rest of the elements on the periodic table try to stabilise by filling their outer shell with some more electrons, or by getting rid of some extra ones. They get their electrons when they combine with other atoms of elements that need to get rid of some. When an atom loses electrons (which carry a negative charge), it becomes a positive ion. The atom receiving the electrons becomes a negative ion. The more electrons an atom receives, the bigger the negative charge and the more it loses, the bigger the positive charge.
Metals generally gain electrons because they have spaces in their outer shell that need to be filled, whereas non-metals give their spare electrons to metals. Positive and negative ions attract one another so the compound forms. Metal ions attract a number of other ions and form lattices. The diagram below shows the ionic bond between sodium and chlorine when they form sodium chloride.
Non-metals also form compounds together by sharing electrons. This type of bonding is covalent. The molecule of water is shown in the diagram below. The oxygen atom shares two electrons, one with each atom of hydrogen. The electrons are used by all atoms simultaneously.
In GCSE science, electrons are represented as dots or crosses and we will see examples of that in the questions. You may be asked to draw these diagrams in your exams.