As objects recede, the characteristic spectral lines of their elements (hydrogen, helium, etc.) are shifted toward to the lower, red, end of the color spectrum (whereas if approaching they shift toward the ultraviolet). Thus scientists measure the amount of this red shift to determine the receding speed and thus the distance, in light-years.
If you're really curious, do an internet search on "expanding universe," "red shift," "galactic distances," etc.
Of course this assumes the red shift is totally unaffected by whatever forces, known or unknown, exist in the path of the billions of light years traveled.