A key is the major or minor scale around which a piece of music revolves.
Each major and minor key has an associated key signature that sharpens or flattens the notes which are used in its scale.
The convention for the notation of key signatures follows the circle of fifths.
Starting from C major (or equivalently A minor) which has no sharps or flats, successively raising the key by a fifth adds
a sharp, going clockwise round the circle of fifths. The new sharp is placed on the new key's leading note (seventh degree)
for major keys or supertonic (second degree) for minor keys. Thus G major (E minor) has one sharp which is on the F; then D
major (B minor) has two sharps (on F and C) and so on.
Similarly successively lowering the key by a fifth adds a flat, going counter-clockwise round the circle of fifths.
The new flat is placed on the subdominant (fourth degree) for major keys or submediant (sixth degree) for minor keys.
Thus F major (D minor) has one flat which is on the B; then B♭ major (G minor) has two flats (on B and E) and so on.
In the diagram above major keys are indicated by red capital letters and the minor keys are indicated by grey lowercase letters.
Root note or tonic
The root note (or tonic) of a key acts as the center of the key. Similar to the root notes of chords, the root note
of a scale is the note on which a scale is built.
A song played in the ‘key of C major’ revolves around the seven notes of the C major scale – C, D, E, F, G, A, and B,
a song played in the ‘key of A minor’ revolves around the seven notes of the A minor scale – A, B, C, D, E, F, and G.
As stated both have no sharps or flats.
Where as a song played in the 'Key of F major' (F, G, A, Bb, C, D, and E) and the
'Key of D mior' (D, E, F, G, A, Bb, and C) both need to have one flat note. Similarly the 'Key of G major' and
the 'Key of E minor both require one sharp note to balance tonally. And so on...