What is the formula of finding mass of molecules?

In principle, since due to relativity effects the energy stored in bonds inside the molecule contributes to the total molecular mass, to obtain a very accurate determination of the mass of a molecule the sum of the mass of the particles (protons, neutrons and electrons) calculated as if the particles would be insulated should be corrected for the effect of the chemical bonds. In order to do that a quantum representation of the molecule is needed.

However this accuracy is rarely needed, the greatest number of times the mass M of the molecule is determined by adding the masses of the particles composing the molecule evaluated as if they were insulated: that is the following formula is used

M= Mp Np + Mn Nn + Me Ne

where Mp Mn Me are the masses of insulated protons, neutrons and electrons respectively and Np Nn Ne are the number of such particles composing the molecule.

If a first approximation is needed, the electronic term can be also neglected, due to the small mass of electrons with respect to the protons and neutrons.

The above equation requires to compute the number of protons, neutrons and electrons composing each element (atom or ion) of the molecule. If we know the mass of each of those elements, we can replace the above equation with the sum of the mass of every element composing the molecule. In doing it however care has to be taken in not confusing similar entities with different masses, like isotopes or ions and neutral atoms.