I know that the piano contains 7 octaves plus a 4th. I also know that it accommodates the full circle of fifths (from C and back to C). But since a fifth contains 7 semitones, it only "needs" 7X12 = 84 keys for the circle. So why the "extra" 4 keys?
Well, the piano started out with only about 60 keys, same as the harpsichord – in fact it WAS a harpsichord, except that the harpsichord maker Bartolomeo Cristofori (try saying that 10 times fast!) got the bright idea of putting hammers on one (to HIT the strings) instead of plectra (to PLUCK the strings).
So the piano was invented – this was around 1700, or maybe a little before that. Anyway, as composers began to use the new instrument they started writing more and more complicated and brilliant music for it. Pretty soon, the keyboard had to expand in both directions. By the middle of the 19th century, it had 85 notes – up to A – then finally they added the last three at the top. There's even a piano made today – the Bösendorfer Imperial Concert Grand – which has 97 keys; the bass notes go all the way down to C. It's nine-and-a-half feet long and weighs almost a ton.
I'm no expert but the obvious answer is so to have the full seven octaves for both A minor and C major. The first key of a piano is an A and the last is a C. The importance of A minor and C major is they are the only two keys made up entirely of white keys.
And to be precise, one extra pitch is added to the top of the final octave to complete it. So a full chromatic scale is 13 pitches, 12+1. Two chromatic scales are 25 pitches, (12x2)+1, etc.
So in total there are (12x7)+1+3 = 88 keys on a piano.
An observation about 88 notes on the piano...
- You can play through the entire major key circle of fifths on the piano starting on the lowest C to the highest C; AND
- You can play through the entire minor key circle of fifths on the piano starting on the lowest A to the highest A.
Interesting how this worked out perfectly!
There are a lot of explanations for this, such as "The extra 4 keys allow the piano to cover the entire range of a 'standard' orchestra." However, it's probably just tradition. The human ear can't really distinguish notes higher or lower very well, but it provides more functionality than 4- or 5-octave pianos.
The keyboard grew beyond five octaves as piano makers essentially said "Ours is better because it has more notes."
There is no particular reason why it didn't stop at 85 or keep going to 90. It could have done either. Eventually the market required that all pianos have the same number, and it just happened to stabilize at 88.