How do you calculate the distance between earth and a star?
distance to nearest stars are measured by a method called Parallax
Stars far away than that can not be measured by parallax is measured by principle of standard candles...Cepheid variables are used as standard candles.
For more distant galaxies Type ! a supernova is used as standard candles. We know that the radiation gets its strength reduced as distance increases by square root relationship.