Roughly 2,500 years ago, Pythagoras observed that objects, such as the anvils he purportedly studied, produced harmonious sounds while vibrating at frequencies in simple whole-number ratios.

More complex ratios gave rise to more dissonant sounds, which indicated that human beings were unconsciously sensitive to mathematical relationships inherent in nature. By showing that the world could be described mathematically, Pythagoras not only provided an important inspiration for physics, but he also discovered a particular affinity between mathematics and music—one that Gottfried Leibniz was to invoke centuries later when he described music as the “unknowing exercise of our mathematical faculties.”

For a thousand years, Western musicians have endeavored to satisfy two fundamental constraints in their compositions. The first is that melodies should, in general, move by short distances. When played on a piano, melodies typically move to nearby keys rather than take large jumps across the keyboard. The second is that music should use chords (collections of simultaneously sounded notes) that are audibly similar. Rather than leap willy-nilly between completely unrelated sonorities, musicians typically restrict themselves to small portions of the musical universe, for instance by using only major and minor chords. While the melodic constraint is nearly universal, the harmonic constraint is more particularly Western: Many non-Western styles either reject chords altogether, using only one note at a time or build entire pieces around a single unchanging harmony.

Together these constraints ensure a two-dimensional coherence in Western music analogous to that of a woven cloth. Music is a collection of simultaneously occurring melodies, parallel horizontal threads that are held together tightly by short-distance motion. But Western music also has a vertical, or harmonic, coherence. If we consider only the notes sounding at any one instant, we find that they form familiar chords related to those that sound at other instants of time. These basic requirements impose nontrivial constraints on composers—not just any sequence of chords we imagine can generate a collection of short-distance melodies. We might therefore ask, how do we combine harmony and melody to make music? In other words, what makes music sound good?

To answer these questions, we need mathematics, just as Pythagoras supposed. But as I and other music theorists have recently shown, we need a kind of mathematics that Pythagoras could not have imagined: the geometry and topology of what mathematicians call “quotient spaces” or “orbifolds.” These exotic spaces contain singularities—“unusual” points that are analogous to the black holes of Einstein’s general relativity—that can be described using only very recent mathematics. Western music can ultimately be represented as a series of points and line segments on abstract shapes in higher dimensions. If we can understand their structure, then the deep principles underlying Western music will finally be revealed.

To turn music into math, we begin by numbering the keys on the piano from low to high. Musicians typically number the 88 piano keys so that the lowest is 21 and the highest is 108, with middle C at 60. Mathematically, these numbers are the logarithms of the slowest frequency at which the piano string is vibrating. In principle we can assign numbers even to notes that are not found on the keyboard, with 60.5 referring to the note halfway between middle C and the next-highest key. These numbers refer to pitches.

Next we model the phenomenon of “octave equivalence”: the fact that notes 12 keys apart sound similar. (As Maria teaches in The Sound of Music, “ti” brings us back to “do.”) To do this mathematically, we divide our piano key numbers by 12 and keep only the remainder. In this way each of the 88 piano keys is assigned a number less than 12: the “C” keys 48, 60, and 72 are represented by 0, while the “C-sharp” (or “D-flat”), keys 49, 61, and 73 are all represented by 1, and so on. Musicians say that these numbers refer to pitch classes, representing the intrinsic “character” or “color” of the note. Geometrically, pitch classes all live on a circle divided into 12 equal parts, exactly like the face of an ordinary clock—though “12” on this clock refers to “0.”

Musically, the order of a group of notes is less important than its content. The ordered sequence C-E-G, or 12-4-7, on the clock, is audibly related to E-G-C, or 4-7-12; musicians consider both to be “C major chords.” A chord is therefore defined as an unordered collection of pitch classes, corresponding geometrically to an unordered set of points on a circle like hours on a clock face.

Chords that are related by rotation on the clock face all sound similar. For example, take the C major chord (12, 4, 7), and move each of the notes clockwise two places. This is the D major chord (2, 6, 9 on the clock), which sounds very much like the C major. In fact, a chord is a major chord if and only if it can be obtained by rotating the C major (so 3, 7, 10 would be another one, the E-flat major chord). The reason these chords all sound alike is that the human ear is more sensitive to the distances between notes than their absolute position on the clockface. Rotating each of the hands of a clock together doesn’t change the distance between them and doesn’t alter the chord’s quality.

We can use this clock analogy to understand the two constraints of Western music mentioned earlier. To satisfy the harmonic constraint, composers need to use chords that are related by rotation, or at least approximately so. This ensures that the distances between the notes in each successive chord stay pretty much constant. To satisfy the melodic constraint, composers connect the notes of successive chords by short distances. For example, one could connect the C major chord (12, 4, 7) to the F major chord (5, 9, 12) by keeping the 12 fixed, moving the 4 one place clockwise to 5, and moving the 7 two clockwise places to 9. This represents a much more efficient alternative to moving each note five places clockwise. Western music is built out of a sequence of such mappings, forming a two-dimensional sonic tapestry.

