# Why am I 1 digit out, when calculating space from two addresses?

My STM32F407 microcontroller datasheet states that my flash region is between the following addresses:

0x08000000 to 0x080FFFFF


I want to calculate the amount of flash, which I know is 1024KB, but when I try to prove this, I always get to 1023. Here's my math:

0x080FFFFF - 0x08000000 = 0x000FFFFF
= 1048575
= (1048575 / 1024)KB
= 1023KB


Inversely...

1024 * 1024 = 1048576


Why am I confused with 1 byte? Dumb question, and I know this is high school stuff...

• You meant 0x080FFFFF - 0x08000000 + 1. To see this, write out the equivalent 1 byte address calculation... 0x08000000 - 0x08000000 ... Oct 30 '15 at 16:42
• betterexplained.com/articles/… Oct 30 '15 at 22:39

First of all, you are talking about the FLASH region, but then about RAM. These are two different things. Second: How many numbers can be numbered by 0 to 9? 10, right? So it is given by 9 - 0 + 1. The same with your space calculation. The total size is
0x080FFFFF - 0x08000000 + 1 = 0x100000 = 1048576. Then 1048576 / 1024 = 1024.