Key signatures: what those sharps at the start mean
Those sharps at the start of a piece exist for one reason: to save you writing the same accidental forty times.
At the start of a piece, just after the clef, you will often see a cluster of sharps or flats. That is the key signature, and it exists for one reason: to save ink.
This is step four of the music theory path. It assumes you can already read notes on a staff.
What it is actually doing
If a piece is in the key of D, almost every F in it will be an F sharp and almost every C will be a C sharp. Writing a sharp symbol next to every single one would be exhausting to write and exhausting to read.
So instead you declare it once. Two sharps at the start, positioned on the F line and the C space, and from then on every F and every C in the piece is sharp unless something says otherwise.
The order is always the same
Sharps always appear in this order: F, C, G, D, A, E, B. Flats appear in exactly the reverse: B, E, A, D, G, C, F.
This is not arbitrary and it never varies. A piece with three sharps has F sharp, C sharp and G sharp — always those three, never a different combination. Once you know the order, counting the symbols tells you exactly which notes are affected.
Working out the key from the signature
For sharps, look at the last sharp in the signature and go up one semitone. Three sharps ends on G sharp, so the key is A major.
For flats, look at the second-to-last flat. That is the key. Three flats gives you E flat major. The one exception is a single flat, which is F major — worth simply memorising.
Major or minor?
Every key signature serves two keys, one major and one minor. Two sharps is either D major or B minor. The signature alone cannot tell you which.
The music tells you. Look at which chord the piece starts and ends on, and listen to whether it sounds bright or dark. That is usually enough.