Inmusic theory, thekey of a piece is the group ofpitches, orscale, that forms the basis of amusical composition in Westernclassical music,jazz music,art music, andpop music.
Tonality (from "Tonic") or key: Music which uses the notes of a particular scale is said to be "in the key of" that scale or in the tonality of that scale.[1]
A particular key features atonic (main)note and its correspondingchords, also called atonic ortonic chord, which provides a subjective sense of arrival and rest. The tonic also has a unique relationship to the other pitches of the same key, their corresponding chords, and pitches and chords outside the key.[2] Notes and chords other than the tonic in a piece create varying degrees of tension,resolved when the tonic note or chord returns.
The key may be in themajor mode,minor mode, or one ofseveral other modes. Musicians assume major when this is not specified; for example, "this piece is in C" implies that the key of the piece is C major.Popular songs and classical music from thecommon practice period are usually in a single key; longer pieces in the classical repertoire may have sections incontrasting keys. Key changes within a section or movement are known asmodulation.
Music is made from audible vibrations, such as fromoscillating strings or air moving throughreeds.[3]. Humans generally perceive some vibrations as sounding "higher" or "lower" than others, creating a subjective perception calledpitch.[4] As a medium vibrates faster, its higherfrequency is perceived as higher pitch.[5] In Westerntonal music, specific frequencies are grouped into twelvepitch classes. Seven of these are considered "natural" pitches, and are represented by the letters A, B, C, D, E, F, and G.[6][7]
Humans perceive frequencies logarithmically, not linearly. The ratio between two frequencies determines how different they sound.[8] If one vibration has twice the frequency of another, they sound similar enough to be considered the same pitch class; they are said to be oneoctave apart.[9][10][11] Pitches separated by an octave are sometimes given numbers to reduce ambiguity. For example, the lowest C playable on a standardpiano is designatedC1, while the pitch with twice the frequency (one octave higher) isC2.[11][a]

