In musical notation, a key signature is a set of sharp or flat symbols placed together on the staff. Key signatures are generally written immediately after the clef at the beginning of a line of musical notation, although they can appear in other parts of a score, notably after a double barline.
Copying from Wikipedia: The convention for the notation of key signatures follows the circle of fifths. Starting from C major (or equivalently A minor) which has no sharps or flats, successively raising the key by a fifth adds a sharp, going clockwise round the circle of fifths. The new sharp is placed on the new key’s leading note (seventh degree) for major keys or supertonic (second degree) for minor keys. Thus G major (E minor) has one sharp which is on the F; then D major (B minor) has two sharps (on F and C) and so on.
Similarly successively lowering the key by a fifth adds a flat, going counter-clockwise round the circle of fifths. The new flat is placed on the subdominant (fourth degree) for major keys or submediant (sixth degree) for minor keys. Thus F major (D minor) has one flat which is on the B; then B♭ major (G minor) has two flats (on B and E) and so on.A key signature designates notes that are to be played higher or lower than the corresponding natural notes and applies through to the end of the piece or up to the next key signature. A sharp symbol on a line or space in the key signature raises the notes on that line or space one semitone above the natural, and a flat lowers such notes one semitone. Further, a symbol in the key signature affects all the notes of one letter: for instance, a sharp on the top line of the treble staff applies to F’s not only on that line, but also to F’s in the bottom space of the staff, and to any other F’s.