To calculate the empirical formula, convert mass composition to moles by dividing by the elements' molar masses, then divide by the smallest mole number to get a simple whole-number ratio. For the molecular formula, divide the compound's molar mass by the empirical formula mass, then multiply the empirical formula by this ratio.