I'm wondering if it is common for people to accurately recall not only the melody of a song they know, but also the key. I've recently done a small experiment where I asked a few of my friends to hum the beginning of some popular tunes, like the Star Wars theme. They hummed it somewhat correctly - the melody was ok, but they didn't all start from the same note. Also, when I played the songs on my phone, it turned out all of them were signing in the wrong key. Is that a coincidence, or is it actually not that common for people to accurately recall the key? Of course I'm asking about those who were not musically trained.
Not many people can actually sing acapella in the key required.(Without being given a start note/chord). They may well sing the tune, in a different key (maybe +/- a m3) but to actually sing in the original key - unlikely. I suppose those with absolute pitch (who can remember or know what the 'proper' key is), will be able to do it.
Even those musically trained will not get it right all the time. Musical training doesn't encompass feats such as this. I used to sing/play with a guy who would start a song - any song - and 9 times out of 10 would be in the key we always played the song in, but I never worked out how it happened - and he didn't know either. He wasn't musically trained - just was a great singer. But that doesn't really help with an answer!
I was going to mention 'Happy Birthday', but as that can be sung in several different keys, (and does so at parties frequently, even when everyone is singing!!), so even a well-known song can't be relied upon.
Most people can't do it.
Absolute pitch reference [perfect pitch] is quite rare - just as rare as people who 'couldn't carry a tune in a bucket'.
Pitch reference, the same as most skills, is on a bell-curve. Most people are in the middle - they can kick a ball in the general direction of a goal, or sing a song if it's not too hard... just don't ask them to score a penalty in the World Cup Final, nor get the exact pitch reference for any song.
Practised singers, even those without perfect pitch, can 'feel' the reference in their throat. I can do it & I really don't have anything close to perfect pitch - I just know when a song I sing frequently is 'right' or 'wrong', by the 'feel'.
Even studies on the Levitin Effect, a phenomenon that posits that people can tend to accurately recall the key of a familiar melody, discover that at least a significant minority of people cannot produce this effect (see here for an example), and this effect has been found to be hard to reproduce. So, I'd say that it's actually not that common for people to accurately recall the key.
You are asking for the well known and understood difference between "Absolute pitch" and "Relative pitch" ("słuch absolutny" and "słuch względny" in Polish).
Some people's heads are wired to understand each note in a melody as a separate entity (absolute pitch), but most people's brains understand melody as a series of differences between pitches.
Contrary to what many people think, "absolute pitch" is not really "better" than "relative" - it's different (in this sense, the name "perfect pitch" used in English is quite misleading). People with perfect pitch cannot easily transpose the tunes they know, especially if transposed by less tham a semitone (some will have problems singing to a slightly detuned guitar). Also, you can have perfect relative pitch (hear intervals with minute precision) or a lousy perfect pitch (hear the exact pitch, but not very well)
(Not quite an answer to the original question, but in support of all the other answers...)
As someone with absolute pitch, my experience is pretty much in line with what all the other excellent answers have said. And yes, it's rare, although it seems we don't know exactly how rare.
If it's a common song (like "Happy Birthday") with no one official recording, then there's no key to remember in the first place, and I can sing/play it in any key.
If I've learned the song from a single recording (or by playing/singing from written music in a particular key), then I know it in that key. I know "Let It Be" in C and "Eleanor Rigby" in E minor.
Some songs I can transpose easily, and some I can't - I don't fully understand why. I can sing "Let It Be" in any key, but I can't do "Eleanor Rigby".
Even if I can manage to transpose the melody, the song "feels" very different if I'm trying to play it in my head in any other key. In the original key, I get a sense of the harmony, accompaniment, and overall texture of the recording I'm familiar with. In any other key, all that stuff vanishes and I'm left with just the melody.
If I'm trying to remember a song I haven't thought about in a long while, I might have the key off by a step or so, just like I might not remember the melody or the words quite right. But I can tell something is wrong until I "settle into" the right key.