Since intervals with small whole-number frequency ratios are more consonant, the question arises: what notes should we use if we want lots of the intervals between them to be consonant? There are a lot of answers to this question, and different answers have been popular at different times in history. Recently, we’ve settled on using twelve equally-spaced notes per octave. Why twelve?
To explore this, I wrote a program which compares various equal-spaced divisions of the octave with intervals formed by whole-number frequency ratios:
It turns out that when you divide the octave into twelve parts, the resulting notes fall much closer to the whole-number ratio notes (especially the most important ones, like 3/2, 4/3, and 5/4) than they do if you use other numbers of divisions (like eleven or thirteen).