Keys and key signatures · Music theory
The order of accidentals, how to recognize a key, relative and parallel keys, the circle of fifths and closely related keys.
Key and key signature
A key is the organization of sounds around a tonic, with the scale of a mode: G major, E minor. Its fixed accidentals are written together at the start of each staff, after the clef, and form the key signature.
The key signature applies to every note with that name, in any octave, for the whole piece (until it changes). Accidentals outside it are written in the music.
A little history, and changing the key signature
The key signature was not always as it is today. A fixed B♭ already appears in the Middle Ages, signatures of several flats in the 16th century and sharp signatures around the mid-17th. In Baroque music it is normal to find minor works with one flat fewer than expected: a custom of the time that does not mean another key.
When a work changes key, the new signature is written after a double bar. The custom of first writing naturals for the old signature has been fading, except when the new one has no accidentals.