The final stage in the process of translating music into math is to pass into the clock’s configuration space: Rather than representing chords using multiple points on a one-dimensional circle, we construct an equivalent, higher-dimensional space in which every chord is a different point. The term “configuration space” refers to the fact that points in the higher-dimensional space represent “configurations” (or arrangements) of the points on the lower-dimensional circle. These spaces are considerably more interesting than the plain-vanilla spaces of ordinary Euclidean geometry.

Here, a complexity arises because the notes in a chord are unordered, whereas the coordinates of a geometrical point are typically ordered. Recall from high school geometry that a Cartesian plane is used to model ordered pairs of real numbers (x, y). To create the space of unordered points on a circle, we can just “fold” the familiar Cartesian spaces (representing ordered points on a line) in various ways. In two dimensions (when there are two notes in each chord), we first wrap around each axis, x and y, so that they become circles rather than lines. The resulting space is a doughnut, or in mathematical parlance, a torus. Second, we glue together all the points in the doughnut whose coordinates are related by reordering—so in two dimensions, (x, y) and (y, x) become the same point. In three dimensions (for three notes in each chord), the process is much trickier; we must glue together all six permutations of (x, y, z), and so on.

When, the dust settles, two-note chords live on a Möbius strip, three-note chords live on a solid, twisted triangular doughnut, and larger notes live on higher-dimensional analogues, whose shapes become difficult to describe nonmathematically. The boundary of each space, or shape, is geometrically unusual (“singular”)—line segments appear to “bounce off” the boundary, rather like billiard balls reflecting off the edge of a pool table.

The structure of these spaces, representing all possible chords, shows us exactly how the two elemental properties of Western music can be combined. Structurally similar chords live on circles that wind through the spaces multiple times (these circles can be understood as lines that return back upon themselves like the Earth’s equator). Melodic connections between chords—such as “hold 12 constant, move 4 one unit clockwise to become 5, and move 7 two units clockwise to become 9”—are represented by line segments in the space that may return back on themselves, or bounce off the space’s boundaries. Our original musical question about combining harmony and melody thus becomes a geometrical question about finding circles that are “close to themselves”—that is, circles containing two points that can be connected by short line segments.

The most direct way to combine melody and harmony is to use chords that divide the 12 positions on our clockface of notes nearly (but not precisely) evenly, such as the C major chord (12, 4, 7), which divides the clockface into three roughly equal parts. These harmonies occupy the center of our musical spaces, and are thus able to take effective advantage of its non-Euclidean twists. Remarkably, in the 12-tone system of notes, these are precisely the chords that Pythagoras identified almost 2,500 years ago: the chords that sound intrinsically harmonious. Far from arbitrary or haphazard, scales and chords come close to being the unique solutions to the problem of creating two-dimensional musical coherence. Contrary to the hopes of generations of avant-garde composers, it follows that the goal of developing robust alternatives to tonality may be extremely difficult, if not impossible, to achieve.

The shapes of the space of chords we have described also reveal deep connections between a wide range of musical genres. It turns out that superficially different styles—Renaissance music, classical and Romantic music, jazz, rock, and other popular forms—all make remarkably similar use of the geometry of chord space. Traditional techniques for manipulating musical scales turn out to be closely analogous to those used to connect individual chords. And some composers have displayed a profound understanding of the higher-dimensional geometry of musical chords. In fact, one can argue that Romantic composers such as Chopin had an intuitive feel for non-Euclidean higher-dimensional spaces that exceeded the explicit understanding of their mathematical contemporaries.

The ideas I have been describing were first published in an article I wrote in Science in 2006. More recently, Clifton Callender, Ian Quinn, and I have shown that the connection between music theory and geometry is in fact much deeper and more comprehensive than even my earlier work indicated: There are in fact large families of geometrical spaces corresponding to a wide range of musical terms, some of which are considerably more exotic than those described here. (For instance, three-note chord types—such as “major chord” or “minor chord”—live on a cone containing two different flavors of singularity.) Seen in the light of this new geometrical perspective, a wide number of traditional music-theoretical questions become tractable. In some sense musicians have been doing geometry all along without ever realizing it.

The mathematician Rachel Hall and I are also exploring some interesting resemblances between music theory and economics. Similar geometrical spaces appear in both disciplines, and questions about how to measure distances between musical chords are very similar to questions about how to measure the distance between economic states. This may seem implausible until one reflects that the geometrical operations we have been discussing are very general. Ultimately, the geometry of music is a branch of the geometry of unordered collections—and unordered collections are basic enough to have applications in a wide range of fields. Pythagoras was correct more than two and a half millennia ago: Music provides one of the clearest examples of a much deeper relation between mathematics and human experience.