Introduction to Keys
A key defines the collection of pitches to be used in a given piece or section. That is, if a piece is in the key of C major, the majority of pitches will be those found in the C major scale. The tonic and dominant scale degrees are considered the most important, and since the key defines which pitches fill these roles, it also helps establish which pitches will be the most important in a given piece or section. Once we know what scale we will be using, we also know that the harmonic content will be drawn from that scale. Thus, the key indicates which pitches will constitute the majority of melodic and harmonic content in the piece.
In notation, the key is indicated by a key signature, which is a collection of sharps or flats that is placed on the staff, just after the clef. When sharps or flats are added to the key signature, they are placed on the staff at the line or space of a specific pitch. This means that every time that pitch is played, it should be raised or lowered accordingly. For example, if the key signature has a flat on the line where the pitch B is placed, it means that all the Bs in the piece become B-flats, no matter which octave they are in. In the example on the left, there are two sharps: one on the F line and the other on the C space. This means that all Fs should be played as F-sharps, and all Cs should be played as C-sharps. C major has no sharps or flats in its key signature, so every note is the default, or natural, version of itself.
Sharps and flats are always added in a specific order and no standard key signatures contain both sharps and flats. Doing otherwise would disrupt the order of whole and half steps in major and minor scales and may create enharmonic equivalents (like E-flat and D-sharp).