The group of sharps or flats printed after the clef and before the time signature. It applies to the whole piece: if it has F♯, every F in the music is played as F♯, in any octave, without being marked again.
Key signatures exist to save ink. D major has two sharps; without a key signature every single F and C in the piece would need its own accidental — hundreds of them. Two symbols at the front settle it once.
Two sharps = D major (or B minor). Every written F is played F♯.One flat = F major (or D minor). Every B is B♭.
Sharps and flats always appear in the same order and never in another: sharps go F C G D A E B, flats go the same list backwards, B E A D G C F. So three sharps can only ever be F♯ C♯ G♯.
Signature
Major
Relative minor
How to read it
none
C
A minor
All white keys
1♯
G
E minor
Last sharp is F♯; a half step up is G
2♯
D
B minor
Last sharp is C♯; a half step up is D
1♭
F
D minor
Just learn this one: one flat is F
2♭
B♭
G minor
The second-to-last flat names the key
Common questions
How do you tell the key from a key signature?
With sharps, the major key is a half step above the last sharp: if the last one is F♯, the key is G major. With flats, it is the second-to-last flat, and a single flat means F major. Then listen for major or minor, since each signature fits both.
What order do the sharps and flats come in?
Sharps come F C G D A E B, and flats come in the reverse order, B E A D G C F. A signature always starts at the front of its list, so two sharps are F♯ and C♯, and two flats are B♭ and E♭. A mnemonic for the sharps: Father Charles Goes Down And Ends Battle.
How many sharps or flats can a key signature have?
At most seven. Seven sharps make C♯ major and seven flats make C♭ major. Beyond that a key would need double sharps or double flats, so it is written as its enharmonic twin instead.