Why is it important to know what key a song is in? I am still learning about key signatures but not a single person mentions the importance of this.
Why is it important to know what key a song is in?
Sometimes it is important, and sometimes it isn't!
If you're singing along to a song by ear, then it may not be important to know the key, unless you have perfect pitch. (It might be useful to know if a particular song has been transposed, in case that's better - or worse - for your singing range).
If you're playing a song by ear on an instrument, knowing the key might help you locate the notes on the instrument - you can think about the notes in the scale when you're playing. (Even when players play using patterns, rather than thinking about note names, they're still probably 'spotting' the notes in the scale).
If you're playing a song from a score, then you at least need to know the key signature, otherwise you don't actually know which notes the dots refer to. Having an idea of the key can also help you think about the structure of the piece.
However, remember that "what key a piece is in" isn't necessarily a fact - it might just be an opinion or a perspective. This is another reason why I don't think it's always true to say "It's important to know what key a song is in". It may well be useful for you to have a way of thinking about the tonality of the piece, but "the key" might not be obvious, or for some pieces, it might not be such a helpful idea.
Edit - just to be clear (and as other answers have pointed out), knowing the key signature isn't enough to know the key. As Michael says, knowing the key signature plus the tonal centre will tell you the key - unless you're at a point in the piece where there are at a lot of accidentals, such that the key signature isn't a good fit for the key in that part of the piece!
(In fact, this could be another way in which 'knowing the key' is useful : knowing what key you've modulated to, so that you're not surprised to see lots of accidentals!)
A piece in a key will far more often than not use the diatonic notes from that key. Those notes are the ones that constitute the scale that belongs to that key. For example, C major contains the notes C D E F G A and B. There are no ♯ or ♭ involved. Therefore the key signature contains no ♯ and no ♭. Sometimes there are times when one or more of the other 5 notes get themselves involved, and at that time, there will have to be what's called an accidental, to show that a diatonic note, belonging to C major, needs to be played on a different pitch.
It might still be an F note, but it needs to be F♯, or a B note, but needs to be B♭. This tells the reader that something a little unusual is happening. It is the same in A major, where the key signature is 3♯. If one of those needs changing, a natural sign will be in front of the changed note. Knowing what notes are already 'available' normally gives the reader more insight.
If I'm playing with a band that I don't normally join in with, the most important factor for me is THE KEY. And that's busking or reading! That gives me more clues than anything else available at the time (unless I'm drumming, when I couldn't care less..!). That's because the key information reveals which chords and notes are going to be mainly played. Without that info, I might as well pick about aimlessly until I find a note or two that sort of fit. Armed with the key, I can support from 1,2,1,2,3,4.
EDIT: it is so important that in some of the bands I play in, it's the only information we start with, by being given the signing for the key for the following song - using number of fingers to signify next key - e.g. three fingers pointing up for A or three pointing down for E♭.
As a beginner, if you're playing a piano piece from sheet music then it's not necessarily important to know what key the piece is in. You can look at the key signature as a shorthand device to help you know which notes to play.
As you become more familiar with songs in different keys, however, you'll start thinking about shapes more than notes. For example, an A major triad and a D major triad have the same shape, because only the middle note is a black note, while E-flat major and A-flat major have the same shape because only the middle note is a white note. Similar considerations apply to scales as well as chords.
Of course, each key has a set of chords and scales that are used more frequently. When you develop the skill of being able to look at the key signature and identify the piece's key before you start playing, that information will help you (mostly subconsciously) prepare yourself for the shapes of the chords and scales you're likely to encounter in the piece.
Let's assume a key signature of two sharps.
If someone has zero understanding about keys and harmony, the key signature (and accidentals in the score) will simply be mechanically applied. When you see a
F notated the key signature tells you to play them as sharps.
So, you may be thinking 'what else is there to know beside that?'
The important thing you will be missing is not knowing what the tonal center of the music is and how harmony works in relation to that tonal center.
For example, with a key signature of two sharps. That could be two possible keys:
D major or
B minor. Let's suppose the key is
As the music moves through various chords, those chords will have relationships to
D major as the tonal center. We call
D the tonic - that's sort of the 'home' or goal of the music. The
D major triad is the tonic triad. Other chords like
E minor or
A dominant seven have names to describe their role or function. In
D major the
E minor chord is the supertonic and
A dominant seven is the dominant. In music using the major/minor keys just about every chord has some kind of name like those and the way they work usually follows established patterns.
Chord progressions like:
supertonic dominant tonic or
tonic subdominant tonic are very common. There are many other patterns. But the important thing - the thing that addresses you question - is these patterns are identified by their relationship to the tonal center of the key.
Instead of just mechanically hitting the right notes with sharps or flats from the key signature applied, understanding the key and the key's harmonic patterns give you a deeper understanding of how the harmony functions.
One additional thought: a piece of music often changes key. So don't just stop at the key signature. Be aware of key changes that might happen within the piece. That becomes important for understanding the structure of a lot of music. And as @topomorto points out, a piece might not be in a key. With that in mind you can expand the idea. You don't want to just learn about keys, but about tonality generally. That knowledge helps you understand the structure of music.
Perhaps if you're playing sheet music it's not that important. You play the notes as written and that's it.
However, if you're into other genres where improvisation is part of the performance (jazz, blues, sometimes rock), then knowing the key is essential. It tells you where the tension centres around, so you can build up the tension (perhaps by playing a V dominant chord) and then resolve it by returning to the key fundamental.
You will need some additional information to improvise effectively, not just the key: what is the harmony (chord sequence), etc. But that's a bit more advanced I would say.
The fact is, you can't just look at a key signature and know what key the piece is written in. You have to look at (or play) the notes of piece in order to determine the key.
On the other hand, once you see the key signature, you can say the music is probably written in one of two keys: the major key with those sharps or flats or the minor key with those sharps or flats. And you usually can tell which one of those is the key by listening to just part of the piece; a piece in a major key will "sound major" no matter which of the major keys it was written in.
When you are just starting out this may not help you much at first. But every key has a tonic (the "home" note) and there are relationships between the notes that are determined by how far each note is from the tonic. When you play a piece in a major key and then play another piece in another major key, all those relationships exist in both pieces, but when you play the second piece the places on the keyboard where each of those relationships apply will have shifted left or right and some of the notes will move onto black keys (or off them).
If that's all too obscure, just play some scales. That's good practice for playing piano music in general. Now if you have a piece that you know is in a major key (perhaps because you've heard it) and you see that the key signature has two sharps (F sharp and C sharp), where do you start playing the scale? You start on a D.
You could start the scale on a different note, but it would sound foreign to the piece you want to play. (Though not nearly as foreign as if you played different sharps or flats.)
To be honest, that may be about as much as I got from the relationship between signature and key as a piano student. If my teacher asked me to play a D major scale, I knew I needed F sharp and C sharp. If I saw a piece with F sharp and C sharp in the signature that sounded "major" and I wanted to play the scale that sounded the "same" as the piece, I would play D major.