Every note on a sheet of music, every key on a piano and every note you sing is a tone. Tones in music are separated by intervals of whole tones and half tones, also called whole and half steps.
When you look at the keyboard of a piano, you see that some of the white keys are separated by black keys and some are not. Black keys on the piano are grouped in twos and threes. When a pianist moves her fingers from one white key to the next without pressing the black one that lies in between, she has played a whole step. If she presses the black key immediately to the right of a white one, she has played a half step--in fact, she has played a sharp. If she presses the black key to the immediate left of a white one, she has played a flat. Sharps and flats are the half steps. Sharps raise the tone by a half step, and flats lower the tone by a half step.
The white keys on a piano are lettered from A to G. Before each group of black keys, there are always two white keys together. Before each group of two black keys, the white keys are B and C. Before each group of three black keys, the white keys are E and F. There are no black keys between E and F, and between B and C, which means the interval between those pairs of notes is a half step.
On any piece of music there are one or two sets of five lines--staffs--connected by a bar at the extreme ends. The sign at the beginning of the staff is called a clef and determines what lines and spaces in the staff coincide with what notes. Next to the clef sign, you'll see symbols that look like a pound key or an italicized lowercase letter b. The pound means sharps. The b signs are flats. From none to seven sharps or from none to seven flats appear--this group of sharps or flats is the key signature. The lines or spaces the symbols are placed on indicate which note is played as a sharp or a flat and this will be consistent for the entire piece of music. The key signature is read by noting which lines or spaces have sharps or flats on them.
When a sharp or flat symbol is seen in the body of the music right next to a particular note, it means that only the note that's marked is played or sung sharp or flat until the next measure begins. In other words, the tone of that particular note is either raised (sharped) or lowered (flatted) from its original, or natural, sound. These sharps and flats are called "accidentals" because they're not marked in the key signature, but are placed by the composer.
Each key in music is based on an eight-note scale. Using the whole and half steps, a major scale is made up of two whole steps, one half step, three whole steps and one half step. When you sing "do, re, mi, fa, sol, la, ti, do," you are singing a major scale regardless of what note you start on. The whole steps are between "do" and "re", "re" and "mi", and between "sol", "la", and "ti". The half steps are between "mi" and "fa", and between "ti" and "do". If you start on middle C, which is the white key immediately before the group of two black ones closest to the center point on the piano, you can sing or play the scale with no sharps or flats needed to make it correct. This means that you're singing in the key of C major. That's not the case if you start anyplace else. In every other major scale, you'll need to raise or lower at least one tone to make the scale correct. This is where the sharps and flats come in.
For example, if a pianist counts alphabetically five notes up from middle C moving from left to right, she comes to G. If the pianist starts at G and plays only the white keys, she'll be fine until she gets to the seventh note in the scale. That note, an F, simply doesn't sound right in a major scale. It's a half step too low. To make the scale correct, she must play the black key immediately to the right of the F, which raises the tone and makes it an F sharp. This is the key of G major because it began on that note, and it has one sharp, an F.
If she moves to the fifth note up from G, the pianist comes to D. To play that scale correctly, she not only needs the F sharp, she needs to add another one. Once again, the seventh note in the scale (a C), if played on the white key, is a half tone too low. She will need to raise it by playing the black key to the right of it, raising it to a C sharp. So, in the key of D major, there are two sharps, F and C.
In each case, if the pianist begins her scale five notes higher than the last one, she will need to raise the seventh note by a half step for the major scale to be correct. This process of adding a sharp to each scale at intervals of five is called the "Cycle of Fifths." Ultimately, she will end with a scale in which there are seven sharps that she must play. This is a scale in the key of C sharp major. It begins on the black key to the right of C and goes from there in the same sequence of whole and half steps, played almost entirely on the black keys.
This process works for flats also, but instead of counting five notes from C, the pianist can count up four notes. The procedure is the same, but the fourth tone of each scale must be lowered. For example, if the pianist begins at middle C and counts four keys to the right, she arrives at F. If she starts with the F and plays the next seven keys after it using only the white keys, she'll have a problem. This time it comes at the fourth note in the scale, which is a B. The tone is too high. To make it correct, she must play a B flat, which is the black key to the left of the B.
If she counts three whole steps and one half step up from F, she comes to B flat. To play that scale correctly, the fourth note, an E, must be played on the black key to the left instead of the white one. In other words, the pianist must play an E flat. As the pianist continues with this progression, she will find that the F major scale is the only major scale in the cycle of fourths to begin on a white key. The rest all begin on black keys.
The same result can be achieved by using the cycle of fifths and moving to the left instead of the right. Either way, one additional tone in each scale must be lowered or played flat, in order for the scale to sound right.
Sharps and flats have been part of music ever since the first ancient human strung a few tones together and liked the sound. People have been singing ever since. Whether it's an aria from one of Puccini's operas or a ditty the singer just made up, sharps and flats will probably come into it somewhere--whenever a tone needs to be raised or lowered just a little until it sounds exactly right.