← All writing Ancient algorithms, 15 min read

Maya numerals and the Long Count: base 20 and a calendar converter in Python

Maya numerals from the Dresden Codex to tested Python: base 20 with a zero, the Long Count, the 260 and 365-day counts, and a converter to Julian Day Numbers.

Maya numerals are a base-20 place-value system written with 3 signs: a dot for 1, a bar for 5 and a sign for 0. Digits from 0 to 19 are built from bars and dots, and the digits stack from the bottom up, each place worth 20 of the place below. In counts of days the third place is worth 360 instead of 400, and that rule turns the numerals into the Long Count, a running day number carved on Classic Maya monuments.

S. G. Morley's 1915 handbook gave me the rules. I checked them against the dates printed in the Dresden Codex and in a 2013 radiocarbon study, then wrote a Python converter with tests (code on GitHub). This post belongs to Ancient algorithms, implemented.

The problem it solves

A Long Count date names a day by how many days have passed since a fixed starting day, the era date. Here is one from page 24 of the Dresden Codex, as Morley reads it:

9.9.9.16.0 1 Ahau 18 Kayab

The 5 numbers are the day count. The 2 names after it are the day's place in 2 shorter cycles, the 260-day count and the 365-day count. A converter has to do 3 things:

  1. turn the 5 numbers into a count of days;
  2. find the 2 cycle names that day carries, and check them against the text;
  3. turn the day count into a date in our calendar.

Steps 1 and 2 are arithmetic. Step 3 needs a number that no Maya text gives, and that is where scholars disagree.

Who wrote it, and when

There is no single author. The notation is attested on stone monuments and in Maya books, the codices.

  • The Long Count on monuments. Kennett and co-authors (2013) cite a Long Count date of 36 BCE at Chiapa de Corzo, outside the Maya lowlands, and say the system spread to more than 40 Maya centers between 600 and 900 CE. All these dates depend on the correlation discussed below.
  • The Dresden Codex. A folding book, held in Dresden, with tables of day counts for the 260-day count, Venus and the moon. The 27 Long Count dates in it that Förstemann counted, as Morley lists them, run from 8.6.16.12.0 to 10.19.6.1.8. When it was painted is a separate question.
  • The written rules. No Maya text explains the arithmetic. What we have are the numbers themselves. Ernst Förstemann's commentary (English translation 1906) works through the Dresden tables, and Morley's An Introduction to the Study of the Maya Hieroglyphs (1915) collects the rules as a handbook.

How Maya numerals work

Digits: bars, dots and zero

Morley states the digit rule plainly: "one dot stands for 1", a bar for 5, and the 2 combine up to "three bars and four dots for 19". He quotes an 18th-century Maya writer, through Daniel Brinton, describing the same system:

They [our ancestors] used [for numerals in their calendars] dots and lines [i. e., bars] back of them; one dot for one year, two dots for two years, three dots for three years, four dots for four, and so on; in addition to these they used a line; one line meant five years, two lines meant ten years

The full table:

DigitBarsDots
0zero sign
1 to 401 to 4
5 to 910 to 4
10 to 1420 to 4
15 to 1930 to 4

Morley describes the zero sign in the codices as lenticular, lens-shaped, and adds in a footnote: "This form of zero is always red and is used with black bar and dot numerals as well as with red in the codices."

Places: base 20, with one exception

Each digit sits in a place. Morley's Table VIII gives the places used for counting days:

PlaceNameMade ofDays
1stk'in1
2ndwinal20 k'ins20
3rdtun18 winals360
4thk'atun20 tuns7,200
5thbak'tun20 k'atuns144,000

He calls these "the exact terms of a vigesimal system of numeration, with but a single exception", the 18 in the third place. Morley suggests the 18 brings the tun close to the 365-day year, and marks this as his guess.

Every number I checked in Morley and Förstemann is a count of days, so the 360 rule is the one we see. For counting other things I found no Maya source in what I read, and a plain base-20 reading (third place 400) is an inference.

The 2 cycles

