Stellar mass determination is most accurately determined for eclipsing binaries, if one of the pair's whose orbital velocity can be determined by astrometry and/or the Doppler effects of the radial velocity. From the velocity (or directly by astrometry), the size of the orbit can be determined, and once the period of the orbit is determined, the total mass can be determined, by Kepler's observations and Newton's theory of gravity:
R³ M ∝ —— P²
The Doppler shifts due to the radial velocity are affected by the angle at which the orbit is being viewed, but if the binary is eclipsing, the angle is pretty clear.
The masses of the individual stars can be determined if the center of mass can be determined through astrometry. In some cases, one star is much larger than the other and the derived total mass is a good first approximation of the mass of the heavier star.
Once masses of some nearby stars have been determined, relationships involving mass, luminosity, spectral type, and the H-R diagram allow the masses of other stars to be estimated.