Flash size in boards.txt ATmega 328p 32u4
1KB is 1024 bytes, not 1000 bytes. 

Therefore 32kb = 32768 bytes. 

32768-512=32256, which is exactly the value used for upload.maximum_size for the 328p.

4kb=4096 bytes. 32768-4096=28672 which is the value for the 32u4.