This was originally a response to a question on Quora.
Two notes sounding “good” together sounds like a very subjective statement. The songs we like and the sounds we like are incredibly dependent on our culture, personality, mood, etc.
But there is something that feels fundamentally different about certain pairs of notes that sound “good” together. All over the world humans have independently chosen to put the same intervals between notes in their music. The feeling of harmony we get when we hear the notes C and G together and the feeling of disharmony we get when we hear C and G flat together turns out to be part of the universal human experience.
Instead of from subjective notions of “good” and “bad”, scientists call the feeling of harmony “consonance” and the feeling of disharmony “dissonance”. Some cultures and genes of music use a lot more dissonance, but most humans perceive the same relative amounts of dissonance between pairs of notes.
The most consonant pairs of sounds are two sounds that are perceived as having the same “pitch” . In other words, the G key below middle C on my piano is so consonant with the G string on my guitar that they are said to be the same note.
Here is a recording of one second of me playing the G-string on my guitar. This graph shows the waveformof the sound, which is really just a rapid series of changes in the air pressure. Hidden within this waveform are patterns that our ears and brain perceive.
These waves then cause little hairs in our ears, called stereocillia, to vibrate, with different hairs vibrating at different frequencies. We perceive this sound through stereocillia in our ear that vibrate at different frequencies You can think of sound as the sum of different frequencies of vibrations and the hairs on our ears extract the amount of each frequency contained in the sound. We can also use math to extract the frequencies contained in the sound as I did below with something called a Fourier Transform.
We commonly think of a pitch, like a G, sometimes think of pitches as having a single “frequency” but sounds the graph shows that it’s are actually composed of various amounts of many different frequencies. In this case the lowest frequency of the string is 196Hz or 196 vibrations per second, but the string is also vibrating at double, triple, 4x times that. The lowest frequency is called the fundamental frequency. These higher frequencies are called overtones also known as harmonics when they are at simple multiples of the fundamental frequency. Instruments with vibrating strings like my guitar tend to vibrate at multiple frequencies where each frequency is a multiple of the lowest frequency – this is related to the physics of a string and it will be really important here.
Here is a one-second recording of me singing along to the G-string.
This audio waveform looks pretty different from the recording of my guitar, but when we look at the frequencies we can see that the two match up.
I added red dots to this frequency graph to highlight where the harmonic frequencies are and show the uniform spacing. Each dot is exactly 196Hz apart just like in the graph of the guitar’s frequencies.
The lowest or fundamental frequency of the recording of my voice matches the 196Hz of my guitar string shown on the previous graph. It’s amazing that we are able to make our voices harmonize so exactly without even thinking about it.
When I sing the G note along with my guitar my voice and my instrument are causing the same hairs in my ear to vibrate.
The fact that the frequency peaks or red dots are even spaced is a physical property of our vocal chords and comes from the fact that our vocal chords are essentially a long tube of air. Other instruments that are like longs tubes of air have the same property such as flutes, saxophones, horns and harmonicas.
When I play my guitar an octave higher I can make a harmony. A one second recording looks like this – again totally different from the previous two.
But when I look at the frequencies in its composition, they are exactly double the the frequencies of the low G string or me singing the low G. The red dots show the spikes from our earlier low G graph, the yellow dots are the frequency spikes from the high G sound.
So when you go an octave up, the same hairs will vibrate as with the lower octave, although not all of them. That’s what gives us the senseof two “notes” being the same even when they’re an octave apart.
Almost every culture that has a notion of an octavealso has a notion of a “fifth” or note halfway between an octave. Two notes that are a fifth apart are the most consonant of any two notes that are not the same.
The G note is the “fifth” of a C note. In western music, all of the most common chords with a C root have a G note in them. Why does a C and a G fit so well together? Here are the frequencies of playinga C on my guitar.
You can see in red the harmonics (or frequency spikes) of my G note and in yellow the harmonics of my C note. They don’t always line up but because my C note’s fundamental frequency (need to define this) is 3/2 of my G note they line up every 3rd harmonic of the C and every 2nd harmonic for the G.
The two notes that sound most consonant with a C are F and G, corresponding to the “perfect fourth” and “perfect fifth” intervalsfrom C. Why do they line up so well? We can look at how many of the harmonics line up.
You can see that G and F harmonics line up quite frequently with C’s harmonics at the bottom. But notice that G and F’s harmonics don’t line up with each other very frequently. So G and C sound very consonant and F and C sound very consonant but G and F sound much more dissonant. This is why it’s very common to play G and C together or F and C together but it’s unusual less common to play a C, G and F all at once.
All of the notes that are consonant with C have intervals with many harmonics overlapping as you can see on this bigger chart.
You can see here that C and E have lots of overlapping harmonics – C, E and G would be a C major chord. C and D# have almost as many overlapping harmonics and C, D# and G would be a C minor chord.
Some notes don’t correspond to any simple fractional interval, and those notes sound very dissonant. For example, playing C and F# together is extremely dissonant because there are no overlapping harmonics (the F# doesn’t quite even line up with 2/5 interval – for more on this see my answer to Why are there 12 notes?).
Some instruments don’t produce these overtones at simple multiples of the fundamental frequency. Drums usually don’t produce simple overtones because the vibrations travel across them in more than one dimension, which creates more complicated patterns. This is why you can’t typically hear drums harmonizing with each other even though they have a recognizable pitch.
We can stop there if we want to, but there are other psycho-acoustic effects that affect consonance vs. dissonance. One effect worth mentioning is the dissonance we here when two frequencies are close but not overlapping. .
When two notes are played close together the waveforms look roughly like this:
When we extend out the waveforms we can see that they move in and out phase.
Our ear hears the sum of the blue and the orange waveform which looks like this.
Or looking at a longer time period:
When the wave forms are in sync at the beginning they amplify each other, but as they get out of phase they subtract from each other. This creats theabeating sound that is very recognizabe if you’ve ever heard an out of tune piano or an out of tune guitar.
To western ears this sounds like an out of tune instrument. Some cultures incorporate this sound into their music. It’s pretty clear that this is an effect associated with dissonance. As other people have mentioned in their answers, two pure sounds with frequencies that are within a note or two are universally heard as dissonant.