The correct answer is: 1024 (but the error is so small if you use 1023, it actually doesn't matter since the reference volt will vary with a much larger margin of error than your calculation will introduce).

But in case you are still wondering why not 1023, here it is.

After reading many responses from many posts on this exact issue (and some go into very technical detail why it should be one or the other), the bottom line is this:

The confusion boils down to a simple miss interpretation of the facts (and some confusion caused by the math).

NB: The result from analogRead() is *not *a value (as we would like to think of it when measuring something), its an *index*. Its an index to a bin number in which the measured value fits, and there are 1024 bins (which has to represents the whole range of values you want to measure).

The first bin number (or bin ID number) is 0, the second bin is 1, the third is 2 etc. until the 1024th bin which has an ID number of 1023.

When you use the equation of (1023/1024)*5 to prove me wrong, since the answer is not 5 (as you want it to be when measuring 5Volt with a 5Volt reference and analogRead()=1023; then you are missing my point!

This is the issue with converting analog values into digital values. With Digital values, there are no in-betweens. A lot of the detail actually gets lost, and more so when we have fewer bins to fit a large range of values into.

Example: If the reference voltage Vref is 5Volt, and the input value is 5Volt, I expect analogRead to provide me with 1023 (the last or highest bin number in the range) so I can interpret that at as 5Volt.

When analogRead gives me 0, I expect the value to be 0 Volt.

BUT now, in which bins would you like to put 0.0001 Volt or 4.999 Volt? When is the value measured too big for the first bin or too small for the last bin?

The fact of the matter is, you only have 1024 bins to put all the values in from 0 to 5 Volt, which is good enough for most things, but it does show a bit of a problem when we want to work back from the digital bin number to the original measured analog number.

With only 1024 bins, and if the range of volt values we want to measure goes from 0 to 5 Volt, it means each bin is 5/1024 = 0.0048828125 Volts "big", which means, measured values from 0 to 0.004882812 will fit in the first bin (bin 0) and values from 4.9951171875 to 5 (and more) will fit in the last bin (bin 1023).

So, the bottom line is that in the analog world, there can be millions of different measured volt values between 0 and 5 volt, but in this 10bit digital system of ours, there can only be 1024.

This means unfortunately that if I read a value of 0 using analogRead(), the value can be anything from 0 to 0.00482...V and if I read a value of 1023, the actual value can be anything from 4.995112... to 5 volt (and more).

So back to the original question: 1023 or 1024?

If you use 1023, your bins are actually larger because you use 1 less bin and 1/1023=0.0009775...V versus 1/1024=0.0009765...V). This means that when analogRead()=1023, the value you calculate may be 5volt using the formula "value/1023*5", but it actually also include smaller values down to 4.995112...V, since those values will also fit in the same bin.

When you use 1024, the bins are smaller, and thus 5*1023/1024=4.995117, which is the smallest value that will fit in the same bin.

In short, 1024 is actually more accurate to use, eventhough the math may let you to believe its wrong!