Here's how to calculate it:
1. Gather information:
You'll need the mass of each element present in the compound. This information can be obtained from:

Mass spectrometry data

Elemental analysis (percent composition by mass)
2. Convert mass to moles:
Use the periodic table to find the atomic mass of each element. Then, divide the mass of each element by its atomic mass to convert it into moles.
3. Find the lowest common denominator:
Divide each mole value by the smallest number of moles obtained in step 2. This gives you a preliminary ratio of atoms in the compound.
4. Convert to whole numbers (subscripts):
Ideally, the values from step 3 will be whole numbers. If not, find the smallest whole number multiplier that will convert all the values to whole numbers (round to nearest whole number). Multiply the preliminary ratio you obtained in step 3 by this whole number multiplier.
5. Write the empirical formula:
The final whole numbers you obtained in step 4 represent the subscripts in the empirical formula. Use the element symbols and their corresponding subscripts to write the empirical formula.
Example:
Let's say you have a compound where you measured 1.2 grams of carbon, 0.2 grams of hydrogen, and 1.6 grams of oxygen.
Solution:

Convert mass to moles:

Carbon: 1.2 g / 12.01 g/mol = 0.1 mol

Hydrogen: 0.2 g / 1.01 g/mol = 0.2 mol

Oxygen: 1.6 g / 16.00 g/mol = 0.1 mol

Find the lowest common denominator:

Divide each mole value by 0.1 mol (smallest number of moles):

Carbon: 0.1 mol / 0.1 mol = 1

Hydrogen: 0.2 mol / 0.1 mol = 2

Oxygen: 0.1 mol / 0.1 mol = 1

Convert to whole numbers:

The values (1, 2, 1) are already whole numbers, so no multiplier is needed.

Write the empirical formula:

The empirical formula is CHâ‚‚O