For nearby stars, a method called
Parallax is used to see how nearby stars are moving as compared to the stars behind them. You have experienced this when you are travelling in a car or train. As you move forward, the houses near to the vehicle goes behind faster. But the houses at a distance seems to go behind slowly. This is how parallax looks like:
For much more distant stars, standard candles are used. If we know the luminosity we can calculate distance.
For most distant stars Type Ia supernovae is used. Please read this detailed article.