The number of molecules in a liter depends on the substance, its density and its atomic mass. If the substance is a gas, the density is affected by temperature and pressure.
If calculating the number of water molecules in a liter of liquid water, one can use the density of 1 gram/milliliter, or 1000 grams/liter, to perform the calculation. The atomic mass of water is 18 grams per mole. Therefore, one liter of water contains 1000 grams * (1 mole / 18 grams) = 55.56 moles of water. Because there are 6.022 * 10^23 molecules in a mole, the number of molecules of water in a liter is (6.022 * 10^23) * 55.56 = approximately 3.345 * 10^25 molecules of water.
According to the Ideal Gas Law, 1 mole of any ideal gas at STP, or standard temperature and pressure, takes up 22.4 liters of space. Therefore, at STP, 6.022 * 10^23 molecules take up 22.4 liters of space. This means that one liter of an ideal gas at STP contains (6.022 * 10^23) / 22.4 = approximately 2.688 * 10^22 molecules.