First, ionic compounds form bonds by transferring electrons from their outer shell. Covalent compounds form bonds by sharing electrons within their outer shell. The number of electrons in the outer shell of an elements atom is indicated by their group number in the periodic table (chlorine is group 7, oxygen group 6, sodium group 1) and a full outer shell contains 8 electrons (unless hydrogen or helium). When two (or more) elements bond together to form a compound, all the outer shells will be completely full or completely empty, either by transferring or sharing electrons. e.g. An ionic compound, such as calcium chloride: Calcium is in group 2, so it has 2 electrons on its outer shell Chlorine is in group 7, so it has 7 electrons on its outer shell.Calcium atoms want to get rid of two electrons, chlorine atoms only need one electron to complete their outer shell.So two chlorine atoms will be required to remove the two electrons from the calcium atomThe formula is CaCl2e.g. Covalent compound, such as carbon dioxide: Carbon is in group four so has four electrons on its outer shell Oxygen is in group 6 so has six electrons on its outer shell.Carbon requires four extra electrons, oxygen requires 2 per atom. Therefore, two oxygen atoms, both sharing two electrons of their own, plus two carbon electrons, will provide three complete outer shells.So the formula is CO2