In musical notation, a key signature is a series of sharps or flats placed on the staff, designating notes that are to be played sharp or flat respectively unless otherwise noted with an accidental. Key signatures are generally written immediately after the clef at the beginning of a line of musical notation, although they can appear in other parts of a score.

A key signature is not the same as a key, in fact, key signatures are merely a convenience of notation. However, they are convenient only for diatonic or tonal music. Furthermore, some pieces which 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.


Fig 1. The B-Major scale

For a given mode the key signature defines the diatonic scale which a piece of music uses. Most scales require that some notes be consistently sharpened or flattened.

For example, in the key of G major, the leading-note is F sharp. The key signature indicates that each time an F is written in the staff it is in fact to be played as F sharp.

Individual sharp, flat or natural signs that modify an individual note in the piece are called accidentals (for example, an F natural in a piece in the key of G). These override the key signature for the duration of the bar they occur in.

Figure 1 shows the key signature of the scale of B-major. Any note which is on the same line or space as its five sharps is increased from its natural pitch by a semitone. Although key signatures can technically consist of any collection of sharps or flats, musical tradition dictates that they be arranged in a fixed order according to the key and mode of the piece. As each major key has an equivalent relative minor key that may be represented with the same key signature. The same also applies to other modes such as Lydian and Phrygian.

The table below illustrates the number of sharps or flats for each key signature and the relative major key signatures for minor scales. See: circle of fifths.

Key Sig.Major ScaleMinor Scale
0 C major A minor
1# G major E minor
2# D major B minor
3# A major F# minor
4# E major C# minor
5# B major G# minor
6# F# major D# minor
7# C# major A# minor
1b F major D minor
2b Bb major G minor
3b Eb major C minor
4b Ab major F minor
5b Db major Bb minor
6b Gb major Eb minor
7b Cb major Ab minor

For key signatures with sharps, the first sharp is placed on F line (for the key of G major/E minor). Subsequent additional sharps are added on C, G, D, A, E and B. For key signatures with flats, the first flat is placed on the B line, with subsequent flats on E, A, D, G, C and F. There are 15 different key signatures, including the "empty" signature of C major/A minor.

The key signatures with seven flats and seven sharps are very rarely used, because they have simpler enharmonic equivalents. For example, the key of C# major (seven sharps) is more simply represented as Db major (five flats) - for modern practical purposes these keys are the same, because C# and Db are the same note. Pieces are written in these seven sharp or flat keys, however. The third Prelude and Fugue from Book One of Johann Sebastian Bach's Well-Tempered Clavier is in C# major, for example.


In cryptography, a key signature is the result of applying a hash function on a key, for the purpose of simplifying operations on keys. For example, cryptographic keys are often quite large and cumbersome to compare, so a user who wants to verify the presence of a public key in a database might use a smaller key signature rather than comparing the whole key.