Notes that sound good together when played at the same time are called consonant. Chords built only of consonances sound pleasant and "stable"; you can listen to one for a long time without feeling that the music needs to change to a different chord. Notes that are dissonant can sound harsh or unpleasant when played at the same time. Or they may simply feel "unstable"; if you hear a chord with a dissonance in it, you may feel that the music is pulling you towards the chord that resolves the dissonance. Obviously, what seems pleasant or unpleasant is partly a matter of opinion. This discussion only covers consonance and dissonance in Western music.
Of course, if there are problems with tuning, the notes will not sound good together, but this is not what consonance and dissonance are about. (Please note, though, that the choice of tuning system can greatly affect which intervals sound consonant and which sound dissonant!)
Consonance and dissonance are subjective qualities of relationship that we assign to music intervals. A quick review of intervals might be helpful if you're approaching the subject for the first time. A dissonant interval can be described as being "unstable" or demanding treatment by resolving to a consonant interval. A consonant interval is one that is stable and does not demand treatment. However, dissonance in itself is not an undesirable thing; we use dissonance to provide the "spice" to music. Thus, there is a hierarchy of consonant and dissonant intervals. (Chords having dissonant intervals are themselves considered dissonant).
Note that this distinction depends entirely on musical context. As such, a sonority which is consonant in one context where it does not seem to demand resolution (say, major 2nds in a Debussy prelude) may sound harsh or out-of-place in a different context where it must be resolved (the same major 2nds in a Bach fugue). In this article, we will be using the terms "consonant" and "dissonant" as they are understood in common-practice tonal music, as is the tacit convention when speaking of consonance and dissonance in general.
Consonance and dissonance refer to intervals and chords. The interval between two notes is the number of half steps between them, and all intervals have a name that musicians commonly use, like major third (which is 4 half steps), perfect fifth (7 half steps), or octave.
An interval is measured between two notes. When there are more than two notes sounding at the same time, that's a chord. Of course, you can still talk about the interval between any two of the notes in a chord.
The simple intervals that are considered to be consonant are the minor third, major third, perfect fourth, perfect fifth, minor sixth, major sixth, and the octave.
Figure 1: Consonant Intervals.
In modern Western Music, all of these intervals are considered to be pleasing to the ear. Chords that contain only these intervals are considered to be "stable", restful chords that don't need to be resolved. When we hear them, we don't feel a need for them to go to other chords.
The intervals that are considered to be dissonant are the minor second, the major second, the minor seventh, the major seventh, and particularly the tritone, which is the interval in between the perfect fourth and perfect fifth.
Figure 2: Dissonant Intervals.
These intervals are all considered to be somewhat unpleasant or tension-producing. In tonal music, chords containing dissonances are considered "unstable"; when we hear them, we expect them to move on to a more stable chord. Moving from a dissonance to the consonance that is expected to follow it is called resolution, or resolving the dissonance. The pattern of tension and release created by resolved dissonances is part of what makes a piece of music exciting and interesting. Music that contains no dissonances can tend to seem simplistic or boring. On the other hand, music that contains a lot of dissonances that are never resolved (for example, much of twentieth-century "classical" or "art" music) can be difficult for some people to listen to, because of the unreleased tension.
Figure 3: In most music a dissonance will resolve; it will be followed by a consonant chord that it naturally leads to, for example a G seventh chord resolves to a C major chord, and a D suspended fourth resolves to a D major chord. A series of unresolved dissonances, on the other hand, can produce a sense of unresolved tension.
Why are some note combinations consonant and some dissonant? Preferences for certain sounds is partly cultural; that's one of the reasons why the traditional musics of various cultures can sound so different from each other. Even within the tradition of Western music, opinions about what is unpleasantly dissonant have changed a great deal over the centuries. But consonance and dissonance do also have a strong physical basis in nature.
In simplest terms, the sound waves of consonant notes "fit" together much better than the sound waves of dissonant notes. For example, if two notes are an octave apart, there will be exactly two waves of one note for every one wave of the other note. If there are two and a tenth waves or eleven twelfths of a wave of one note for every wave of another note, they don't fit together as well.
\(\bullet\) The perfect fifth and the perfect octave are considered perfect consonances. The unison is a consonance insofar as it can be considered an interval at all (many say it cannot).
\(\bullet\) The major third and sixth, as well as the minor third and sixth, are imperfect consonances.
\(\bullet\) The perfect fourth is dissonant in some contexts but consonant in others (see below). Specifically, the perfect fourth is dissonant when it is formed with the bass note of any sonority.
\(\bullet\) The perfect fourth is considered dissonant in common practice music when not supported by a lower third or fifth (but see below).
\(\bullet\) Major and minor seconds, sevenths, and ninths are dissonant. Composer/theorist Vincent Persichetti, in his book Twentieth-Century Harmony, classifies major 2nds, minor 7ths, and major 9ths as "soft dissonances," whereas minor 2nds, major 7ths, and minor 9ths are "sharp dissonances."
\(\bullet\) The tritone (an augmented fourth or diminished fifth) is dissonant. In the Middle Ages and Renaissance, it was known as diabolus in musica because the perfect fifth was considered to be a reflection of the divine, and the tritone falls just short of a perfect fifth. [Note for the advanced: Technically, it is not proper to refer to the diminished fifth as a "tritone." The word "tritone" refers to "three whole-tones," the distance represented by the tritone. This means that the augmented fourth, which comprises three whole-tones, is a true tritone, while the diminished fifth, because of its accidental-spelling, is not made up of three whole-tones and is therefore not a tritone. However, it is acceptable as an informal convention to refer to the diminished fifth as a "tritone."]
\(\bullet\) In Jazz, the minor 9th is often considered too dissonant for practical use. This is the basis for some notes being called "avoid notes", typically the 4th of a major scale - it sounds dissonant because it forms a minor 9th with the 3rd. Other "avoid notes" are the minor 6th in aeolian mode, or the minor 2nd in phrygian mode. Some chords are typically voiced to avoid a minor 9th (musicians invert the interval and play a major 7th instead). For example, in a Cadd11 chord (see Complete List of Chord Patterns), there is a minor ninth between the third, E and the eleventh F. If the F is played below the E, the interval becomes a major seventh, which is less dissonant.
The perfect fourth is the inversion of the perfect fifth. In common practice music, it can be both consonant and dissonant: in this case, it has a need for resolution when unsupported by lower notes, in which case it is dissonant even though it sounds as "good" as the fifth. The fourth is always consonant when supported by a lower third or perfect fifth, for example, E-G-C-E is consonant, but G-C-E is dissonant. In more contemporary music, many consider the fourth to always be as consonant as the fifth.
In Medieval music, the perfect fourth was even considered a perfect consonance, as the perfect fifth and the octave. However, this attitude no longer prevails.