How does analogRead know minimum and maximum value

You usually hook "things" up to an anlog in on Arduino so it acts as a voltage divider between 5V and ground. so you will always get from 0V to 5V on the pin.

If you hook up something (like a LDR) that does not go all the way down to 0 Ohm then you just don't get the full 0 - 1023 range from the ADC.

If you hook up something that is not a voltage divider between Arduinos 5 and ground, you are responsible for securing that the voltage is allways between 0V and 5V.