The 2 subscript used for diatomic oxygen, or #O_2#, represents the number of oxygen atoms that combine to form that molecule.
In other words, you need two oxygen atoms to form one oxygen molecule.
Because two oxygen atoms are used to form one oxygen molecule, the molar mass of the molecule will be twice that of an individual oxygen atom.
There is a very important distinction to be made between molecules and compounds. A molecule consists of two or more atoms that can either be identical or distinct.
Compounds, on the other hand, are substances comprised of two or more elements, or atoms, that cannot be all identical.
For example, something like #O_2# is a molecule because it has two or more oxygen atoms, but it is not a compound because those atoms are both oxygen.
By comparison, water, or #H_2O#, is a molecule because it has three atoms bonded together, and it is a compound because those elements are not all the same (one oxygen and two hydrogens).
So, #Cl_2#, #Br_2#, #H_2#, and so on are molecules but not compounds, while substances like #HCl#, #H_2O#, #CO_2# are both molecules and compounds.