Every bright star and galaxy is mostly made up of hydrogen. But hydrogen emits and absorbs light at very specific (electro-magnetic frequencies or colors), which together make up a pattern.
Here's the pattern ...
1. ... when hydrogen is in a stationary container, as measured in a lab.
2. ... when hydrogen is that of a nearby star moving away.
3. ... when hydrogen is that of a galaxy moving away faster.
4. ... when hydrogen is that of a galaxy moving away even faster.
5. ... when hydrogen is that of a quasar, moving away even faster.
It's the same pattern in all cases, and therefore hydrogen, except that the pattern is shifted to the right when the star is moving away fast.
In space, galaxies that are moving away faster are also further away, and the relationships between shift, speed and distance are known. So once an amount of shift (redshift) is known, so is the speed and distance of the star or galaxy made up of that hydrogen.