How stems and branches, the sixty-pair cycle, nạp âm and the 28 mansions follow from the Julian day

A day's stem and branch is one remainder on the Julian day number. Take the Julian Day Number (JDN) of the solar date: the stem is (JDN + 9) modulo 10, the branch is (JDN + 1) modulo 12. Years, months, hours, nạp âm and the 28 mansions are counting cycles of the same kind, so they can be checked by invariants instead of trusting a hand-copied table.
What is the Julian Day Number?
The JDN counts days continuously from 1 January 4713 BCE, independent of months, years or calendar type. 1 January 1900 is JDN 2,415,021; 19 November 2026 is JDN 2,461,364. Because it is a running count, the switch from the Julian to the Gregorian calendar (4 October 1582 followed directly by 15 October 1582) does not break the stem-branch cycle.
How are the day, year, month and hour computed?
Indexes start at 0: Giáp is 0, Tý is 0.
| Pillar | Formula | Example |
|---|---|---|
| Day | stem = (JDN + 9) mod 10; branch = (JDN + 1) mod 12 | 19 Nov 2026: JDN 2,461,364 gives 3 and 9, i.e. Đinh Dậu |
| Year | stem = (lunar year − 4) mod 10; branch = (lunar year − 4) mod 12 | 2026: 2022 mod 10 = 2, 2022 mod 12 = 6, i.e. Bính Ngọ |
| Lunar month | branch by month number (month 1 is Dần); stem of month 1 = (2 × year stem + 2) mod 10, then count on | a Bính year: month 1 is Canh Dần |
| Hour | branch by two-hour period (Tý from 23:00 to 01:00); stem of the Tý hour = (day stem mod 5) × 2, then count on | a Đinh day: the Tý hour is Canh Tý |
The months in this table are lunar months. Bát Tự takes months by solar terms, so its month pillar can differ; see the Bát Tự post.
Why is the cycle 60 and not 120?
60 is the least common multiple of 10 and 12. Stem and branch both advance one step a day, so even stems only pair with even branches and odd with odd. Half of the 120 possible pairs, such as "Giáp Sửu", never occur.
How does nạp âm attach to the stems and branches?
Thirty nạp âm names, each covering exactly two consecutive pairs of the cycle: Giáp Tý and Ất Sửu are Hải Trung Kim, Bính Dần and Đinh Mão are Lư Trung Hỏa. Nạp âm is a traditional lookup table, not derived from astronomy; the code only guarantees the table is read correctly.

Stems and branches are calendar counting and can be checked numerically. Elements, nạp âm and linking mansions to auspicious days are traditional conventions of particular schools, not scientifically verified.
How are the 28 mansions checked?
The 28-mansion cycle is locked to the seven-day week, because 28 is divisible by 7. Each mansion belongs to one of the seven luminaries, and each luminary to a fixed weekday: the mansion Đẩu belongs to Jupiter, so it always falls on a Thursday, and 19 Nov 2026 is indeed a Thursday. Shift the starting point by one day and the whole table is off, which anyone can check against a weekly calendar.
Which invariants do the tests hold?
- The 60-cycle never breaks: every day from 1 Jan 1900 to 31 Dec 2100 has the stem-branch right after the previous day's, including across the 1582 calendar switch.
- Recorded dates: the formula must give the stem-branch of days recorded in historical texts, checked by an entirely different calculation route. The oldest is the Kỷ Tỵ solar eclipse in the third year of Duke Yin of Lu, recorded in the Spring and Autumn Annals and dated by astronomers to 22 February 720 BCE.
- Nạp âm: every year from 1900 to 2100 belongs to exactly one nạp âm, and the year's stem-branch must look up to the name of the group that contains it.
- 28 mansions: on every day from 2020 to 2030 the mansion's luminary matches the real weekday; the cycle has 28 distinct mansions in four groups of seven.
Where are the data and code?
Day, month and year stem-branches are in the 1900 to 2100 lunar calendar dataset and the sixty-pair table on the Open data page; the code is on the Open code and data page.
- The lunar calendar beneath these counts: the post on the lunar calendar and the 24 solar terms.
- Check your own library against the shared answer key: the post on testing a library with the test cases.
If you reuse these figures, please credit: Data: Nhat Nguyet (nhatnguyet.org).




