A chemical formula is an expression that denotes the number and types of atoms present in a molecule of a substance. It is a representation of the composition of a molecule, in terms of the elements present, using their symbols.
For example: O2 is the chemical formula of the element oxygen. Therefore, one molecule of oxygen comprises two atoms.
CO2 is the chemical formula of the compound carbon dioxide. It consists of one atom of carbon and two atoms of oxygen.