Atoms form ions so that they have a full outer shell, the same electronic configuration as a noble gas. Metals in Groups 1 and 2 lose their outer electrons and form positive ions. Non-metals in Groups 6 and 7 gain electrons and form negative ions. The group number tells you how many electrons are involved.
Group 1 atoms lose one electron and form ions with a 1+ charge. Group 2 atoms lose two electrons and form ions with a 2+ charge. Calcium is 2.8.8.2. It loses its two outer electrons and becomes a calcium ion with the configuration 2.8.8 and a 2+ charge.
Group 7 atoms gain one electron and form ions with a 1- charge. Group 6 atoms gain two electrons and form ions with a 2- charge. Oxygen is 2.6. It gains two electrons and becomes an oxide ion with the configuration 2.8 and a 2- charge. Chlorine is 2.8.7. It gains one electron and becomes a chloride ion with the configuration 2.8.8. The total positive charge in an ionic compound equals the total negative charge, so calcium chloride needs two chloride ions for each calcium ion.