What we call "octaves' are the phenomenon of a 2:1 frequency ratio. Our perception of octaves as "the same note" seems to be a deeply embedded sense. No one questions the practice of giving two different notes the same name when they are one octave, two octaves, three octaves or more apart from each other.
Why is this?
What is it about this 2:1 ratio that we sense as "the same"?
Consider the effect of clapping at a steady speed, then doubling the speed of clapping. Or have another person clap along with you but at double the speed and stay in sync.
You'll notice that the claps will perfectly align every other beat, so that the lower speed clap is effectively embedded in the faster one. The ratio of the frequency of your clapping is the same as an octave. This provides a clue as to the reason octaves are perceived as the same.
In the ear, sound is processed by setting in motion some 15,000 tiny specialized hair cells, each of which has between 50 and 300 filaments projecting from it, called stereocilia. These hairs are contained in a fluid filled spiral shaped structure called the cochlea. The hairs and the stereocilia in each ear resonate with specific frequencies and transmit that information to the auditory cortex of the brain which has specialized neurons for each frequency and range of frequencies. So your brain is always sensing the frequencies of every sound and is able to recognize the ratios between those freq
uencies.
Exactly how the brain can calculate the precise frequency ratios between all the pitches we hear is quite complex and still somewhat mysterious, but it is probably connected to the brain's ability to sense time as sequential events based on it's own brainwave frequencies and the embedding of resonations in its neural network. Regardless of the precise mechanism, it's clear that we are very good at perceiving the ratios between notes regardless of their absolute pitch.
In other words; if you hear a melody in one key, and then the same melody in another key, you recognize it as "the same" because you recognize the ratios between the frequencies of every note in the melody, rather than relying only on the absolute pitches of the individual notes. The melody of the song Happy Birthday in the key of C would be: