A key is a home note plus the scale built on it: in G major, G is home and the notes come from the G major scale, with one sharp, F♯. Rather than write the ♯ before every F, music writes it once at the start of each line: the key signature (see Reading Music).
Sharps are always added in the same order, and so are flats. The sharps come in the order F C G D A E B; the flats in the exact reverse, B E A D G C F. A key with three sharps always has the first three: F♯, C♯ and G♯.
Look closely: each sharp is a 5th above the one before, F up to C up to G … That's the circle of fifths again. Each step clockwise on the circle adds a sharp (or takes away a flat); each step anticlockwise does the opposite.
Each signature belongs to one major key and one minor key, its :
Three keys can be written two ways: G♭ and F♯, D♭ and C♯, B and C♭ sound the same. Musicians usually pick the one with fewer signs: D♭ (five flats) rather than C♯ (seven sharps), B (five sharps) rather than C♭ (seven flats). G♭ and F♯ both have six, and both are used.
Pick a key's root note, then major or minor, to see its signature and its scale. Click a note to hear it.
D major: F♯ C♯. The last sharp is C♯. A half step up from it is D: D major.
Next: Relative and Parallel Keys