Pingala's Binary: The First 0s and 1s

How Sanskrit prosody invented binary numbers 2,000 years before computers

Discover Piṅgala's Chandaḥsūtra, the 3rd-century-BCE Sanskrit text whose Chapter 8 contains the oldest surviving binary number system in world literature, the earliest technical use of the word śūnya, and the arithmetic triangle that Europe would later call Pascal's triangle.

The Grammarian Who Saw Two

Somewhere between the third and second century BCE, a Sanskrit scholar named Piṅgala sat down to write a complete handbook of Sanskrit prosody. Sanskrit poetry was built on syllable weight. Every syllable in a verse was either laghu, light and short, or guru, heavy and long, and the difference was felt in the throat: one held the voice for a count of one, the other for a count of two. A meter of six syllables had sixty-four possible patterns of light and heavy. A meter of eight syllables had two hundred and fifty-six. A prosodist who wanted to name every meter, list every pattern in order, and convert a pattern to its position in the list needed a system. Without one, the field was a tangle of named exceptions with no underlying logic.

Piṅgala took two symbols: la for laghu (light) and ga for guru (heavy). They were abbreviations of ordinary Sanskrit words, not invented tokens. Then he wrote four procedures that, read in modern terms, contain the binary number system, the oldest recursive halving algorithm in world literature, and the triangular table of numbers that Europe would later name after Blaise Pascal. He was solving a problem in poetry. That was the only problem he thought he was solving.

Leibniz studying the I Ching in Hanover

The popular history of binary credits Gottfried Wilhelm Leibniz, who in 1703 published a paper in the Mémoires of the Paris Royal Academy. Leibniz himself credited the Chinese I Ching. This story is missing a chapter. The oldest systematic treatment of binary numeration anywhere in world literature is in Piṅgala's Chandaḥsūtra, written roughly 1,900 years before Leibniz.

Pingala marking la and ga symbols on a palm-leaf prosody chart

The Problem Piṅgala Was Solving

Sanskrit poetry is built on syllable weight, not syllable count alone. Every syllable in a Sanskrit verse is either laghu (light, short) or guru (heavy, long), and the rhythmic character of a meter is fixed by the exact sequence in which light and heavy syllables appear. A meter of n syllables therefore has two raised to the n possible patterns of light and heavy. For n equal to six, that is sixty-four. For n equal to eight, it is two hundred fifty-six. For the standard anuṣṭubh meter of eight syllables per quarter, the total number of possible patterns is already two hundred fifty-six, and a poet needs to be able to name each one, compare them, and recognize them.

Piṅgala realized that to handle this systematically, he needed four things. First, a two-symbol notation. Second, a procedure for listing every possible pattern in order, which he called prastāra, 'spreading out'. Third, a conversion between the ordinal number of a pattern and the pattern itself, which is exactly what modern computing calls binary-to-decimal and decimal-to-binary conversion. Fourth, a way to count how many patterns have exactly k heavy syllables without listing them one by one, which modern mathematics calls the computation of binomial coefficients. He got all four.

The Two Symbols

Piṅgala's two symbols are la for laghu and ga for guru. They are abbreviations of ordinary words from the field the text is about, not invented tokens. Every syllable in every Sanskrit verse is genuinely either a la or a ga, so Piṅgala's binary is not an abstraction laid over the domain. It is the domain itself viewed with formal eyes. The same move that 20th century computer scientists later made with Boolean algebra, where true and false are abstractions standing in for closed or open circuits, Piṅgala made in reverse. He saw that a problem in poetry was already binary and wrote the rules for manipulating it as such.

The Halving Algorithm

