In Music theory, the key is the tonal center of a piece. It is designated by a note name (the tonic), such as C, and can be either in major or minor mode. Other modes are also possible, for example: dorian, phrygian, lydian, but most popular music uses either the major (Ionian) and minor (aeolian) modes. 18th and 19th century music also tends to focus on these modes.
The major mode has half-steps between scale steps 3 and 4 and 7 and 8. The natural minor mode has half-steps between 2 and 3 and 5 and 6.
What a key designates to a performer is the scale in which all the diatonic notes of the piece lie. This is slightly more complicated in a minor key, because the pitch of the sixth and seventh scale degrees in a minor key can change depending on their harmonic context. The primary key of a piece of music is indicated at the beginning of the piece with a key signature.
A piece may change key at some point. This is called modulation. Modulation is sometimes done by just starting in the new key with no preparation - this kind of key change is common in various kinds of popular music, when a sudden change to a key a whole tone higher is a quite frequently heard device at the end of a song. In classical music, however, a "smoother" kind of key change is more usual -- this kind of key change is called 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 French horn, normally in the key of F, plays notes a major fifth lower than written.
Similarly, some instruments may be said to be built in a certain key. A brass instrument built in, say, 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, 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).