Why does a piano keyboard look the way it does? The answer has to do with music modes. The modes are types of scales. A scale is simply a specified sequence of intervals from one note to the same note an octave higher, say, from A to the next higher A.
In order to understand this point it is useful to know something about how the piano keyboard came to be. The earliest keyboard instruments, before pianos existed (see Who invented the piano?) had only one row of keys, which corresponded to the lower row on a piano as we know it today. (Keyboards then weren't white, but we'll call them the white keys so as to avoid confusion.) These keys corresponded to the notes A through G.
At that time in Western musical history, music existed in modes. If you played all the keys from A to the next higher A, that would be the Aeolian mode (which we call natural minor today). C to C is Ionian (which we now call major).
Here is a list of the music modes, with the starting key on a piano:
Hence, if you start on F and play all the white keys up to the next F, that would be a Lydian scale.
Now, music would be very limited if every time a composer wanted to use, say, the Ionian mode (or major as we know it today), he or she were forced to use C as the basis. That's where the second row of keys (the black keys on the modern piano) come into play. What if music were intended for a voice, and that singer couldn't reach all the pitches in the C scale? The composer might need to start, say, on G.
If we start on G and try to play an Ionian scale, we'll be fine up until the very end: G A B C D E F G. The next to last note is too low and needs to be raised, so we need a pitch between F and G on the piano. Thus, the first black key was born, midway between F and G. In this case, we'll call it F-sharp. (We need all diatonic notes in each traditional scale—that is to say, some form of each note A through G. This note couldn't be G-flat in this case, since we'd use G twice and F not at all.)
Now let's say we want to play in the Ionian mode (major) but start on F. In this case, there would again be one note out of place: F G A B C D E F. Here, the B is too high and needs to be lowered. Hence, we need a pitch right between A and B... so another black key is born. This pitch (not piano key, since the keys are not the notes!) is B-flat in this case—flat because the B is lowered.
It turns out that we need only five "in-between" keys, or black keys. With them, it is possible to start on any key and play any scale in any of the music modes. It's also possible to start on the black keys.
The keyboard as we know it today was used by the 14th century and gradually became a convention. (The above description is a bit of a simplification, since B-flat was not raised on all early keyboards; in other cases, the only raised key was B-flat.)
Today's piano keyboard (and organ, and harpsichord...) thus has a total of twelve keys within each octave, seven white keys and five black keys. The distance from any one key on a piano to the very next one is a half step, and two half steps make a whole step. Thus, from C to D is a whole step because there is a key in between, whereas E to F is a half step because there is no key between them.
Now we can get a bit more detailed with regard to the music modes. Here is a table listing the modes and its pattern of whole steps (W) and half steps (H) (click the play button to the right to hear each mode):
Composers have long since ceased to limit themselves to the "textbook" music modes, new scales have been invented and new systems for using the twelve pitches within the octave in traditional Western music. Even "in-between in-between" pitches (called quarter tones) are sometimes used.
Curiously, however, virtually all of what we now call "classical music" is limited to just two modes, Ionian (major) and Aeolian (minor). (Technically, there are three types of minor, and the Aeolian mode corresponds to just one of them, natural minor.)