How to find the key from the key signature

The key signature is the set of sharps or flats at the start of every staff. They hold for the whole piece and in every octave, and they tell you the key.

Want to practice it while you read? Scales and key signatures

The order of sharps and flats

The accidentals in a key signature always appear in the same order. Sharps: F, C, G, D, A, E, B. Flats, the other way round: B, E, A, D, G, C, F. If a key signature has two sharps, they are F and C; never any others.

All seven sharps, in order.
All seven flats, in order.

With sharps: a half step above the last one

The last sharp is the leading tone of the major key. The tonic is a half step above it. With two sharps, the last one is C♯: the key is D major.

Two sharps: D major. Listen to the scale: every F and C sounds sharp.

With flats: the second-to-last one

With flats, the major tonic is the second-to-last flat. With three (B, E, A), the second-to-last is E♭: E-flat major. With a single flat there is no second-to-last: it is F major, and that one you learn by heart.

Three flats: E-flat major.

Major or its relative minor

Each key signature serves two keys: a major key and its relative minor, a minor 3rd below (three half steps). D major and B minor share the same two sharps.

To tell which one it is, look at the music: which note and which chord it ends on, and whether the leading tone of the minor key shows up with an accidental. In B minor you will see A♯, which is not in the key signature.

B harmonic minor: the key signature of D major, with the A♯ written in.
Key signatureMajorRelative minor
NoneC majorA minor
1 sharp (F)G majorE minor
2 sharps (F, C)D majorB minor
3 sharps (F, C, G)A majorF♯ minor
4 sharps (F, C, G, D)E majorC♯ minor
1 flat (B)F majorD minor
2 flats (B, E)B♭ majorG minor
3 flats (B, E, A)E♭ majorC minor
4 flats (B, E, A, D)A♭ majorF minor

In the exercise you name the key of a key signature and write it out yourself. You start with one accidental; more come in once those are solid.

Practice: Scales and key signatures