Calcium and chlorine react to form the ionic compound calcium chloride, which has the formula `CaCl_2` .
Calcium loses two electrons, forming the cation `Ca^(2+)` and each chlorine atom gains one electron, forming the anion `Cl^-` . Positive ions are called cations and negative ions are called anions. When an element loses electrons to form an anion the ending of the name is changed to -ide, which is why the compound is named calcium chloride and not calcium chorine.
The formula is based on the fact that ionic compounds are neutral, or have an equal amount of positive and negative charge. Since the calcium ion has two positive charges and the chlorine ion has one negative charge, the formula `CaCl_2` results in two positive and two negative charges for a net charge of zero.
Now let's look at why calcium loses two electrons and chlorine gains one. When elements react to form compounds, they gain, lose or share electrons to achieve the same number of valence (outer) electrons as a noble gas. This is called the Octet Rule, because all noble gases except helium have eight outer electrons. Helium only has two. Noble gases are stable (don't react easily) because they have a complete outer energy level of electrons. Calcium atoms have 20 electrons of which two are valence electrons. When a calcium atom loses two electrons it ends up with the same number of electrons as argon, which is a stable noble gas. Chlorine has 17 electrons of which 7 are valence electrons. When in gains one electron it also has the same number as argon.
Here's the pattern for ions formed by main group elements according to the Octet Rule:
Group 1A elements have one valence electron which they lose to form +1 ions.
Group 2A elements have two valence electrons and form +2 ions.
B and Al in Group 3A have three valence electrons and form +3 ions.
Elements in the carbon family form molecular (covalently bonded) compounds more often that ionic compounds..
Elements in Group 5A, the nitrogen family, have five valence electrons and gain three to form -3 ions.
Elements in Group 6A, the oxygen family, have six valence electrons and gain 2 two to form -2 ions.
Elements in Group 7A, the halogens, have seven valence electrons and gain one to from -1 ions.
Group 8A, the noble gases, are stable and don't form ions.