Major key signatures indicate what flats or sharps used in a composition to make the piece to sound major. The key signature starts at the beginning of each staff and use either sharps or flats. Writing in a major key usually prevents the need to use any accidentals other than those written in the key signature.
Minor key signatures make it possible to read a piece in a minor key without having to wade through several accidentals. However, with minor music, it is usually not possible to avoid all accidentals. The seventh scale degree of harmonic minor music is raised a half step. This means that in the key of D harmonic minor, there will be a C# accidental in the music that is not indicated in the key signature.
Key signatures use a particular order when placing the accidentals in the key signature. When using flats, the order reverses to B, E, A, D, G, C and F. Flat key signatures make it possible to avoid having to use an alternative sharp key signature that may be more complicated. For instance, C# major has seven sharps in it; however, by using Db instead of C#, you can reduce the number of accidentals since Db only has five flats.
The order that sharps appear in the key signature are F, C, G, D, A, E and B. This means that if the last sharp in the key signature is a D, you know without even looking at the other sharps that F, C and G are also included in the key signature. Like flats, sharp key signatures make it easier to read music otherwise littered with accidentals. Most string music uses sharps since sharps are easier for a string player to read due to the nature of the instrument.
Perhaps the most important reason for a key signature is that in tonal music they help to create a pull towards certain strong pitches. In the key of C Major, the C will be the focus of a composition. The melody will begin and end on a C and other pitches in the piece will serve to create a pull back towards C. Tonal music is all about finding your way back to the home pitch. Key signatures make it possible to ensure that C is the strongest note and other pitches are subservient to the tonic, or first scale degree.