In music theory, the term key is used in many different and sometimes contradictory ways. A common use is to speak of music as being "in" a certain key, such as in the key of C or in the key of F-sharp. Sometimes the terms "major" or "minor" are appended, as in the key of A minor or in the key of B-flat major, and so on. Although the concept of musical key can be a complicated subject when examined closely, broadly speaking the phrase in key of C means that C is music's harmonic center or tonic. Note that the letter-name "C" does not indicate a single specific pitch but rather all pitches with the letter name C (sometimes called a pitch class). The terms "major" and "minor" further imply the use of a major scale or a minor scale. Thus the phrase in the key of E major implies a piece of music harmonically centered on the note E and making use of a major scale whose first note, or tonic, is E. Although the term "key" is commonly used this way, actual music can rarely be described so simply. This overview of the term also makes many assumptions and may not hold true for all forms of music.
The key identifies the tonic triad, the chord, major or minor, which represents the final point of rest for a piece, or the focal point of a section. Although the key of a piece may be named in the title (e.g. Symphony in C), or inferred from the key signature, the establishment of key is brought about via functional harmony, a sequence of chords leading to one or more cadences. A key may be major or minor; music can be described as being in the Dorian mode, or Phrygian, et cetera, and as such are usually considered to be in a specific mode rather than a key. When a particular key is not being described in the English language, different key naming systems may be used.
The chords used within a key are generally drawn from the major or minor scale associated with the tonic triad, but may also include borrowed chords, altered chords, secondary dominants, and the like. All of these chords, however, are used in conventional patterns which serve to establish the primacy of the tonic triad.
Cadences are particularly important in the establishment of key. Even cadences which do not include the tonic triad, such as half cadences and deceptive cadences, serve to establish key because those chord sequences imply a unique diatonic context.
Short pieces may stay in a single key throughout. A typical pattern for a simple song might be as follows: a phrase 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, then modulate 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 a ritornello, in each key once it was established. In Classical sonata form, the second key was typically marked with a contrasting theme. Another key may be treated as a temporary tonic, called tonicization.
In common 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 some Romantic-era music) the key is deliberately left ambiguous at first. Some arrangements of popular songs, however, will shift up a half-step or a whole step sometime during the song (often in a repeat of the final chorus) and thus will end in a different key. This is known as modulation.
Certain musical instruments are sometimes said to play in a certain key, or have their music written in a certain key. Instruments which do not play in the key of C are known as transposing instruments. The most common kind of clarinet, for example, is said to play in the key of B flat. This means that a scale written in C major in sheet music will actually sound as a B flat major scale when played; that is, notes sound a whole tone lower than written. Likewise, the horn, normally in the key of F, sounds notes a perfect fifth lower than written.
Similarly, some instruments may be said to be built in a certain key. For example, a brass instrument built in B flat will play a fundamental note of B flat, and will be able to play notes in the harmonic series starting on B flat without using valves, fingerholes, or slides or otherwise altering the length of the vibrating column of air. An instrument built in a certain key will often, but not always, have its music written in the same key (see trombone for an exception). However, some instruments, such as the diatonic harmonica and the harp, are in fact designed to play in only one key at a time: accidentals are difficult or impossible to play.
In general string instruments tend to be tuned in sharp keys (such as C, D, A, and E); and wind instruments tend to be tuned to flat keys (such as F, B-flat, and E-flat).
In Western musical composition, the key of a song has important ramifications for its composition: