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.

There is no direct method currently available to measure the distance to further stars, 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 out 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 determine the star's actual brightness. By knowing the actual brightness and comparing it to the apparent brightness seen on 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.

The following link is helpful: Parallax