I always knew this but used to wonder
why 12?, as I'm sure a lot of people did. It turns out of course to be a human choice, but the convenience of that choice can be codified mathematically.
On a piano you move up an octave by going up by 8 white keys, or 12 semitones (white and black keys). Going up by 4 semitones is called a "major third", which multiplies the frequency of the note by 5/4. If you do three major thirds you get an octave. However, notice that (5/4) multiplied by itself three times is 125/64 which is actually slightly less than 2.
In fact there is no way to tune a piano perfectly - there has to be a compromise in the intervals somewhere. The reason for this is exactly that no rational number (fraction) equals 2 when raised to an integer power.