Every piece of music is written in one key or another, such as the key of Bb or the key of E or whatever. The key signature at the beginning of a score tells what sharps or flats are being used in the song, and therefore what scale the song is based on.
Each piece of music contains a key signature. This is written immediately after the clef (on the staff) and is represented by a number of sharps (#) and flats (b). If you look carefully at the beginning of each line of music, you will see a group of sharps or flats (they are never used at the same time). These are placed individually on either a line or a space of the music staff and are placed on the notes they affect. In other words, if a sharp (#) is placed on the top line of the music staff, the note F is played as an F#. And all occurrences of the note F, whether on the top of the staff, the first space of the staff, or above or below the staff (marked by ledger lines), are played as an F#.
If a note that is dictated as sharp or flat by the key signature is to be played as natural, an accidental is placed before the note. For example, if an F (natural) is to be played in the key of G, an accidental has to be placed before it so it is not played as an F#.
The main purpose of the key signature is to limit the number of flats or sharps noted in the music. In other words, rather than placing a # by the note F every time it occurs in the music, it's much easier to indicate to the musician that all Fs are to be played as F#s. Without key signatures, written music would be cluttered with sharps and flats making it very difficult to read.
Here are some common key signatures and the notes they affect:
Key of C: No sharps or flats
Key of G: One sharp (F#)
Key of D: Two sharps (F# and C#)
Key of A: Three sharps (F#, C# and G#)
Key of E: Four sharps (F#, C#, G# and D#)
Key of F: One flat (Bb)
Key of Bb: Two flats (Bb and Eb)
Key of Eb: Three flats (Bb, Eb, and Ab)
Each key also has it's own relative minor. Though a major and its relative minor are similar in almost every way (their scales are the same though started in different places), they are thought of separately. A relative minor is named by the note that is a minor third down from the major (key). Another way to think of it is the relative minor is named by the sixth note in the major scale. For example, the note A is the six note of a C major scale, so an A minor is the relative minor to C. The use of a particular key's relative minor is very common in music and knowing them goes a long way in understanding a song's chord progression.
Here are some keys and their relative minors (keys).
The relative minor for C is A minor
The relative minor for D is B minor
The relative minor for A is F# minor
The relative minor for Bb is G minor
An experienced musician playing in a non-formal setting (not using written music) simply needs to know the key to a particular song to be able to play the chords and scales (melodies) for that song.
Finally, it is not unusual for a song to be written in more than one key - to change somewhere in the middle of a song. Such key changes can be a challenge for relatively new musicians.