The question of Keys, Key Signatures, and Modes comes up again and again.
Most explanations seem somewhat jumbled and/or full of technical description.
This is confusing, but over the years (decades?) it has become clearer to me.
It comes down to:
What note does the tune resolve too? (its Tonic Note)
What notes are in the scale of the tune? (how many Flats or Sharps)
Chords give clues, but they are subjective or 'symptomatic' as chord choices are not always universally agreed upon.
Why does it matter what the Key is?
Knowing what the Key is alerts melody players what notes, and chord players what chords, to expect (or not expect).
Yes, it is possible to play well without knowing what Key, Notes, or Chords you are playing, but most people recognize they have names; and it is easier to understand if everyone uses the correct names.
Tunes may also contain 'accidental' notes (not in the scale of the Key), but these usually stand out as different - the more one plays the more intuitive they are.
TRAD MUSIC ONLY USES 4 MODES?
Major, Mixolydian, Dorian, and Minor are the 4 Modes that virtually all Tradition (Western) Music use - Celtic, Old Time, Country, Blues, Bluegrass, Rhythm & Blues; and I believe Rock, and maybe Jazz too.
Tunes that are in a Major (Ionian) Key tend to be self-evident, however the mislabeling of tunes in Minor (Aeolian) and 'Modal' Keys (Mixolydian and Dorian) cloud that clarity. There are also 3 other 'Authentic' Modes (Phrygian, Locrian, and Lydian) that rarely come up.
There also happen to be 7 "Plagal (or Hypo-) Modes" where tunes resolve to the fourth note of the scale, instead of the first (or last) note. These are typically used in 'Renaissance' music, but commonly are likely never noticed that there is a 'different' name for the scale of same notes. For example the Hypoionian uses the same notes as the Ionian (Major), but the fourth note is the tonic.
HOW TO DETERMINE THE KEY?
1) determine what note a tune (or each of its parts) resolve to - its Tonic Note.
2) determine what notes are played (comprise the scale - how many sharps or flats) - its Key Signature
3) match the Tonic Note and Key Signature with the appropriate Key Name.
KEY NAME is the Tonic NOTE followed by the MODE:
Start by presuming the note it resolves to is a Major Key, and how many flats or sharps would that be?
C Major = 0b / 0#
G Major = 1#
D Major = 2#
A Major = 3#
E Major = 4#
B Major = 7b / 5#
Gb (F#) Major = 6b / 6#
Db (C#) Major = 5b / 7#
Ab (G#) Major = 4b
Eb (D#) Major = 3b
Bb (A#) Major = 2b
F Major = 1b
If less sharps (or more flats) are used, how many?
0 fewer, then Major (Ionian)
-1# (or +1b), then Mixolydian
-2# (or +2b), then Dorian
-3# (or +3b), then Minor (Aeolian)
-4# (or +4b), then Phrygian
-5# (or +5b), then Locrian
-6# (or +6b), then Lydian
If a tune resolve to A:
A Major has 3#s
but Key signature (or actual #s in tune) is 1#
then A Dorian
The attached chart may make it clearer.