On a piano, each white key represents one of the seven "natural" pitches. These are arranged from A to G, followed by another A one octave higher. Among these pitches, the relative increases in frequency fromB toC and fromE toF are smaller than the changes between other adjacent pitches. This smaller distance is called asemitone, while the larger distance from e.g.A toB is awhole tone. When two natural pitches are a whole tone apart, a black key represents an intermediate pitch. Instead of using separate letters, these pitches are denoted with theaccidentals♯ (sharp) and♭ (flat), which represent raising or lowering a natural pitch by one semitone. The pitch betweenG andA may be denoted as eitherG♯ (G plus one semitone) orA♭ (A minus one semitone). In musical terminology, G♯ and A♭ are consideredenharmonic.[13]
Most Western music is built around major and minorscales. These scales use seven of the twelve pitches, arranged in ascending or descending order, and beginning and ending with the same pitch one octave apart.[14][15][7] An ascending major scale moves between pitches with the patterntone, tone, semitone, tone, tone, tone, semitone.[16][17][b] An ascending minor scale instead uses the patterntone, semitone, tone, tone, semitone, tone, tone; this results in the third, sixth, and seventh pitches being one semitone lower compared to the major scale.[19]. On a piano, a major scale beginning from C and a minor scale beginning from A each contain only natural pitches and use exclusively white keys; the two scales are considered distinct "modes" of the same group of pitches.[20][21] In contrast, a major scale beginning from A uses the pitchesA, B, C♯, D, E, F♯, G♯, A.[22][c] The pitch which begins and ends a given scale is called itstonic.[25]
Akey is a way to classify a piece of music. It represents that the piece is oriented around a specific Major or Minor scale.[26] The name of a key, such asA Major, contains both a Tonic pitch and a Mode (either Major or Minor). Because there are 12 pitches to use as a tonic, there are 24 distinct keys.[20][27][d] If the mode is not specified, the simplified term "key of C" usually implies the key is C Major.[28]
If a piece of music is in a key, it mostly uses pitches from the corresponding scale.[20] The seven pitches that belong to the scale are calleddiatonic pitches, while the remaining five are calledchromatic pitches.[15] A key does not prohibit the use of chromatic pitches, but they will be rarer than diatonic pitches.[26] The key's tonic represents a pitch of "stability" for the music to orient around. In particular, a composition almost always ends on the tonic.[20][29]
Not all music has a well defined key. Some classical compositions, such asChopin'sPrelude op. 28 no. 2 andWagner'sTristan und Isolde, do not clearly follow these patterns.[30] Modernatonal music, including the works ofArnold Schoenberg, has no tonal stability and freely interweaves all twelve pitches.[31][32]
Music is written using astaff (music) with five or more parallel lines. Pitches are represented bynotes placed either on a line or in the space between lines. The relationship between pitch and position is defined by a symbol called aclef. In a standard staff with atreble clef, the bottom line represents the pitch E, the line above represents G, and the space between the two lines is F. The pitch between F and G cannot be represented solely by position, so it is represented by marking either an F or G note with an accidental (♯ or ♭).[33]
In the keys of C Major and A Minor, the common diatonic pitches do not use accidentals.[34] When writing in other keys, the positions themselves can be marked with accidentals as a shorthand. For example, a ♯ accidental on a line or space representing F means that, unless otherwise specified, all F pitches should be raised one semitone.[21][34][11]. Another accidental, ♮ (natural), overrides this general rule and represents the natural pitch.[35][36] When writing this shorthand notation, known as akey signature, Sharps are always arranged in the order F, C, G, D, A, E, B, while Flats use the opposite order.[34]
A key signature allows the corresponding major or minor scale to be written without accidentals.[37][28] Any remaining accidentals represent chromatic pitches which are less closely associated with the key.[38] However, a key signature does not uniquely specify a key, since it does not identify the tonic. Any key signature could represent either a major or minor key with the same pitches but different tonics.[20][39]
Short pieces may stay in a single key throughout. A typical pattern for a simplesong might be as follows: aphrase ends with a cadence on the tonic, a second phrase ends with a half cadence, then a final, longer, phrase ends with an authentic cadence on the tonic.
More elaborate pieces may establish the main key, thenmodulate to another key, or a series of keys, then back to the original key. In the Baroque it was common to repeat an entire phrase of music, called aritornello, in each key once it was established. In Classicalsonata form, the second key was typically marked with a contrastingtheme. Another key may be treated as a temporary tonic, calledtonicization.
Incommon practice period compositions, and most of the Western popular music of the 20th century, pieces always begin and end in the same key, even if (as in someRomantic-era music) the key is deliberately left ambiguous at first. Somearrangements of popular songs, however, modulate sometime during the song (often in a repeat of the finalchorus) and thus end in a different key. This is an example ofmodulation.
Inrock andpopular music some pieces change back and forth, or modulate, between two keys. Examples of this includeFleetwood Mac's "Dreams" andThe Rolling Stones' "Under My Thumb". "This phenomenon occurs when a feature that allows multiple interpretations of key (usually a diatonic set as pitch source) is accompanied by other, more precise evidence in support of each possible interpretation (such as the use of one note as theroot of the initiating harmony and persistent use of another note as pitch of melodic resolution and root of the final harmony of each phrase)."[40]
Certainmusical instruments play in a certain key, or have their music written in a certain key. Instruments that do not play in the key of C are known astransposing instruments.[41] The most common kind ofclarinet, for example, is said to play in the key of B♭. This means that a scale written in C major insheet music actually sounds as a B♭ major scale when played on the B-flat clarinet—that is, notes sound awhole tone lower than written. Likewise, thehorn, normally in the key of F, sounds notes aperfect fifth lower than written.
Similarly, some instruments are "built" in a certain key. For example, abrass instrument built in B♭ plays afundamental note of B♭, and can play notes in theharmonic series starting on B♭ without using valves, fingerholes, or slides to alter the length of the vibrating column of air. An instrument built in a certain key often, but not always, uses music written in the same key (seetrombone for an exception). However, some instruments, such as the diatonicharmonica and theharp, are in fact designed to play in only one key at a time:accidentals are difficult or impossible to play.
The highland bagpipes are built in B♭ major, though the music is written in D major with implied accidentals.
In Western musical composition, the key of a piece has important ramifications for its composition: