The abbreviations explain it:
a.m. =
ante meridiem, which means "before midday/noon"
p.m. =
post meridiem, which means "after midday/noon"
Yes, I suppose technically, 12:00 noon is neither "before" nor "after" noon, but considering the "quantum of time" (smallest meaningful unit of time0 is 10^-43 seconds (i.e., 0.0000000000000000000000000000000000000000001 seconds), let's face it, by the time your clock actually records 12:00 noon and your brain registers that fact, it's already literally "after noon." So 12:00 p.m. makes sense.