Chapter 8 of the Chandaḥsūtra contains a dense cluster of sutras, each only two or three Sanskrit words long, that define a procedure for computing powers of two efficiently and for decomposing any positive integer into its binary representation. Read in modern terms, the procedure is: to compute two raised to n, repeatedly halve n; at each step, if the number is even, square the current result; if the number is odd, subtract one and multiply the current result by two. This is the square-and-multiply algorithm that every modern public-key cryptography library runs to compute large modular exponents. One of the sutras that defines the remainder step says rūpe śūnyam, 'for the unit, a zero'. It is one of the earliest uses in world literature of the Sanskrit word śūnya in a strictly technical mathematical sense, roughly eight to nine hundred years before Brahmagupta formalized śūnya as a full-citizen number in 628 CE. The word that would later mean 'zero' begins its technical life here, as a notational mark Piṅgala uses in his halving procedure.

Meru-Prastāra: Pascal's Triangle, 700 Years Early

Meru-prastara triangle on palm leaf

Piṅgala's fourth problem, counting how many of the two-raised-to-n possible meters of n syllables have exactly k guru syllables, is solved by a construction his commentator Halāyudha, writing around 950 CE, called the meru-prastāra, the 'Mount Meru arrangement'. In the Mṛtasañjīvanī commentary, Halāyudha describes a triangular table in which each cell equals the sum of the two cells immediately above it, and in which row n, column k gives the count of n-syllable meters with exactly k guru syllables. The row sums give two raised to n, the total count of n-syllable meters. This table is identical to the binomial-coefficient triangle that Blaise Pascal published in 1654 CE, seven hundred years after Halāyudha and over eighteen hundred years after Piṅgala first described the underlying problem. The Persian mathematician al-Karajī and the Chinese mathematician Yang Hui also had the triangle before Pascal. None had it before the Indian tradition that flowed from Chapter 8 of Piṅgala's text.

Virahāṅka and the Fibonacci Numbers

There is one more surprise in the Piṅgala commentary tradition. In the sixth or seventh century CE, a commentator named Virahāṅka, working on the problem of counting Sanskrit meters by mātrā (moraic count) rather than syllabic count, derived a sequence of numbers where each term is the sum of the two previous terms. This is the sequence now called the Fibonacci numbers, after Leonardo of Pisa, who wrote them down in his Liber Abaci in 1202 CE. Virahāṅka had them roughly six hundred years earlier, as a byproduct of counting meters. A later commentator named Hemacandra wrote the full recurrence explicitly in Sanskrit around 1150 CE, fifty years before Fibonacci. The sequence and its recurrence were a living part of the Piṅgala commentary tradition long before Pisa.

What Was Preserved, What Was Missed

None of this ever left the world of Sanskrit prosody. Piṅgala's binary, Halāyudha's triangle, and Virahāṅka's recurrence all lived inside a single technical tradition for analyzing the meters of classical poetry. They were never applied to commerce, never applied to astronomy, never applied to the computational problems that medieval and early modern European mathematicians would later face. The decimal place-value system went out from India and conquered the world because merchants and scribes carried it with them. Piṅgala's binary stayed home because Sanskrit poetry was its only customer. When Leibniz rediscovered binary in 1703, he was rediscovering something that had been sitting in Chapter 8 of a Sanskrit treatise for two thousand years, waiting for a use case the grammarians had never imagined.

Every time your phone compresses a photograph, every time a rocket's guidance computer multiplies two integers, every time a modern cryptographic library raises a number to an enormous power, the same square-and-multiply idea Piṅgala wrote for counting Sanskrit meters is running beneath the surface. The problem of storing and manipulating information as patterns of two states is not new. The problem of knowing that binary is the right tool for the job is new. The tool itself was already built.

Piṅgala had written his two symbols: la and ga. He was a grammarian solving a problem in poetry. That was all he thought he was solving.

Key figures

Piṅgala

c. 3rd to 2nd century BCE, location uncertain but likely north India within the grammatical tradition of Pāṇini

Halāyudha

c. 10th century CE (active around 950 CE), likely in Central or North India

Virahāṅka

c. 6th to 8th century CE, location uncertain

Case studies

Leibniz's Binary and the I Ching That Came Too Late

