A compound is a substance composed of two or more elements. Unlike a mixture, atoms of the elements are bound together in the compound's molecules. Compounds can be as simple as table salt, where a molecule consists of one atom of sodium and one of chlorine. Organic compounds -- those built around carbon atoms -- are often long, complex chains of individual atoms.
The first step in finding the formula for a given compound is finding out what elements it contains. For starters, a chemist looks at the compound and identifies its properties, such as weight, solidity, color and odor. Then she starts testing it, for example by burning samples, melting them or dissolving them in various fluids. This may take a while but eventually the results should enable her to identify the basic elements.
Learning that a compound contains, say, hydrogen, carbon, oxygen and iron doesn't tell you the formula. Trying to calculate the formula molecule by molecule isn't practical, so instead you take a large sample, say 100 grams. When you analyze the compound for component elements, your results should include the weight of the different elements in the 100 grams of compound. You use a mathematical formula to convert the number of grams into moles for each element, which allow you to compare apples with apples, when you're trying to determine how many atoms of each element are present.
Compounds come with two different formulas. The first is the empirical formula which shows you the number of different atoms in the compound. After you convert the grams of each element into moles, you calculate the ratio of the moles, which gives you the ratio of the elements in the compound. More number-crunching gives you the molecular formula. If the empirical formula is six carbon atoms to 11 hydrogen to one oxygen, the molecular formula might be 12 carbon, 22 hydrogen, two oxygen or some other multiple.
Even after getting the formula, you still don't truly know the compound. For that you need to figure the three-dimensional structure. Molecules can form as tetrahedrons, trigons or straight lines. Some compounds can only have one possible structure, given the elements they contain. Others require tests to figure it out, for example by replacing some of the atoms with atoms of another element and watching how reactions change. Two compounds with the same formula and different structures can have different properties.