Here's one of the less-obvious formulas:
Bonus level L spells: (A - 2 - 2 * L) / 8, where A is your relevant ability score. (Round down as usual.)
Example:
A wizard with Int 23 has (23 - 2 - 2) / 8 = 2 bonus level 1 spells, (23 - 2 - 4) / 8 = 2 bonus level 2 spells, (23 - 2 - 6) / 8 = 1 bonus...