A day also carries 2 names that repeat:

  • The 260-day count (the Tzolk'in, or tonalamatl in Morley). A number from 1 to 13 runs alongside 20 day names. Both advance by 1 each day, so the pair repeats after 260 days, the least common multiple of 13 and 20.
  • The 365-day count (the Haab'). 18 months of 20 days, numbered 0 to 19, then 5 days called Wayeb'. Morley explains that the first day of a month is written 0, "for not until one whole day" of the month had passed was it counted as 1.

The pair of names repeats every 18,980 days, the least common multiple of 260 and 365. That period is the Calendar Round, about 52 years.

The era date is 13.0.0.0.0 4 Ajaw 8 Kumk'u. Morley writes the same names in older spelling as 4 Ahau 8 Cumhu. Every Long Count date counts days forward from it.

What the sources leave open

  1. How the Maya calculated. The codices record results: day counts, the names they reach, and tables of multiples. They show no working. Any procedure for adding or multiplying is a modern reconstruction.
  2. Why the era date is written 13.0.0.0.0. On Stela C at Quirigua, as Morley reads it, a count of 13 bak'tuns ends on 4 Ahau 8 Cumhu, the era date, and modern writers give the era date as 13.0.0.0.0. In arithmetic the era date is day 0, and 13.0.0.0.0 is also the day 1,872,000 days later, in 2012.

Working an example: Dresden page 24

Page 24 of the Dresden Codex has 2 Long Count dates in neighboring columns. Morley reads the second as 9.9.9.16.0 1 Ahau 18 Kayab.

Step 1. Turn the places into days.

  • 9 × 144,000 = 1,296,000
  • 9 × 7,200 = 64,800
  • 9 × 360 = 3,240
  • 16 × 20 = 320
  • 0 × 1 = 0

The total is 1,364,360 days after the era date. Morley gets the same.

Step 2. Count on in the 260-day count. The era date is 4 Ajaw, and Ajaw is the 20th name.

  • Number: 1,364,360 leaves 10 when divided by 13. Counting 10 on from 4, and wrapping at 13, gives (4 - 1 + 10) mod 13 + 1 = 1.
  • Name: 1,364,360 leaves 0 when divided by 20, so the name is still Ajaw.

That gives 1 Ajaw, as written.

Step 3. Count on in the 365-day count. 8 Kumk'u is day 348 of the year, counting from 0 Pop as day 0, because Kumk'u is the 18th month: 17 × 20 + 8 = 348.

  • 1,364,360 leaves 355 when divided by 365.
  • (348 + 355) mod 365 = 338.
  • 338 = 16 × 20 + 18, and the 17th month is K'ayab.

That gives 18 K'ayab, as written. The day count and both names agree, so the page is internally consistent.

Step 4. Convert to our calendar. Add the GMT constant: 1,364,360 + 584,283 = Julian Day 1,948,643. That is 4 February 623 in the Julian calendar, or 7 February 623 in the proleptic Gregorian calendar.

The first date on the same page, 9.9.16.0.0, is 1,366,560 days. That is exactly 72 Calendar Rounds, so it falls on 4 Ajaw 8 Kumk'u, the same names as the era date. Morley points this out, and the test file checks both dates.

Why it works

A Long Count date is a mixed-radix number, a number whose places have different bases: here 20, 18, 20 and 20. The value is the sum of each digit times its place value, which is step 1 above. Going the other way, from a day count to the 5 places, is repeated division by 144,000, 7,200, 360 and 20, keeping each quotient.

The 2 cycles are remainders. The 260-day count is the day count modulo 13 and modulo 20, and the 365-day count is the day count modulo 365, each shifted by where the era date sits. Since 13 and 20 share no factor, the pair (number, name) takes all 260 combinations. Since 260 and 365 share the factor 5, only 18,980 of the 94,900 possible pairs of 260-day and 365-day names ever occur, 1 in 5.

Going from a Calendar Round date back to a day count is the Chinese remainder problem: find d with given remainders modulo 13, 20 and 365. The repo version solves it with the crt function from the kuttaka post, which handles divisors that share a factor. A pair that breaks the 1-in-5 rule, such as 1 Imix 1 Pop, raises an error.

The Python

This version converts a Long Count to the Calendar Round and to a Gregorian date. It runs on its own.

TZOLKIN = ["Imix", "Ik'", "Ak'bal", "K'an", "Chikchan", "Kimi", "Manik'", "Lamat", "Muluk", "Ok",
           "Chuwen", "Eb", "Ben", "Ix", "Men", "Kib", "Kaban", "Etz'nab", "Kawak", "Ajaw"]
HAAB = ["Pop", "Wo", "Sip", "Sotz'", "Sek", "Xul", "Yaxk'in", "Mol", "Ch'en", "Yax",
        "Sak'", "Keh", "Mak", "K'ank'in", "Muwan", "Pax", "K'ayab", "Kumk'u", "Wayeb'"]
PLACES = (144_000, 7_200, 360, 20, 1)  # bak'tun, k'atun, tun, winal, k'in
GMT = 584_283  # Julian Day Number of the era date


def days(long_count: tuple[int, ...]) -> int:
    """Days since the era date 13.0.0.0.0 4 Ajaw 8 Kumk'u."""
    return sum(value * size for value, size in zip(long_count, PLACES))


def calendar_round(d: int) -> str:
    """The 260-day and 365-day names of the day d days after the era date."""
    number = (4 - 1 + d) % 13 + 1  # the era date is 4 Ajaw
    name = TZOLKIN[(19 + d) % 20]
    position = (17 * 20 + 8 + d) % 365  # and 8 Kumk'u, month 17 counting from 0
    return f"{number} {name} {position % 20} {HAAB[position // 20]}"


def gregorian(jdn: int) -> tuple[int, int, int]:
    """Proleptic Gregorian date of a Julian Day Number; year 0 is 1 BCE."""
    a = jdn + 32044
    b = (4 * a + 3) // 146097
    c = a - 146097 * b // 4
    d = (4 * c + 3) // 1461
    e = c - 1461 * d // 4
    m = (5 * e + 2) // 153
    return 100 * b + d - 4800 + m // 10, m + 3 - 12 * (m // 10), e - (153 * m + 2) // 5 + 1


for lc in [(0, 0, 0, 0, 0), (9, 9, 9, 16, 0), (13, 0, 0, 0, 0)]:
    d = days(lc)
    print(".".join(map(str, lc)), d, calendar_round(d), gregorian(d + GMT))

It prints:

0.0.0.0.0 0 4 Ajaw 8 Kumk'u (-3113, 8, 11)
9.9.9.16.0 1364360 1 Ajaw 18 K'ayab (623, 2, 7)
13.0.0.0.0 1872000 4 Ajaw 3 K'ank'in (2012, 12, 21)

Year -3113 is 3114 BCE, because astronomers count a year 0. The era date is 11 August 3114 BCE in the proleptic Gregorian calendar and 6 September 3114 BCE in the Julian calendar. The gregorian function is the standard integer algorithm from Claus Tøndering's Calendar FAQ.

The repo version adds the reverse conversions, Julian calendar dates, bar-and-dot addition and the Calendar Round lookup. The tests check:

  • the era date: 4 Ajaw 8 Kumk'u, Julian Day 584,283, 11 August 3114 BCE Gregorian and 6 September Julian;
  • 13.0.0.0.0 4 Ajaw 3 K'ank'in on 21 December 2012, and 23 December under 584,285 and 24 December under 584,286, the dates Martin and Skidmore give;
  • 9.13.3.7.18 11 Etz'nab 11 Ch'en, the date on Lintel 3 of Temple I at Tikal, as 1,390,838 days and 6 August 695, the figures Kennett and co-authors give;
  • both Initial Series on Dresden page 24, and the 13 day names in its table of multiples of 2,920;
  • property tests with Hypothesis: Long Count round trips, the Calendar Round repeating every 18,980 days and no sooner, bar-and-dot addition against Python integers, the Venus-table periods returning to the same day names, and the Gregorian conversion against Python's datetime on random dates from year 1 to 9999.

Against the modern method

Modern software stores a date as a day count from an epoch, then derives the year, month and day. Python's date.toordinal() counts from 1 January of year 1, Unix time counts seconds from 1970, and astronomers use the Julian Day Number, which counts from noon on 1 January 4713 BCE in the Julian calendar. The Long Count is the same idea: a day count from an epoch, with the names of the day derived by remainders.

The differences are in the derived names:

  • Our calendar derives a year, a month and a day with irregular month lengths and leap-year rules, which is why the Gregorian conversion needs the formula above.
  • The Maya calendar derives the 260-day and 365-day names by plain remainders. The 365-day count has no leap day, so it drifts against the seasons by about a day every 4 years.

The Dresden Codex and its numbers

These are the parts of the Dresden Codex I checked against my code, keeping to what Morley (1915) and Förstemann (English translation, 1906) say is on the pages.

  • Page 24: multiples of 2,920. Besides the 2 dates above, the page has a table counting 2,920, 5,840, up to 35,040 days from 1 Ahau, each with the day it reaches: 9 Ahau, 4 Ahau, 12 Ahau, and so on, to 1 Ahau again at 37,960. Since 2,920 leaves 0 with 20 and 8 with 13, the name stays Ajaw and the number steps by 8. Morley notes that Förstemann restored parts of the top row, and calls a 4th row "probably an interpolation of some kind".
  • Pages 46 to 50: Venus. Morley describes a period of 2,920 days, which is 5 Venus cycles of 584 days and 8 years of 365 days, repeated 13 times to 37,960 days and then 3 times over, 113,880 days in all. 113,880 is a whole number of 260-day counts (438), 365-day years (312), 584-day Venus cycles (195) and Calendar Rounds (6). The tests check that 2,920 days later the 365-day date is the same, 37,960 days later the 260-day date is the same, and 113,880 days later the whole Calendar Round is the same.
  • Pages 51 to 58: the moon. Morley says these pages set down 405 lunar months, about 11,959 days.1

What the codex shows is the tables: day counts, multiples and the names they reach. It does not show how a scribe got them, and the purpose of several tables is still read in different ways.

Parallels and lineage

  • Base 60 in Mesopotamia. The scribes of YBC 7289 wrote a place-value system in base 60 about 2,000 years before the Classic Maya, with no mark for where the whole part of a number ends. The sources I read connect the 2 systems in no way.
  • Base 10 with a zero in India. Folkerts (2001) gives 595 CE for the oldest example of Indian decimal place value. The oldest known zero in an Indian inscription is at Gwalior, in a temple grant dated Vikrama year 933, which is 876 CE (Hultzsch 1892). The Maya and Indian systems grew up separately, with no contact in the sources I read. The Indian digits are the subject of the algorism post.
  • Day counts in astronomy. The Julian Day Number, which astronomers use, does the same job as the Long Count. Converting between them is a single addition.

What is debated

  • The correlation constant. The GMT correlation rests on colonial records that pair a Maya date with a European year, such as a massacre at Otzmal in 1536, according to Kennett and co-authors. Their 2013 radiocarbon dates on a wooden lintel from Tikal support the GMT family and rule out the other proposals they tested, which spread over nearly 1,000 years. A radiocarbon date cannot separate constants a few days apart, and Kennett and co-authors write of the "GMT family". Within it, Martin and Skidmore (2012, p. 3) call 584285 and 584283 "the two most widely accepted", and argue for 584286.
  • Julian or Gregorian dates. A date before 1582 can be given in either calendar. Kennett and co-authors give 6 August 695 for the Tikal lintel, which matches the proleptic Gregorian calendar; the Julian date is 3 August. The code returns both.
  • The 13 in the era date. Morley (1915) reports that Bowditch and Goodman took 13 bak'tuns to make the next unit, from the Quirigua and Palenque dates, and argues for 20 from the codices, where 20 of the 5th place make 1 of the 6th.
  • Who first used the Long Count. The earliest dates Kennett and co-authors cite are outside the Maya lowlands, and they say the system was "likely adopted from adjacent regions".

Key takeaways

  • Maya numerals are base 20, written with dots for 1, bars for 5 and a zero sign, stacked bottom to top.
  • In day counts the third place is 360 (18 × 20), which makes the 5 places of the Long Count: 1, 20, 360, 7,200 and 144,000 days.
  • The 260-day and 365-day names are remainders of the day count, and their pair repeats every 18,980 days.
  • Dresden page 24's 9.9.9.16.0 is 1,364,360 days, which is 1 Ajaw 18 K'ayab, as written, and 7 February 623 (Gregorian) under the GMT correlation.
  • The tie to our calendar rests on a correlation constant: 584,283 here, with 584,285 and 584,286 as the alternatives a few days apart. Radiocarbon supports this family of constants.

Sources

Footnotes

  1. Förstemann's commentary uses 11,960 days for the same pages. The tests use neither figure. ↩

Common questions

How do Maya numerals work?↓

Maya numerals use 3 signs: a dot for 1, a bar for 5 and a sign for 0. Digits from 0 to 19 are built from bars and dots, and digits are stacked from the bottom up, each place worth 20 times the one below. In counts of days the third place is worth 360 (18 times 20) instead of 400.

How did the Maya write 401?↓

As a plain base-20 number, 401 = 1 x 400 + 0 x 20 + 1, so it is a dot on top, a zero sign in the middle and a dot at the bottom. As a count of days, where the third place is 360, 401 days = 1 tun + 2 winals + 1 k'in, written 1.2.1: a dot, 2 dots, a dot.

How do you add Maya numbers?↓

Place by place from the bottom: put the bars and dots of both numbers together, turn every 5 dots into a bar, and turn every 4 bars into 1 dot in the place above. For example 7.13 (153) plus 5.9 (109) is 13.2 (262). No Maya text that survives describes the procedure; this is the modern reading of the notation.

Did the Maya calendar end on 21 December 2012?↓

On 21 December 2012, under the GMT correlation 584283, the Long Count reached 13.0.0.0.0 4 Ajaw 3 K'ank'in, the end of the 13th bak'tun. The count continues: 15 November 2026 is 13.0.14.1.17. Under 584285, which Martin and Skidmore (2012) count with 584283 as the 2 most widely accepted constants, it ended on 23 December 2012, and under their own 584286 on 24 December.

What is the GMT correlation?↓

The Goodman-Martinez-Thompson correlation is the constant that ties the Long Count to the Julian Day Number: the era date 13.0.0.0.0 is Julian Day 584283 (11 August 3114 BCE, proleptic Gregorian) or, in the other widely accepted value, 584285. It rests on colonial-era records, and radiocarbon dates from a Tikal lintel published in 2013 support the GMT family over other proposals.

Share this
← More writing Get in touch