In musical notation, a key signature is a set of sharp (♯), flat (♭), and rarely, natural (♮) symbols placed together on the staff. 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, notably after a double barline.
A key signature designates notes that are to be played higher or lower than the corresponding natural notes and applies through to the end of the piece or up to the next key signature. A sharp symbol on a line or space in the key signature raises the notes on that line or space one semitone above the natural, and a flat lowers such notes one semitone. Further, a symbol in the key signature affects all the notes of one letter: for instance, a sharp on the top line of the treble staff applies to Fs not only on that line, but also to Fs in the bottom space of the staff, and to any other Fs. This convention was not universal until the late Baroque and early Classical period, however; music published in the 1720s and 1730s, for example, uses key signatures showing sharps or flats on both octaves for notes which fall within the staff.
An accidental is an exception to the key signature, applying only in the measure in which it appears.
Although a key signature may be written using any combination of sharp and flat symbols, fifteen diatonic key signatures are by far the most common, and their use is assumed in much of this article. A piece scored using a single diatonic key signature and no accidentals contains notes of at most seven of the twelve pitch classes, which seven being determined by the particular key signature.