Arduino data conversion – 1023 or 1024?

Voltage at the analog input pins can be measured by using the analogRead function. Since it returns the 10-bit integer of the ADC output, the value falls in the range from 0 to 1023. Looking at the examples on the Internet, you can find two ways how the voltage is calculated:

  1. analogRead(A0)*(5.0/1023.0);
  2. analogRead(A0)*(5.0/1024.0);

They are not the same, so which is the correct one? See our answer.