In 1703, Gottfried Wilhelm Leibniz published a short paper in the Mémoires of the Paris Royal Academy called Explication de l'Arithmétique Binaire. In it he laid out the base-two number system and the rules of arithmetic that went with it, and he credited his sources carefully. His main acknowledgment was to the Chinese Yi Jing (I Ching, the Book of Changes) and its sixty-four hexagrams of broken and unbroken lines, which he had learned about through a long correspondence with the Jesuit missionary Joachim Bouvet at the Kangxi emperor's court in Beijing. Leibniz believed, correctly, that the hexagrams could be read as binary numerals from zero to sixty-three, and he took this as evidence that the ancient Chinese had grasped binary first. What Leibniz could not have known, because no European scholar had yet translated the text, was that a Sanskrit treatise on prosody had laid out the full binary enumeration procedure, the halving algorithm, and the relevant combinatorial triangle roughly 1,900 years earlier, in the Chandaḥsūtra of Piṅgala. The transmission chain never closed. The Jesuits carried the I Ching to Europe in the 17th century, but no one carried Piṅgala. Sanskrit prosody was a specialist subject with no European readership, and Chapter 8 of Piṅgala's text sat in Indian pāṭhaśālās for another 150 years before European Indologists finally paid attention to it.

The Indian grammatical tradition did not treat Chapter 8 of the Chandaḥsūtra as a mathematical breakthrough. For Piṅgala and his commentators, it was a straightforward piece of prosodic machinery, a tool for counting and naming meters. The binary insight was obvious once you saw that every Sanskrit syllable is either laghu or guru, and the counting insight was obvious once you saw that the number of patterns doubles for every extra syllable. What the tradition did brilliantly was take the obvious and formalize it. What the tradition did not do was carry the formalism outside its original domain into astronomy, commerce, or natural philosophy. Leibniz re-did the same work from scratch because nobody had ever told him the work was already finished.

Leibniz's 1703 paper became the canonical European source for binary arithmetic. When George Boole published An Investigation of the Laws of Thought in 1854 and laid the foundations of Boolean algebra, he was working inside the Leibnizian tradition. Claude Shannon's 1937 master's thesis, which first connected Boolean algebra to electrical switching circuits and thereby founded the theoretical basis of digital computing, is a direct descendant. Nothing in that chain of influence ever passes through Piṅgala. The Indian origin of binary was finally documented in European scholarship by B. van Nooten's 1993 paper 'Binary Numbers in Indian Antiquity' in the Journal of Indian Philosophy, nearly three hundred years after Leibniz and roughly 2,200 years after Piṅgala.

An idea confined to a single specialist domain can lie fallow for two millennia. Transmission is not automatic. A tradition that wants its best ideas to travel has to teach them in domains beyond the one they were born in. The modern scientific world rediscovered binary not because Leibniz was smarter than Piṅgala but because Leibniz wrote it down in a venue that other scientists were reading.

The gap between Piṅgala's binary enumeration in the Chandaḥsūtra (c. 3rd century BCE) and Leibniz's Explication de l'Arithmétique Binaire (1703 CE) is approximately 1,900 to 2,000 years. The gap between Halāyudha's meru-prastāra (c. 950 CE) and Pascal's Traité du triangle arithmétique (1654 CE) is approximately 700 years. Both are cases where a European 'first' was neither.

Donald Knuth Credits Piṅgala by Name

In 2011, Donald Knuth, the Stanford computer scientist widely regarded as the founding theorist of algorithm analysis, published the first fascicle of Volume 4A of The Art of Computer Programming, the canonical reference in the field. In Section 7.2.1.7, titled 'History and Further References', Knuth traces the prehistory of the combinatorial generation techniques that Volume 4A is about. He does not start with Leibniz or Pascal. He starts with Piṅgala. He identifies Piṅgala's Chandaḥsūtra as the earliest known source of the binary number system, the earliest known source of Pascal's triangle (which Knuth calls 'the Meru Prastāra'), and the earliest known source of the Fibonacci sequence (which he attributes to Virahāṅka and Hemacandra in the Piṅgala commentary tradition). Knuth's phrasing is careful: 'These results from ancient India were rediscovered hundreds of years later in Europe, but the original discoveries deserve to be remembered.' For a field whose standard histories almost always start with Pascal and Fibonacci, the acknowledgment is a small but significant course correction.

