For example, in iron sulfide every iron atom is joined to one sulfur atom, so we show its formula as FeS. In sodium oxide, there are two sodium atoms for every oxygen atom, so we show its formula as Na2O. Notice that the '2' is written as a subscript, so Na2O would be wrong.
This diagram shows that one carbon atom and two oxygen atoms combine to make up the units of carbon dioxide. Its chemical formula is written as CO2.
Sometimes you see more complex formulae such as Na2SO4 and Fe(OH)3 :