When we say we are playing in a certain key, we are talking of the root note to which all other notes will relate.
It is also the note that the piece of music will resolve to at the end (cadence), or any other place where a resolution is required.
To help remember which notes are diatonic to a key, we use the Circle of Fifths. It is used to portray the relationship between the keys.
The key of C has no sharps, so it is the starting point. We then know that this key uses the notes C, D, E, F, G, A and B.
If we go up a fifth, to G, we will get one sharp in the key of G (F#). If we go up another fifth (this time the fifth of G) to D, we get two sharps (F# and C#).
As we go up by fifths, the key will add one more sharp to the diatonic scale. The notes that will sharpen will progress as follows:
The inside circle is going up by fourths (anti-clockwise), starting from C, which has no flats.
As we go up by fourths, the key will add one more flat to the diatonic scale. The notes that will flatten will progress as follows:
Each major key also has a relative minor key (shown in brackets) which will contain the same notes as the major, and starts on the 6th note of the major scale. A major key and it's relative minor key, therefore, are very closely related and can often be used interchangeably.