The key describes the note around which a piece of music is built. When a song consists of notes from a particular scale, it is said to be written in the key which has the same notes as that scale. For example, if a song contains mostly notes from the C major scale, it is said to be in the key of C major.
If a song contains mostly notes from the F major scale, it is said to be in the key of F major. If a song contains mostly notes from the G major scale, it is said to be in the key of G major.
When singing or playing in any major key other than C, the key will contain at least one sharp or flat, and possibly as many as six. Instead of writing these sharps or flats before each note as they occur, they are usually written at the beginning of the song just before the time signature. These sharps or flats are called a key signature.
The number of sharps or flats in the key signature depends on the number of sharps or flats in the corresponding major scale. The major scales and key signatures for the keys of F and G are shown in the following diagrams.
Without sharps and flats, these scales would not contain the correct pattern of tones and semitones and would therefore not sound like a major scale. Sol-fa syllables can be applied to any major scale.
You simply call the first note of the scale do, and follow the pattern through the rest of the scale. In the key of G major, the note G would be do, A would be re, B would be mi, etc. In the key of F major, the note F would be do, G would be re, A would be mi, etc.
The G major scale contains one sharp, F#, therefore the key signature for the key of G major contains one sharp, F#.
The F major scale contains one flat, Bb, therefore the key signature for the key of F major contains one flat, Bb.
The reason some scales contain sharps while others contain flats is that there has to be a separate letter name for each note in the scale. E.g., the G major scale contains F# instead of Gb even though these two notes are identical in sound. However, if Gb was used, the scale would contain two notes with the letter name G and no note with the letter name F. This is the reason for choosing to call the note F# in this key.
In the key of F major, the note Bb is chosen instead of A# for the same reason. If A# was used, the scale would contain two notes with the letter name A and no note with the letter name B.
The note each major scale starts on will determine how many sharps or flats are found in each key signature because of the necessity for the scale to have the correct pattern of tones and semitones in order to sound right.
The following chart contains the key signatures of all the major scales used in music, along with the number of sharps or flats contained in each key. Because there are 12 notes used in music, this means there are 12 possible starting notes for major scales (including sharps and flats).
This means that some of the keys will have sharps or flats in their name, e.g., F# major, Bb major, Eb major, etc. Keys which contain sharps are called sharp keys and keys which contain flats are called flat keys.