They can estimate the distance by a couple methods. For some objects, they can use the principle of parralax, basically, taking measurements when the Earth is at one end of its orbit, and then comparing to when we are at the other end of the orbit in order to get a triangulation. If that doesn’t work, they usually rely on the redshift values of the star and any objects in front of or behind it to get an estimation. The redshift value tells them how fast the star is moving away from us, and from that try to estimate the distance.
Thanks, Boogieman. But my mind is still boggling. It seems to me that there is a line where knowledge ends and guessing begins. Educated guesses, mind you, but guesses nonetheless.