The unit of measure used to determine the distance between musical pitches is the interval. Since there are seven letters in the musical alphabet, there are seven basic musical intervals. Each interval can be lowered or raised by a half step (flat or sharp) to create alterations, but there are seven basic labels as seen below.
Interval numbers do go beyond seven, but they are basically repeats of the first seven intervals displaced by one (or several) octave.
There are two types of consonant intervals, perfect and imperfect. Perfect intervals portray the purest form of musical consonance. Imperfect intervals still sound harmonious, but they are not as pure as perfect intervals. The unison, fourth, fifth and octave are perfect intervals. The third and sixth are imperfect intervals. This leaves the second and seventh as the dissonant intervals.
You may think that music which contains only consonance would be ideal since the harmonies all blend well with each other. However, a key element of all forms of entertainment is conflict and resolution. Great books, television shows, plays, movies and sporting events all contain this. A question or challenge is presented and the characters struggle to conquer that challenge. There is usually a climactic moment toward the end of the event where the conflict reaches a peak and is finally resolved. Whether it is a murder mystery in which the killer if finally found or a football game that ends with the winning field goal, all people look for this element of conflict and resolution in entertainment.
In music, dissonance is used to create conflict. Harmonies and chord can be combined in ways that build tension. The tension is then released with consonant harmonies. Too much dissonance can be considered distasteful by the audience. In the same way, too much consonance can be considered boring. Of course there is no absolute solution since music appreciation is subjective. However, the majority of listeners within a given genre of music will agree on the general boundaries of good and bad music. The key to great composition is knowing those boundaries and knowing how to utilize consonance and dissonance in a way that is tasteful and interesting.
Understanding this concept is advantageous for performers as well as composers. While performing music, it is important to know how the conflict and resolution unfolds throughout the piece. This better enables the performer to express these aspects of the music. A composer uses conflict and resolution to gain the audience's attention. A performer can either accentuate or diminish this component through his or her performance.