So the question is, "how does it know what the maximum is"? It has to have a reference voltage. As that_chap mentioned, you can change the reference voltage. But if you don't, then the 5VDC is the reference voltage.
The analog-to-digital converter is just describing a ratio, not a voltage. If the signal is equal to GND, or lower, you get 0.000000; if the signal is equal to the reference voltage, you get 1.000000; if it's somewhere in between, you get a number that is the same ratio in between. So halfway between GND and 5VDC gives 0.500000. One third of the way between GND and 5VDC gives 0.3333333.
Rather than return a complicated floating-point value, it multiplies the result into an easy-to-use integer instead: (ratio * 1023).
(If you're comfortable with thinking in binary, it's just the fractional part of the ratio, without the
binary point, to make it an integer. If that made no sense, ignore it.