There are three systems of measurement used, depending on distance.
First, the nearest stars can be determined by use of parallax – the shift in their positions over six months, during which the earth moves to the opposite end of a baseline of 186,000,000 miles as it orbits the sun. A hypothetical star at 3.2 light years distance would have shifted by one second of arc (1/3600 of a degree) – that distance therefore being one parsec. A parsec is the inverse of the parallex shift in seconds – a star at 6.4 LY would appear to move half a second of parallax, and therefore be two parsecs; one at 12.8 LY, a quarter second, and hence four parsecs; and so on.
Obviously, this measurement only works up to a limited distance – those angles become exceedingly tiny, even with the best of equipment. However, they provide a fairly good cross-section of the types of star.
Now, we turn to the H-R diagram. On this, a star on the main sequence will be of a given intrinsic brightness (absolute magnitude) to radiate at a given spectrum. Stars off the main sequence will have certain specific characteristics, such as broadened absorption bands from the distended atmospheres of red giants, etc.
Hence by identifying a star as of a given brightness and “type,” we can by the process of comparing visual magnitude with absolute magnitude calculate how far away that star is. A star that would be -3 at ten parsecs distance (its absolute magnitude) which is +1 in visual magnitude is obviously significantly farther away than ten parsecs.
A variation on this technique involves the Cepheids, which are blue supergiant stars that pulse in a period intrinsically related to their absolute brightness and size, Ergo, if a cluster of stars or galaxy contains a Cepheid with visual magnitude of +12 that has a given variability period, it is possible to figure out what a Cepheid of that period’s absolute magnitude is, and hence how far away it – and the cluster of which it is a part – is. This extends the brightness-distance measurement to the nearest galaxies – say 2-5 million light years out.
Beyond this, the red shift measurement is done on the basis of the expanding universe, and is only used where the other measurements will not work. A given galaxy known by Cepheid measurements to be, say 3 million LY out, will radiate in a spectrum with specific lines marking absorption by given elements, transitions of excited ions, etc. Those lines are at specific points on the spectrum. If a faint galaxy shows a spectrum where such a line pattern is shifted down the spectrum to a different wavelength, then one can assume that the spectroscopic Doppler effect of movement at relativistic speeds is occurring, and objects at extreme distances are assumed to be moving at such speeds due to the expansion of the universe due to the shifts in their spectral patterns.