A key signature is a set of flat or sharps and is used to notify which music notes that will be altered with flats or sharps. The key signature is always written just after the clefs.
In the example above, the key signature indicates that all B, E and A notes will be altered in B♭, E♭ and A♭, because the three first flats in the order of flats are B♭, E♭ and A♭.
It is exactly the same as this below:
Or it can contain from one to seven flats:
Or from one to seven sharps:
The key signature can be null (no sharps or flats):
But a key signature can't be a mixture of sharps and flats:
You can see that the flats and the sharps are written on specific lines or space of the staff
Order of flats:
Order of sharps:
Order of flats and sharps on the circle of fifths
You can find the order of flats and the order of sharps on the circle of fifths, sharps are clockwise and flats are counterclockwise:
Major and minor scale with null key signature
There are only two scales with null key signature:
Key signature | Major scale | Minor scale |
![]() |
C Major | A minor |
Major and minor scales with sharp key signatures
There are seven major scales and seven minor scales with sharp key signature:
Key signatures | Major scales | Minor scales |
![]() |
G Major | E minor |
![]() |
D Major | B minor |
![]() |
A Major | F sharp minor |
![]() |
E Major | C sharp minor |
![]() |
B Major | G sharp minor |
![]() |
F sharp Major | D sharp minor |
![]() |
C sharp Major | A sharp minor |
Major and minor scales with flat key signatures
There are seven major scales and seven minor scales with flat key signature:
Natural key signature
Natural key signature is used to cancel previous key signature:
Changing key signatures
Before to change the key signature, previous one is canceled with naturals:
Finding key names from key signatures
Finding key names from key signatures with flats
With flat key signature, the last flat (♭) is always the degree IV of the major scale:
So with six flats, the key signature refers to G flat Major scale (or his relative minor key E flat minor):
Finding key names from key signatures with sharps
With sharp key signature, the last sharp (♯) is always the degree VII of the major scale:
So with seven sharps, the key signature refers to F sharp Major (or his relative minor key D sharp minor):
Examples of key signatures in famous works
Mozart, Introitus from Requiem
The Introitus from Mozart's Requiem has only one flat on key signatures for strings instrument and a null key signature for the basset horns in F (corni di bassetto) because it is a transposing instrument.
This royalty-free extract was recorded in 1951 by the Wiener Philharmoniker orchestra, conducted by Josef Krips (source, CC0 1.0 Universal (CC0 1.0)
Public Domain Dedication license).
Dvořák, From the New World, Largo
The movement Largo from the symphony n°9, also called From the New World Symphony, by Dvořák use a five flats key signature:

This musical sample was recorded in 2012 by The DuPage Symphony Orchestra's (source, CC BY-SA 3.0 US licence).
Chopin, Nocturne opus 15 n°2
The Nocture opus 15 n°2 by Chopin use a six sharps key signature:

(Royalty free musical sample performed by pianist Samson François in 1964, Creative Commons Zero 1.0 license, source)
You will notice that this work uses a key that is not widely used: F sharp Major. You will also notice the use of an anacrusis, double sharp (measures 5,10,12), trills (measure 7), sixteenth note quintuplets (measure 3), and sixteenth note septuplets (measure 10).
External links :
1 - https://www.dolmetsch.com/musictheory9.htm
2 - https://musicterms.artopium.com/k/Keysignature.htm