Ionic compounds are different from ionic-bonded atoms.
As normal ionicly bonded atoms, they will lose their electrons and another element will gain them, causing the two atoms to be electrostatically attracted to each other. However, ionic compounds, have more than two atoms bonded together.
When this happens, the atoms will form in a sort of checkerboard pattern. If many atoms bond like this, the compound will be cube-shaped, which we named 'regular lattice structures." These structures will often be drawn or depicted as the cube shape. Still, with small spheres on its surfaces, another way we can depict this is we use a diagram named the "ball and stick diagram", which are similar but they instead draw or model each atom connected via a stick.
Something interesting about ionic compounds is that they have very high melting and boiling points, and they can conduct electricity, but most of the time we have to dissolve them in water or melt them down for electric conductivity, like putting salt in water to make the water more conductive, but what matters is the amount of charged particles
The boiling and melting points change depending on the strength of the bonds of atoms held together, and if the bonds in ionic compounds are very strong, more energy is required to break apart the bonds.
But if you want the ionic compound to conduct electricity, it first needs to have charged particles, if you take any solid it will be tough because all the bonds are stagnant, but if it melted or dissolved then the ions in the solid are free to move and conduct.
In ionic compounds, one element would have to lose and one would have to gain an electron, for example, if you wish to write aa Sodium bonding with a Chlorine atom, which the Sodium has a +1 charge while the Chlorine has a -1 charge.
So to have them bond, the Sodium would lose the electron while the Chlorine would gain one, thus, you would write this equation as NaCl+.
But what happens if the atoms need more electrons to bond, what about Magnesium and Chloride, Magnesium needs to lose 2 electrons since it is in group 2 of the periodic table.
So the Magnesium loses 2 electrons to be a 2+ ion, then we need to balance it out, so we must take two Chlorine ions since one ion is only a -1, so if we were to write this out it would be MgCl2.
Complex compounds like Calcium Hydroxide or Aluminium Sulfate are, more complicated as these ions aren't single elements so their atomic numbers or electron amounts are not on the table.
Instead, we will have to memorise it, for the Calcium Hydroxide is OH-, while the Aluminium Sulfate is SO42-.
Now we can look at the elements by themselves, Calcium is group 2 of the periodic table which means that Calcium or Ca has a +2 charge, while hydrogen is a -1 charge.
Similar to the Chlorine atom, a single Hydroxide has a -1 charge, which means we need to put two of them in the CaOH- equation instead of one, the written formula for this is:
Ca(OH)2.
The reason why we put the 2 outside the brackets is because it means whatever is inside the brackets there is 2 of them.
Now to tackle the Aluminium Sulfate, the Aluminium has a +3 charge, while the Sulfide ion has a -2 charge, this makes it a little bit more complicated because when two compounds bond they need to have the same amount of electrons.
But the problem is we can't add another electron to the Sulfate, in order for this to work we would need to first find the lowest multiple of both of the charges, which 3*2 is 6, so six is the smallest multiple we can find.
So in order for this to work out we need 3 * 2 to get us 6, which we will take two Aluminium both of which are +3 charge, and three Sulfate ions, which means we have our 3 * 2.
So we would write this as: Al2(SO4)3.
That's how we would write it, as we need 2 Al atoms the smaller scale 2 is there, then there is the SO4, which means the chemical writing for Sulfide, then the small 3 at the end means that there are three of the Sulfate ions.
Other ionically bonded compounds are: NO3- for a Nitrate ion, a carbonate ion which is CO3^2-, and lastly is the Ammonium ion which is NH4+.