
Paperis Articles
Bach — Music Written by Mathematics, or Music That Mathematics Can Measure?
Bach has long been called "mathematical." This piece separates the three things that word has meant — a critic's metaphor, hidden codes, and measurable structure — and follows what studies that counted note transitions as networks, and studies that measured listeners' ears, have shown, and what they have not yet asked.
Your field's papers, as audio
Pick your fields and journals — Paperis summarizes the key papers and turns them into audio. Listen on your commute.
Start Paperis free →Bach — Music Written by Mathematics, or Music That Mathematics Can Measure?
1722, A Collection of Pieces Touring Twenty-Four Keys
In 1722, the small court city of Köthen in central Germany. The German composer Johann Sebastian Bach (1685–1750), who was the musical director of that court, compiles a collection of pieces for keyboard instruments. It is a book that sets out from each of the twelve notes as a starting point, touring major and minor keys—all twenty-four keys in turn, once each—and pairing two pieces for every key. This collection is Volume 1 of "The Well-Tempered Clavier", and its first pair is two pieces written in C major, with the preceding piece called a prelude. Bach's works bear the catalog number BWV, and this first pair is BWV 846.

Johann Sebastian Bach · oil painting by Elias Gottlob Haussmann (1748, second version of the 1746 portrait) · Bach-Archiv Leipzig · public domain · Wikimedia Commons
The first piece, the prelude, begins without a memorable melody. Within a single measure, the same pattern of rolling a single chord upward from bottom to top repeats twice, and when moving on to the next measure, the shape of the pattern is left as is while only the chord changes. This first measure has already been heard once in "Chords and Consonance — Teeth That Mesh, Teeth That Grind". This time, we listen to four measures in a row.
Clip: Bach, Well-Tempered Clavier I, Prelude in C, BWV 846, bars 1–4 (synthesized piano; score input Mutopia Project, public domain)
We heard the repeating pattern and the changing chords. Long before now, people have brought up the word "mathematics" in front of Bach's music. Music critics have compared Bach's music to the precision of mathematics (PMID 11607061), and the claim that Bach's music is a code to be solved has also followed it for a long time (DOI: 10.1093/oso/9780190943899.003.0010). This article asks just one thing. Is Bach's music music written with mathematics, or is it music that can be measured with mathematics? The two questions look similar, but their answers are different.
One Line Enters, Then Another Line Enters
The piece that follows the prelude has a completely different character. To listen to this piece, a few terms are needed. A voice is one of the lines of melody in music where multiple lines of melody go together. The line sung by the soprano in a choir and the line sung by the bass are each one voice. Counterpoint is a compositional technique of weaving together multiple independent voice lines so that they sound simultaneously while meshing harmoniously with one another. Unlike a song where one line is the protagonist and the rest take care of the accompaniment, in counterpoint every line goes its own way.
A fugue is a piece in counterpoint woven by having multiple voices take turns entering and building upon a single short melody. That short melody has a separate name. The subject of a fugue is a short melody presented alone by a single voice at the very beginning of the piece, which reappears throughout the piece in various voices and at various pitches. The fugue of BWV 846 is woven with four voices, and the subject is about a measure long. First, we listen to the beginning where the subject appears alone.
Clip: the matching Fugue, opening — the subject alone (synthesized piano; score input Mutopia Project, public domain)
Keeping this single line in mind, we listen to the passage where voices are added one by one. The second voice enters on the third beat of measure 2 carrying the same subject at a higher pitch, while the voice that entered first keeps going without stopping and continues with a different melody. The third voice enters from below at measure 4, and the fourth voice enters at the lowest register on the third beat of measure 5, making four voices in all.
Clip: Fugue, bars 1–6, voices entering one by one (synthesized piano; score input Mutopia Project, public domain)
We recall whether the second entry and the third and fourth entries were caught equally well. The third and fourth voices enter from underneath the lines that are already moving, into progressively lower registers. This piece was woven according to the rule of transposing the same melody to different pitches and interlocking multiple lines together. However, saying that it was woven following rules is not the same thing as saying it was constructed by numerical calculation.
Three Things the Word "Mathematical" Has Pointed To
A short article published in a scientific journal in 1990 picked up critics' metaphor that "Bach's music is as precise as mathematics" and asked a question (PMID 11607061). Critics compare Bach's music to the precision of mathematics, but what "mathematics" is that, and what is that "precision"? This piece suggested that the mathematics is, at least in part, a geometry dealing with shapes where magnifying a part repeats the whole, and that precision can be seen in how much a straight line deviates on a graph with logarithmic scales on both axes. It is a proposal to turn a metaphor into a measurable mathematical structure. The author himself called it a "short piece," and subsequent research verifying this proposal is not among the bases of this article.
The second branch is cryptography. A chapter in the Bach study Rethinking Bach (2021) summarizes this current like this (DOI: 10.1093/oso/9780190943899.003.0010). Interpreters have counted notes and measures, added numbers pulled from writings, and traced shapes drawn by notes on the score to find hidden meanings. Much of that theory is amateur work, but the same approach appears in academic writing as well. And the conclusion of this chapter is this. All new cryptographic claims start from the unexamined premise that "Bach worked in code in the first place."
The third branch is the center of this article. It is the method of actually counting the notes written on the score and looking to see if their statistics have measurable features. The research team we will see in the next section also introduces Bach's works as "highly mathematically structured" in their abstract (DOI: 10.1103/physrevresearch.6.013136).
A critic's metaphor, hidden codes, and a measurable structure. The three use the same word but are different claims. Just because one gains evidence does not mean the other two gain evidence together. Finding features in note statistics does not mean Bach hid codes, nor does it mean the critic's metaphor is correct as it stands.
Counting the Bridges Between Notes and Notes
We draw a picture using the first bar of the prelude we just heard. The first bar repeats a pattern that starts on C and scatters upward to E, G, high C, and high E. We put a dot for each note and draw a line between the two dots every time we move from C to E. Once we follow the whole bar, as the same pattern repeats, several lines become lines that have been crossed multiple times. A network is a net-shaped picture woven from dots and lines connecting those dots, where here each individual note is a dot, and moving from one note to the next note is a line. This single picture is an example made by this article, and actual research draws entire pieces in the same way.

