The trivial answer to this question would be : If you know the molecular formula, that tells you how many atoms of each element there are. So, water (H2O) has 2 hydrogen (H) atoms and 1 oxygen (O) atom.
Now let's assume you do not know the molecular formula, and only know that the compond is called, say, magnesium chloride. The way to figure the number of atoms in a molecule of this compound is through the valencies of its elements. The valency is the number of electrons in the outermost shell of the atom. It is these outer (valence) electrons which are responsible for forming the chemical bonds between the atoms. Magnesium (Mg) has a valency of +2. This means that it has 2 electrons in its outer shell. Chlorine (Cl) has a valency of -1. This means that it is one electron short of a fully filled outer shell. Both atoms would like to have fully filled outer shells. The easiest way for Mg to achieve this is by getting rid of it's 2 excess electrons. Clearly Cl needs just one electron to be happy. So the answer would be for Mg to find a pair of Cl atoms to give each of them one of its excess electrons. So the molecule formed between Mg and Cl will be MgCl2.
The shortcut way to figure this out is as follows:
1. Write down the element sybols followed by their valencies in brackets; forget about the +/- signs,
2. Exchange these numbers between the elements, and remove the brackets
3. Reduce to the simplest ratio.
Lets do a few examples :
Mg(2)Cl(1) ---->Mg1Cl2---->MgCl2 (the 1 is not explicitly written down)
Al(3)O(2) ----->Al2O3 , done.
C(4)O(2) ----->C2O4 ----->simplify to CO2 by dividing by 2.
Some elements exhibit more than one valency, and it's a little tricky to figure out which valency it will exhibit when. This usually depends on how the compound is made.
When such a compound is named, the correct valency that is exhibited is also mentioned to remove doubt. For instance, Iron (Fe) can have a valency of +2 or +3. The lower valency is indicated by attaching an -ous ending to the latin name and the higher valency, by an -ic ending. So Fe(2) is called ferrous while Fe(3) is called ferric.
There's a nice bit on valency here, if you scroll down some : http://www.jghs.edin.sch.uk/mathscience/chemistrynotes/topic4.html [Broken]
Do try the other compounds to get the hang of it.
EDITED to add : Also, the above discussion was essentially for inorganic compounds. There's a whole new bag of rules and tricks in naming and understanding organic compounds such as 1-methyl-2-(3-pyridyl)pyrrolidine.
Thanks, Gokul43201. I knew about the valency (except that it had to do with the electrons, that makes sense), just not how to read it from a periodic table, with the columns the elements are in. (I'm sure a good periodic table tells you the valency or something, but I didn't have one of those at my chemistry test.) The site you linked to explained that. Thanks.
That's a good question by Monique. I can't really imagine. Does anyone know?
If you get to learn more chemistry, you will be taught things like salt analysis, where you will learn to do just this. Basically, you utilize your knowledge of the various reactions between known substances, as well as properties like solubility, emission spectra (flame tests) and color to determine what the unknown substance is.
That still doesn't address how you figure out what what the individual atoms are in a molecule, you are just identifying the substance.
Sure, you can take the white substance and if it's sweet you say it's glucose: C6H12O6 and when it's salty you say it's table salt: NaCl. But how are you going determine that a glucose molecule is composed of six carbon atoms, twelve hydrogen atoms and six oxygen atoms..
How in Dimitri Mendeleev's time did they know the atomic mass of the elements?
You could dissolve the solution and electroylsis it. Then do the necessary test on the gases to see what is realised (e.g. hydrogen to a flame goes pop). They had fire in Dmitri's day. Also electroylsisation was happening before Dmitir was thinking of the Periodic Table.
The remaining substance could be tested with universal indicator (made from iodine) to see what the pH was and then determine the element or simply oxidise it and then see what elements displace it.
Then by knowing the elements you can assume the charges for the attractions and the bonding and make the chemical formula for the compound.