The number of black keys on the piano is determined by the size of the piano. There are full size pianos and pianos of smaller dimensions. On a full size piano with 88 keys, there are 52 white and 36 black keys. A more complex question is how the black keys came to be on the piano, and that is not quite so easy to answer. Originally, the musical "keyboard" was crafted for use by the ancient Greeks, and was used as a controlling device for a water organ called the "hydraulis." These early keyboard setups had one row of keys, roughly equivalent to the white keys. They were all in the same plane, with no keys raised or differentiated from the other keys in any way (as they are on a modern piano, where the blacks are recessed and raised higher than the white keys.) The mathematical relationship between the keys was quite complex, originally discovered by the great mathematician Pythagoras. To simplify it, each key to the right was higher than the previous one, and a formula governed this setup, too difficult to mention here. Eventually composers discovered that there were other tones that sounded good in addition to the standard setup of seven or eight. In order to add these additional tones to the setup, they modified the keyboard by raising these additional keys and recessing them from the original "white" keys. In this way, the original setup was not disturbed but rather added to and refined. After many hundreds of years, the Renaissance composers discovered a total of five extra tones, (think "black") that could be added to the original seven "white" tones. The end result was that the distance between any two keys, whether white or black, was equidistant. That is, the pitch from one to the next was raised by exactly the same increment. How these white and black keys came to be arranged into the modern arrangement of five black keys, with a group of three and a group of two, is quite another story and has much to do with the shape of the human hand and the musical developments occurring during the period of the Renaissance. On many Baroque instruments, particularly elaborate harpsichords of the eighteenth century, the colors were reversed, with the "white" keys black and the "black" keys white. I've seen harpsichords with red and black, and red and white.