The key signature indicates which notes of the scale should be flattened and sharpened in a given piece. It lists those flats or sharps that define the main key of a piece, and if a piece modulates the key signature can change.
You may find the following links helpful:
Working out the key of a passage
a more basic introduction to key signatures from the connexions project