Why does my 500GB hard drive have a capacity of exactly 500,107,862,016 bytes?

The answer is IDEMA formula, as described in the IDEMA Standard LBA 1-03 specification (specs available here, or direct PDF download).

LBA counts = (97,696,368) + (1,953,504 * (Advertised Capacity in GBytes – 50))
LBA counts = (97,696,368) + (1,953,504 * (500 – 50))
LBA counts = 976,773,168

Capacity in Bytes = 512 Bytes * LBA counts
Capacity in Bytes = 500,107,862,016 Bytes