Key Signatures

Order of Sharps or Flats
Sharp key signatures consist of a number of sharps between one and seven, applied in this order: F C G D A E B. A mnemonic device often used to remember this is "Father Charles Goes Down And Ends Battle." Others are "Fat Cats Go Down Alleys Eating Birds", or "Fanny Craddock Gets Drunk After Every Beer". The key note or tonic of a piece in a major key is immediately above the last sharp in the signature. For example, one sharp (F♯) in the key signature of a piece in a major key indicates the key of G major, the next note above F♯. (Six sharps, the last one being E♯ (an enharmonic spelling of F♮) indicate the key of F♯ major, since F has already been sharped in the key signature.)

"Flat key signatures" consist of one to seven flats, applied as: B E A D G C F (same as the order of sharps, but reversed.) The mnemonic device is then reversed for use in the flat keys: "Battle Ends And Down Goes Charles's Father". The major scale with one flat is F major. In all other "flat major scales", the tonic or key note of a piece in a major key is four notes below the last flat, which is the same as the second-to-last flat in the signature. In the major key with four flats (B♭ E♭ A♭ D♭), for example, the penultimate flat is A♭, indicating a key of A♭ major.

Background
A key signature is not the same as a key; key signatures are merely notational devices. They are convenient principally for diatonic or tonal music. Some pieces that change key (modulate) insert a new key signature on the staff partway, while others use accidentals: natural signs to neutralize the key signature and other sharps or flats for the new key. For a given musical mode the key signature defines the diatonic scale that a piece of music uses. Most scales require that some notes be consistently sharped or flatted. For example, the only sharp in the G major scale is F sharp, so the key signature associated with the G major key is the one-sharp key signature. However, the connection is not absolute; a piece with a one-sharp key signature is not necessarily in the key of G major, and likewise, a piece in G major may not always be written with a one-sharp key signature. This is particularly true of minor keys. Keys which are associated with the same key signature are called relative keys. The Dorian Toccata and Fugue in D minor, BWV 538 by Bach has no key signature, which accords with its Dorian mode status (empty signature on D) in preference to its minor key status (which would have a single B♭ signature). The B♭s that occur in the piece are written with accidentals. When musical modes, such as Lydian or Dorian, are written using key signatures, they are called transposed modes.

Notational conventions
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.

Put another way: for key signatures with sharps, the first sharp is placed on F line with subsequent sharps on C, G, D, A, E and B; for key signatures with flats, the first flat is placed on B with subsequent flats on E, A, D, G, C and F. There are thus 15 conventional key signatures, with up to seven sharps or flats and including the empty signature of C major (A minor).

Corollaries:
When the process of raising by a fifth (adding a sharp) produces more than five or six sharps, successive such raising generally involves changing to the enharmonic equivalent key using a flat-based signature. Typically this is at F♯ = G♭, but may also be at C♯ = D♭ or B = C♭. The same principle applies to the process of successive lowering by a fifth.
 * Starting from a key with flats in its key signature: raising by fifths successively reduces the flats to zero at C major (A minor). Further such raising adds sharps as described above.
 * Starting from a key with sharps: lowering by fifths successively reduces those sharps to zero. Further such lowering adds flats as described above.

The relative minor is a minor third down from the major, regardless of whether it is a flat or a sharp key signature.

The key signatures with seven flats and seven sharps are rarely used because they have simpler enharmonic equivalents. For example, the key of C♯ major (seven sharps) is more simply represented as D♭ major (five flats). For modern practical purposes these keys are (in twelve tone equal temperament) the same, because C♯ and D♭ are enharmonically the same note. Pieces are written in these extreme sharp or flat keys, however: for example, Bach's Prelude and Fugue No. 3 from Book 1 of The Well-Tempered Clavier BWV 848 is in C♯ major. The modern musical Seussical by Flaherty and Ahrens also has several songs written in these extreme keys.