On top of this picture, we can measure "unexpectedness". The amount of information is a value that scores, as a probability, how unexpected that note is when a certain note appears, and it is larger for notes with a lower probability of appearing. In the first bar of the prelude, a low C is always followed by E. Just looking at that bar alone, the E following the low C has a very small amount of information. If a different note suddenly comes after the low C, that note has a large amount of information. Expanding this calculation to the entire piece allows us to score a value for a single piece, and the study we will look at next uses such piece-level values.
A study published in a 2024 American Physical Society journal turned Bach’s pieces into such note-transition networks, then analyzed them with the tools of network science, information theory, and statistical physics (DOI: 10.1103/physrevresearch.6.013136). When they scored the information contained in each piece's network, different forms of pieces such as fugues and chorales clustered together according to their amount of information and network structure. This means that the statistics of how notes transition came out differently depending on the form. Details such as which form scored higher are not in the abstract. The amount of information is scored at these two scales. The previous definition is a value scored for a single note, and the value scored for each piece by this study is a value for the entire piece's network. The studies compared against human expectations later use the value of a single note.
The research team went a step further. They ran a model that mimics how humans might guess and learn such networks, and as a result, Bach’s music networks transmitted a lot of information while keeping the difference between the network guessed by the model and the actual network small (DOI: 10.1103/physrevresearch.6.013136). The research team interpreted this as suggesting that Bach’s pieces are structured to transmit information efficiently. As structures that make that efficiency possible, they pointed to high heterogeneity and strong clustering. Heterogeneity is a term that in network science usually refers to the uneven degree to which connections are concentrated in a few dots, and clustering refers to the degree to which neighboring dots are densely woven together to form groups. Exactly what this study measured is not in the abstract.
There are three things to hold onto when reading this result. First, the "network guessed by humans" is a value calculated by a model. Experiments where pieces were played to humans do not appear in the abstract. Second, the amount of information and efficiency are quantities defined by the calculation method chosen by the research team. The framework explained by the abstract is a simple network woven from notes (dots) and their transitions (lines), and the research team also left more complex musical properties as tasks to explore in the future. How rhythm or the texture of voices was handled is not in the abstract. Third, this is a characteristic found by measuring completed pieces, and it does not say by what method Bach composed his pieces.
One analysis measured by a different method compared Bach and Beethoven. Extracting the highest-note line and lowest-note line from The Well-Tempered Clavier and Beethoven’s piano sonatas, the analysis compared the probability of which note would come after a given note and the degree of uncertainty in that probability (PMID 31856208). The results of the two composers were similar. The upper line and lower line each had their own statistical characteristics along with shared characteristics, and the uncertainty levels of the two lines moved in gear with each other while also moving separately in part. Because this is a quantity different from the amount of information scored by the previous study, this analysis cannot answer whether that characteristic belongs only to Bach.
There are measurable characteristics in Bach's music. However, "can be measured" is different from "was written with mathematics." The studies in this section showed the former, and neither asked nor answered the latter.
Is the Most Common Also the Most Bach-Like?
Among the models built by counting notes, there is one that relies on a plausible premise: the more frequently something appears in Bach's music, the more Bach-like it is. A commentary published in a musicology journal in 2015 tested precisely this premise (DOI: 10.18061/emr.v10i3.4861). Evaluating another researcher's model—which was built by counting which scale degrees and cadence progressions occur together in Bach chorales (hymn tunes sung by church congregations, to which Bach added four-part harmonies)—this commentary presented college students taking a second-level harmony class with pairs of cadence progressions and asked them to judge which one was more in Bach's style. Whether they were made to listen to the sound or shown sheet music is not mentioned in the abstract.
The results ran counter to the premise. Even if it was the most common cadence progression in Bach chorales, if the surrounding ornaments were altered in a specific way, the students judged it to be less Bach-like than a cadence that never once appeared in the chorales (DOI: 10.18061/emr.v10i3.4861). The author of the commentary interpreted this as evidence that "the shape of the ornamentation matters more to the formation of a style than the scale degree or the type of cadence." It is a small test within the commentary, and the number of participants is not mentioned in the abstract.
What this test shows is narrow but clear. What appears most frequently and what is judged to be most Bach-like may not be the same thing. There is a gap between counting frequencies on a sheet of music and a person judging something to be "Bach-like." However, since even the presentation method is not stated in the abstract, this test cannot be interpreted as an experiment measuring auditory perception. Studies that directly measure the listener's ears are a separate matter.
What the Listener Is Counting
There is an experiment that played short melodies to 46 four- and five-year-old children, comparing versions where the final note ended "as expected" according to the rules of Western music versus versions where it ended "unexpectedly" (PMID 33271397). The children responded faster and more accurately to the notes that ended as expected. This means that by age five, expectations for the next note are already firmly established. Several aspects of the home music-exposure environment moved alongside the strength of that expectation, though the design was not meant to determine causation. The researchers started from the claim that children naturally acquire the rules of music through general learning mechanisms such as statistical learning. Statistical learning is the process of learning how often one thing follows another simply by hearing a lot, without any intent to learn.
How similar are the statistics learned by the ear to the statistics of computational models? There is a study that used a computational model, which independently learned the statistics of note flow by listening to a lot of music, to assign a probability to each note in actual melodies and compared them with the "degree of expectation" felt by people (PMID 20005297). The lower the probability the model assigned to a note, the less people reported expecting it, and a strong negative correlation emerged between the two. Notes with low probability also produced distinct differences in brainwaves, such as a larger negative potential response around 400 to 450 milliseconds. When the amount of information defined in the previous section was measured on a single-note basis, it aligned with human expectation.
The more trained the ear, the more precise this sense was. When musicians and non-musicians listened to 12 passages that the model rated as difficult to predict the next note for and 12 passages rated as easy, listeners felt greater uncertainty at the difficult passages, and this effect was greater in musicians (PMID 25295018). The researchers interpreted this as showing that the more training one receives in that field, the more accurately the probabilistic structure of music is retained in the head.
Even so, statistics do not explain everything. In an experiment where participants were played the beginning of an unfamiliar melody and asked to directly sing the note likely to come next, both statistical learning and principles rooted in the auditory system—such as a "preference for moving in small steps"—contributed to expectation (PMID 30913527). While the researchers considered the role of statistical learning to be larger than previously thought, they noted that a large share of human responses remained unexplained by either of the tested models, and concluded that models capable of capturing harmony or layered structures are needed. In melodies created with artificial grammars, listeners learned new statistics well, but did not show a stronger preference for placing stress on notes with high information content. What best predicted stress preference was the peak of the melodic contour (PMID 39585826).
The ear also naturally learns the statistics embedded in the flow of notes. However, those statistics alone cannot fully explain human expectations. Most of these studies used general or artificial melodies, not Bach's compositions. To apply these results directly to ears listening to a Bach fugue, they must be measured separately using that music.
What Listening to Multiple Lines at Once Means
This time, we listen to the final four measures concluding the same fugue. This is a passage where multiple voices move together. We listen to see if we can pick out a single line and follow it to the end.
Clip: Fugue, closing four bars (bars 24–27) (synthesized piano; score input Mutopia Project, public domain)
We recall what we heard and what was hard to hear because multiple lines overlapped. Measuring this experience with numbers—specifically, studies that play a fugue and record whether people notice the subject as it enters—are not among the evidence collected in this article. Instead, there are studies measuring around the edges of this.
One involves the rules between separated notes. In an experiment where artificial tone sequences with arranged notes were played, when the notes were similar in both pitch range and timbre, listeners learned the rules between immediately adjacent notes to some extent, but failed to learn the rules between notes separated by other notes in between, even though the rules between the separated notes were very consistent (PMID 15355140). When the separated notes were distinguished from the rest by their pitch range or timbre, the rules between those separated notes were learned. The researchers concluded that statistical learning is governed not only by temporal proximity, but also by the principle of "grouping similar things together." In a fugue, too, the notes of one voice continue with the notes of other voices interspersed. However, this experiment used artificial tone sequences, and whether these results apply directly to following the voices of a fugue is not measured in the evidence for this article.
There are also studies that measured how the ear finds places where a melody pauses like a sentence. When 38 college students listened to tone sequences—whose degree of predictability for the next note was controlled using a computational model—by manually advancing one note at a time, the students lingered longer at notes where the next note became harder to predict (PMID 34409898). Another 31 college students rated tone sequences ending on such notes as sounding more "finished." This effect appeared independently of how surprising the note itself was or where that note was originally located in the phrase of the piece. The ear leaned toward cutting off and hearing the flow of sound at points where the next step became uncertain. This was also measured using general tone sequences and did not measure the entry of the fugue subject.
Another is whether the large-scale structure of the score changes the listener's evaluation. Bach's "Goldberg Variations" is a piece consisting of an aria and thirty variations. A 1985 study had participants listen to a shuffled version and the original version of this piece's variation order and evaluate them on 15 scales (DOI: 10.2307/40285323). Only 1 out of the 15 scales favored the original order more. In a test where three variations were played in their original order and in a random order, listening evaluations did not differ either. The difference between the harpsichord performance and the piano performance was also very small. Who the participants were is not in the abstract. Even when the order of variations set by Bach was changed, the listeners' evaluations hardly changed. What this study measured was preference and listening evaluation, not whether the structure was understood. At least by the evaluation scales of this experiment, the large-scale order of the score hardly translated into listening evaluations.
There is also a brain imaging study that looked at both the listener's experience and the character of the piece. Brain images were taken while 24 prospective professional musicians and 17 amateur musicians listened to a baroque piece by Bach and a piece by the Austrian composer Anton Webern (PMID 41316851). When listening to Bach, participants spent more time in a state where brain regions worked divided into clusters; when listening to Webern, they more frequently transitioned to a state where regions worked broadly together. The higher the musical expertise, the greater the degree of working broadly together when listening to Webern. The difference in expertise when listening to Bach is not in the abstract. The researchers concluded that the form of the piece and the listener's expertise together shape the brain's organization. This is a study comparing two pieces, and it did not measure the ability to recognize the subject.
Placing these studies side by side, what the ear learns depended on the sound cues of pitch and timbre, while the brain's organization during listening depended on the listener's expertise. Studies that directly measured which parts of the score's structure reach the ear are not among the evidence in this article. How many times the ear follows the entry of the fugue subject is also a question that cannot yet be answered by the evidence in this article.
What Is Still Debated, What Is Still Unmeasured
The first debate is whether music and mathematics use the same machinery in the head. A 2025 review noted that the question of whether there is a cognitive link between the ability to make music and the ability to understand numbers has sparked speculation in philosophy and education for hundreds of years, and that while empirical studies are growing, those studies have noticeable limitations (PMID 39052342). The research team left the question of whether there is a shared cognitive structure for reasoning about numbers and mathematics as a future task. Another review from 2026 gathered evidence that a region in the lower frontal lobe is used in an overlapping way when processing the structures of language, music, and mathematics, and while noting that various experiments and computational models suggest a shared cognitive mechanism, it wrote that differences also remain between language, music, and mathematics (PMID 41344536). This overlap does not mean that "someone who listens to Bach well is also good at math." A similar question of whether listening to music makes the head better was covered separately in "The Mozart Effect — Ten Minutes in the Earphones Before the Test".
The second is what has not been measured yet. The interpretation from a 2024 study that Bach's music network is structured to transmit information efficiently came out on a model that mimics human guesses (DOI: 10.1103/physrevresearch.6.013136), and whether actual listeners guess Bach's pieces like that model is something that must be measured separately.
The third is the premise of cryptanalysis. A book chapter from 2021 criticizes that new cryptographic claims did not sufficiently examine the premise that Bach worked with ciphers (DOI: 10.1093/oso/9780190943899.003.0010). The criticism that the abstract mentions is about the premise, and whether specific ciphers were refuted one by one is not in the abstract.
So — If You Listen to the Fugue Once More
Now, let's imagine listening to the fugue from BWV 846 from the beginning again. One voice introduces the subject alone, and a second voice enters carrying the same subject at a shifted pitch. The regularity heard at that moment comes from the texture of rewriting the same melody at a shifted pitch and interlocking multiple lines. When we call this "mathematical," whether that word is a critic's metaphor or a structure that can be measured depends on which of the three paths seen earlier it refers to.
If we turn the same piece into a network of pitch transitions, a computational model can assign an amount of information to that piece and compare it with pieces of other forms. This is a measurable feature, and a quantity defined by the model. In an analysis that separately measured the transition statistics of the upper and lower lines, the results for Bach and Beethoven were similar. The interpretation of finding hidden meanings in the numbers within the score rests on the unexamined premise that Bach worked with cryptography.
And there is the listener's ear. By around the age of five, the ear already expects the next note, and the more trained the person is, the more precise that expectation is. However, in a 1985 experiment, shuffling the major order hardly changed the appreciation evaluation at all. If you missed the moment when the third and fourth voices entered, that experience brushes against one question for which the evidence in this article has not yet found a measured study.
Bach's music is music that can be measured with mathematics. The evidence that it was written with mathematics is nowhere in the research gathered by this article.
Source Papers
- "Information content of note transitions in the music of J. S. Bach" (2024) — DOI: 10.1103/physrevresearch.6.013136 — Converting Bach pieces into note transition networks and measuring information amounts grouped them by form, suggesting a "fabric for efficient communication" under human inference models (authors' interpretation). Heterogeneity and clustering.
- "Rethinking Bach Codes" (2021) — DOI: 10.1093/oso/9780190943899.003.0010 — A chapter from the academic book Rethinking Bach. Maps the genealogy of interpreting Bach codes and criticizes that all new claims start from the unexamined premise that "Bach worked with codes."
- "Fractal geometry of music." (1990) — PMID 11607061 — A short piece accepting critics' "mathematical precision" metaphor and proposing that part of that mathematics is fractal geometry.
- "Statistical learning and the uncertainty of melody and bass line in music." (2019) — PMID 31856208 — Analyzes transition probabilities and uncertainty in the highest and lowest pitch lines of equal temperament and Beethoven piano sonatas, with similar results for both composers.
- "Probability and Style in the Chorales of J. S. Bach" (2015) — DOI: 10.18061/emr.v10i3.4861 — Commentary. Even the most common endings, when ornaments are changed, are judged less stylistic than a never-appearing ending (pairs presented to harmony class students; presentation method and number of participants not in the abstract).
- "Melodic expectations in 5- and 6-year-old children." (2021) — PMID 33271397 — 46 children aged 5 to 6 showed faster and more accurate responses to notes ending as expected, and home musical environments predict expectation strength.
- "Unsupervised statistical learning underpins computational, behavioural, and neural manifestations of musical expectation." (2010) — PMID 20005297 — Strong negative correlation between note probabilities in a statistical learning model and subjective expectations, with brain responses such as late negativity potentials at low-probability notes.
- "Predictive uncertainty in auditory sequence processing." (2014) — PMID 25295018 — Greater perceived uncertainty in high-uncertainty contexts, stronger in musicians.
- "Statistical learning and Gestalt-like principles predict melodic expectations." (2019) — PMID 30913527 — Both statistical learning and Gestalt principles contribute to song blank-filling tasks, with a large unexplained share necessitating harmony and hierarchical structure models.
- "Melodic contour supersedes short-term statistical learning in expressive accentuation." (2024) — PMID 39585826 — New statistics were learned well, but accents on notes with large information amounts were not preferred; melodic contour peaks predict preferences.
- "Distant melodies: statistical learning of nonadjacent dependencies in tone sequences." (2004) — PMID 15355140 — Rules between distant notes are learned only when pitch range and timbre are distinct; statistical learning is also governed by principles of similarity.
- "Predictive Uncertainty Underlies Auditory Boundary Perception." (2021) — PMID 34409898 — People linger longer on notes where the next note is uncertain (38 college students) and evaluate note sequences ending with such notes as more complete (31 students), independent of surprise degree and original position.
- "The Effects of Instrumentation, Playing Style, and Structure in the Goldberg Variations by Johann Sebastian Bach" (1985) — DOI: 10.2307/40285323 — Even when the variation order is changed, the original order is preferred on only 1 out of 15 scales (listening evaluation), and differences in instruments and playing styles are also small.
- "Expertise-Dependent Brain Network Organization During Music Perception." (2025) — PMID 41316851 — 24 pre-experts and 17 amateurs showed brain state differences while listening to Bach and Webern, with expertise increasing integration during Webern listening.
- "Towards mechanistic investigations of numerical and music cognition." (2025) — PMID 39052342 — Review. Limitations of research connecting number and music cognition and whether they share structures as a future task.
- "The neurobiology of human sequential signal prediction: Insights from language, music, and mathematics." (2026) — PMID 41344536 — Review. Overlap in the inferior frontal gyrus during structural processing in language, music, and mathematics, with domain-specific differences remaining.
Sources (16)
- Information content of note transitions in the music of J. S. BachDOI 10.1103/physrevresearch.6.013136
- Rethinking Bach CodesDOI 10.1093/oso/9780190943899.003.0010
- Fractal geometry of musicPMID 11607061
- Statistical learning and the uncertainty of melody and bass line in musicPMID 31856208
- Probability and Style in the Chorales of J. S. BachDOI 10.18061/emr.v10i3.4861
- Melodic expectations in 5- and 6-year-old childrenPMID 33271397
- Unsupervised statistical learning underpins computational, behavioural, and neural manifestations of musical expectationPMID 20005297
- Predictive uncertainty in auditory sequence processingPMID 25295018
- Statistical learning and Gestalt-like principles predict melodic expectationsPMID 30913527
- Melodic contour supersedes short-term statistical learning in expressive accentuationPMID 39585826
- Distant melodies: statistical learning of nonadjacent dependencies in tone sequencesPMID 15355140
- Predictive Uncertainty Underlies Auditory Boundary PerceptionPMID 34409898
- The Effects of Instrumentation, Playing Style, and Structure in the Goldberg Variations by Johann Sebastian BachDOI 10.2307/40285323
- Expertise-Dependent Brain Network Organization During Music PerceptionPMID 41316851
- Towards mechanistic investigations of numerical and music cognitionPMID 39052342
- The neurobiology of human sequential signal prediction: Insights from language, music, and mathematicsPMID 41344536