It turns out that measuring the distance to a star is an interesting problem! Astronomers have come up with two different techniques to estimate how far away any given star is.
The first technique uses triangulation (a.k.a. parallax). The Earth’s orbit around the sun has a diameter of about 186 million miles (300 million kilometers). By looking at a star one day and then looking at it again 6 months later, an astronomer can see a difference in the viewing angle for the star. With a little trigonometry, the different angles yield a distance. This technique works for stars within about 400 light years of earth. (For details on triangulation, check out How GPS Receivers Work.)
There is no direct method currently available to measure the distance to stars farther than 400 light years from Earth, so astronomers instead use brightness measurements. It turns out that a star’s color spectrum is a good indication of its actual brightness. The relationship between color and brightness was proven using the several thousand stars close enough to earth to have their distances measured directly. Astronomers can therefore look at a distant star and determine its color spectrum. From the color, they can determine the star’s actual brightness. By knowing the actual brightness and comparing it to the apparent brightness seen from Earth (that is, by looking at how dim the star has become once its light reaches Earth), they can determine the distance to the star. Despite of all these, there is no unit that is constant and we can trust, even light turned out to cheat us due to the effect of spacetime distortions(which seemed to be a solid theory by Einstein but fails in utterly chaotic places of universe). sigh, living in world full of speculations. .