Finding a distance needs two things: how bright an object really is, and how bright it looks. Compare the distance that you get with the known size of the Milky Way to decide where the object belongs.
In the 1920s Hubble found Cepheid variable stars in the Andromeda nebula. What did this show?