Knuth is doing, in the 21st century, what Halāyudha did in the 10th. Halāyudha wrote the Mṛtasañjīvanī, 'the reviver of the dead', because Piṅgala's sutras were becoming unreadable without commentary. Knuth is writing a different kind of commentary. He is reviving the attribution that European mathematical historiography had allowed to die. The work itself had always been alive in Indian prosody departments; what had died was the rest of the world's memory of who did it first. Halāyudha's text restored Piṅgala for Sanskrit scholars. Knuth's section restores Piṅgala for the computer science profession that is now the largest consumer of binary.

Volume 4A of The Art of Computer Programming has shipped hundreds of thousands of copies since 2011 and is the standard graduate-level reference for combinatorial algorithms worldwide. Every algorithms course at every major university that uses Knuth as a reference now has a path, if the student chooses to follow it, back to Piṅgala by name. The citation does not reverse 1,900 years of missing attribution, but it ensures that any serious student of the subject can trace the lineage correctly if they want to.

Attribution is a choice. A field that tells its history honestly pays a small cost in rewriting textbooks and gains a large benefit in moral clarity and accurate teaching. Knuth's example shows that the correction is available whenever a senior figure in a field is willing to do the work. The only real obstacle is the inertia of existing citations.

Volume 4A of The Art of Computer Programming, first published in 2011, contains an explicit credit to Piṅgala's Chandaḥsūtra as the earliest source of the binary number system. Knuth's field (algorithm analysis and combinatorial generation) has existed as a named discipline since roughly 1968. The gap between the discipline's founding and its formal acknowledgment of Piṅgala is 43 years. The gap between Piṅgala himself and that acknowledgment is more than 2,200 years.

UTF-8 and Devanāgarī: Piṅgala's Descendant Carries Piṅgala's Text

Every Sanskrit shloka that you read on a phone or laptop today is stored and transmitted as a sequence of binary digits grouped into bytes according to a specific encoding. For Devanāgarī, the dominant encoding is UTF-8, the Unicode Transformation Format introduced in 1992 by Ken Thompson and Rob Pike at Bell Labs and adopted as the default encoding of the World Wide Web by 2008. In UTF-8, each Devanāgarī character is represented as a sequence of three bytes, each byte as a sequence of eight bits, and each bit as one of two states, on or off, laghu or guru. When you read the opening sutra of the Chandaḥsūtra, 'रूपे शून्यम्', on a screen, that exact text is traveling as a sequence of laghus and gurus obeying precisely the two-symbol logic Piṅgala formalized twenty-two centuries ago. The text has become its own notation. Piṅgala's binary is now carrying Piṅgala's words.

There is a phrase in the Sanskrit tradition, often used about sacred texts, that describes a teaching being carried perfectly across long stretches of time. The phrase is paramparā, 'succession'. Usually it refers to an unbroken line of teachers and students reciting and commenting on a text through generations. UTF-8 is a strange new kind of paramparā. The laghu-guru formalism that Piṅgala designed so that Sanskrit poetry could be counted and named is now the medium in which every surviving copy of Sanskrit poetry lives. The tool and the text have merged. Every time a student of the Chandaḥsūtra opens the text on a laptop, Piṅgala's binary is silently carrying out its own ancient author's instructions to spell out, in two symbols, every possible pattern of meaningful syllables.

