The astonishing feature of the "ear" (meaning the whole process of hearing from the sound entering into the ear drum to the brain intereting those sounds) is that this whole suite of sounds is melded together into a single note, a single pitch somehow.
The ear drum's motion pushes back and forth on a series of little bones which finally push and pull on a fluid filled chamber, called the cochlea. That chamber is a long (about 3 cm) tapered chamber which is divided into two longitudally but a couple of thin membranes highly populated by nerve cells. These nerve cells respond to those memberanes being bent, and convey that information to the brain. This membrane is tuned, so that if a sound of a certain frequency comes into the innter ear, one a tine piece (less than a millimeter in length) vibrates to each specific frequency in the sound. Thus each of the harmonics of a note produce motion in different parts of the basilar membrane, and the nerves send to the brain information from each of those parts separately. Thus the brain receives, not something which is a replica of the sound itself, but rather separately with respect to each of the harmonics of the sounds coming in.
Thus one would think that the brain would report on all of those frequencies, and one would hear any sound, not as a single pitch, but as a whole cacophany of sounds. But that is not what happens. Instead the brain somehow reassembles the sounds into a single pitch experience, in which, if you listen really carefully, and with training, one can just about hear a few of separate sounds.
It does so even in the presence of other sounds. Thus a violin note does not split up into its separate harmonics if one has someone talking in the foreground or even has other instruments playing.
If one plays two notes a fifth apart (frequency ratio of 3/2) then the the two notes together tend to merge together. The frequencies in the combination has frequencies 1 3/2 2 3 3 (4 1/2) 5 6 6 .. Ie one has Ie, one again has a regular series of frequencies, which the brain tends to regard as a series which it should meld together into one experience.
The fourth has a similar series
1 4/3 2 8/3 3 4 4 5 (5 1/3) 6 (6 2/3) 7 ...
which are all multiples of 1/3. Again, this regular sequence somehow makes the brain think that it should unify all those notes into one experience. Similarly for a major third, and a major sizth.
If one happens to have a fifth which is slightly off tune, then one will get beats between the harmonics which the two series have in common. (The double 3 or double 6 will beat with each other. ) These beats will make the sound of the two notes together feel non-pefect. The brain is trying to meld the notes together while the beats get in the way of that. While the ear is willing to forgive some disharmony in the two note together, it gets less and less willing to the more harmonics the two notes share. Thus the octave, in which all of the harmonics of the higher note are identical to harmonics of the lower note, the ear is particularly intolerant of a mistuning. The fifth is next, the fourth is next, then the third and the sixth, etc.
It is ironic that even now why that is true is still somewhat of a mystery. We do not understand why and how the human mind melds together certain sounds into one single exerience, instead of hearing it as a cacophany. But along the way, that insight of Pythagoras resulted in a steady worry in exactly the people who were most important to our current scientific understanding of the world. And it led to the discovery of what sound is, of the prevelance of harmonics hidden in each note that we hear, and in the whole study of how the brain interacts with the physical world.
One of the key features of the human hearing system is that it is the most sensitive of the senses we have. A trained human can differentiate between sounds which are closer than one part in 10000 of each other and does so over about 10 octaves (another factor of a thousand.)Thus we can differentiate between about 1 to 10 million different sounds just in terms of frequency.