In music, a key is a group of notes and chords that revolves or gravitates around a single chord, known as the tonic. That attraction is created by the presence of the major 7th, also called the leading-tone: the last note of the scale that is just a half step away from the tonic (the first note). A key also assigns functions to each of its chords: much like in a sentence each word has a specific function (verbs, nouns, and so on), chords in a musical phrase also have functions that give meaning to the group.
The basic difference between them is that the 3rd note in the major scale is a major 3rd, whereas on a minor scale it is a minor 3rd. The 6th and the 7th are also different: major on the major scale, minor on the minor scale.
Two keys are enharmonic when their notes share the same pitches but are named differently. Not only keys can be enharmonic, but also chords or single notes. For example, the note C is enharmonic with B#: on the piano, you will find them both in the same key, but their names are different.
The Key Signature is where the composer will indicate which notes (if any) are sharps or flats. That indication follows a specific order and it tells you what is the key the piece. You can find the Key Signature located at the beginning of the score, right after the clefs.
For every major key, there is one other minor key that shares the exact same notes and vice-versa: each major key has a relative minor and each minor key has a relative major. For that reason they both share the same key signature, having the exact same sharp notes or flats notes in it.
For every major key, there is one other minor key that shares the exact same notes: each major key has a relative minor and each minor key has a relative major. For that reason they both share the same key signature, having the exact same sharp or flats.
On major keys, the relative minor is the scale starting on the 6th note above the tonic. For example, in C major the relative minor will be A minor (C - D - E - F - G -A).
On minor keys, the relative major is the scale starting on the 3rd note above the tonic. For example, in E minor the relative major will be G major (E - F# -G).
The closely related keys are those keys that have only one note different from the main key, therefore are very similar and considered to be close. The more steps you move in either direction on the circle of fifths, the more distant the keys get from the main key (the more different they will sound).
Why does this matter?
In most pieces you can expect to see the closely related chords much more often than any other ones, that is why it is helpful to know where they are in any given key. For example, in the key of F major, one should expect to see chords such as G minor, A minor, Bb major, and C major.
If a piece modulates (changes keys), chances are it will move to one of its closely related keys. This is because you just need to change one note to move into the new key, making it easier and seamless. It is not at all uncommon to modulate to more distant keys, of course, but it is more difficult to do that. Composers will often move gradually, going from one closely related key to the next, until they reach the distant new key.
Keys are a set of chords that follow a strict pattern. A musical scale has 7 notes and, to create the key, we build a triad (a 3-note chord) over each note of the scale. The major and minor scales have a specific set of intervals, which leads to the patterns we use most of the time.
Music that is centered around a tonic (the first chord of a key) is called tonal music. In order to establish its tonal center, a scale needs three intervals: a perfect 4th, a perfect 5th and a major 7th (also called leading tone). The perfect 4th and 5th give the scale stability, for those are the two most consonant intervals after the octave. Both major and minor scales have these intervals, so we don't need to change them. The major 7th (last note of the scale, only a half step before the first) is also important because it creates the tension needed to establish the home key. As the nickname suggests, it leads our ears back to the home key. This interval is minor on minor scales and that is the reason why we raise the 7th on minor keys, making it a major 7th.
The 3 main groups
If we have those 3 intervals in place, the home key can be established and the chords will then have behavior. That behavior, at the most basic level, has to do with moving away and moving back to the home key. The 3 main functions a chord can have are Tonic, Subdominant, Dominant. These functions are based on the 1st, 4th and 5th degree of the scale, respectively. Why these? Because they are the ones that never change, are consonant and give stability to the key.
Important!This is not to be confused with the names of each degree in a scale, where the notes are labled: tonic (1), supertonic (2), mediant (3), subdominant (4), dominant (5), submediant (6), subtonic (b7) and leading tone (7). The names of each function are derived from the labels of the first, fourth and fifth degrees in the scale.
At the most basic level, the chords in the Tonic group establish the home key; the chords in the Subdominant group move away from the home key and chords in the Dominant group move back to the key.
Assigning a chord to its group
We assign the chords into each group by similarity. At a fundamental level, a chord has 3 notes (also referred to as a triad). Two chords with 2 notes in common will belong to the same functional group. Our ears will perceive them as similar and they will have similar behavior inside their key. How strong that behavior is will vary between chords.
For example, in the key of C major the 5th degree is G. Therefore, the dominant group in this key will start with G major (G - B - D). The other chords in this key that have 2 notes in common with G major are E minor (E - G - B) and B diminished (B - D -F). For that reason, all 3 chords will be able to behave as dominants in this key. How strong that behavior is will vary between chords: the G major is the strongest, closely followed by the B diminished and E minor will be the weakest dominant chord of all three in this example.