As of 2026, Unicode contains approximately 150,000 encoded characters, including the full Devanāgarī block and every other Indic script. UTF-8 is used by approximately 98 percent of all websites. The entirety of classical Sanskrit literature available online, from the Ṛgveda to the Aṣṭādhyāyī to the Chandaḥsūtra itself, is transmitted in a two-symbol encoding that is logically identical to, and historically descended from, the enumeration procedure Piṅgala wrote for counting Sanskrit meters. The descendant carries the ancestor.

Ideas that look purely specialist when invented can become universal substrates millennia later. Piṅgala had one use case for binary, namely counting meters, and he built a tool that fit that use case exactly. Because the tool was well built at the level of the underlying logic, it turned out to be the right tool for a completely different problem that nobody in his tradition could have anticipated. The lesson is not to chase universal applicability. The lesson is to build the specialist tool correctly and trust that if the logic is clean, future problems may find the tool on their own.

UTF-8 is used by approximately 98 percent of all websites and is the default text encoding of the World Wide Web. A single Devanāgarī character takes three bytes, or 24 bits, to encode. The opening sutra rūpe śūnyam occupies roughly 28 bytes (224 bits) when transmitted in UTF-8, which means every copy of Piṅgala's binary sutra now travels across the internet inside a stream of 224 laghu-guru digits obeying exactly the rules Piṅgala wrote.

Historical context

Late Mauryan to early post-Mauryan period, c. 3rd to 2nd century BCE

The Mauryan empire had been the largest political unit India had ever seen, and its collapse in the early 2nd century BCE left a patchwork of regional powers in the north. The Śuṅgas ruled Magadha and the middle Gangetic plain from Pāṭaliputra, the Sātavāhanas controlled the Deccan, and Indo-Greek kingdoms occupied the northwest. Pāṇini's Aṣṭādhyāyī, the great grammatical treatise that had formalized Sanskrit a few centuries earlier, was now the living standard of Sanskrit instruction, and the six Vedāṅgas (śikṣā, vyākaraṇa, nirukta, chandas, kalpa, jyotiṣa) were established fields with their own technical literatures. Piṅgala's Chandaḥsūtra belongs to this milieu. It is the canonical text of the chandas Vedāṅga and was composed in the same compressed sutra style as Pāṇini's grammar.

The Chandaḥsūtra is one of only two or three places in world antiquity where the idea of a formal algorithmic procedure, written down as a sequence of rules to be executed in order, is clearly present. (The others are Pāṇini's own grammar and Euclid's Elements in Greece.) Piṅgala's text is unusual even among these because it does combinatorial counting and binary enumeration, which are specific techniques that European mathematics would not recover for another 1,700 to 1,900 years. The chapter in which this work appears sits near the end of a treatise on Sanskrit poetry, which is why the rest of the world missed it for so long. The larger point is that the habit of writing procedures, once established in a culture, generalizes in surprising ways. Pāṇini's grammar and Piṅgala's prosody are the intellectual parents of Indian mathematical astronomy a few centuries later, and eventually of the Kerala school's work on infinite series a millennium after that.

Living traditions

Piṅgala's binary logic is the logical substrate of every digital device in use today. Every bit in every computer, every pixel on every screen, every byte in every network packet is a laghu or a guru in the sense Piṅgala defined. Donald Knuth's Art of Computer Programming, Volume 4A (2011), cites the Chandaḥsūtra by name as the earliest known source of the binary number system and of the triangular table the West calls Pascal's triangle. The Unicode standard, which governs how Sanskrit itself is now stored and transmitted on computers, is a two-symbol encoding whose logic descends directly from Piṅgala's own system. In the traditional Sanskrit world, the Chandaḥsūtra and Halāyudha's Mṛtasañjīvanī commentary remain living texts in the chandas Vedāṅga curriculum at Sanskrit universities and pāṭhaśālās across India, and Piṅgala's meter classification system is still the standard reference for any modern Sanskrit poet composing in classical forms.

Reflection

More in Dashamana: The Decimal Place Value System

All lessons in Dashamana: The Decimal Place Value System · Indian Mathematics: Ancient Genius, Modern Foundations course