To determine mass of a galaxy, we apply the same laws (Kepler's and Newton's) used in determine the mass of the Sun, binary stars, and our galaxy. We look at the ROTATION rate of gas or stars, as a function of radius for a galaxy. The speed of the stars tells us how much mass it is in orbit around. High speed = lots of mass.
What has been found in both ours and other galaxies is that stars are orbiting much faster than they should. The stars appear to be responding to a LOT more mass than we can see. Gravity does not lie. The matter IS THERE. Its just not emitting light. This material, whatever it is, is referred to as Dark Matter.