How to Find the Last Digits of an Enormous Power
Use cycles, repeated squaring, Euler's theorem and the Chinese remainder theorem to get the final digits of huge powers by hand.
Key takeaways
- The last k digits of a number are its remainder modulo 10^k, and you may reduce at every step of a calculation.
- Last digits of powers repeat with period 1, 2 or 4, depending on the final digit of the base.
- When the base shares no factor with 10, the exponent can be reduced using Euler's theorem or the shorter Carmichael period.
- When the base is even or a multiple of 5, split the modulus into prime powers and recombine.
- Repeated squaring works in every case and needs only about as many steps as the exponent has binary digits.
The last digit of a number is its remainder on division by 10, and the last two digits are its remainder on division by 100. So you never need to write out 7^222 to know how it ends. You only need to track remainders, and remainders of powers eventually repeat.
The last digit of 7^222 is 9. This article shows how to get that answer in one line, and how to handle two or three final digits when the exponent runs into the thousands or beyond.
Why you can discard everything else
If two numbers have the same last two digits, so do their products with any third number. In symbols, if a ≡ b (mod 100) then ac ≡ bc (mod 100). The hundreds and higher places can never influence the final two places of a product.
That means a long multiplication can be trimmed after every step. To get the end of 7⁵, compute 7, 49, 43 (from 343), 01 (from 301), 07. The full value 16807 does end in 07. This is clock arithmetic with a 100-hour clock.
One last digit: find the cycle
Multiply repeatedly by the same base and there are only ten possible last digits, so a repeat must come soon.
| base ends in | last digits of successive powers | period |
|---|---|---|
| 0, 1, 5 or 6 | stays the same | 1 |
| 4 | 4, 6 | 2 |
| 9 | 9, 1 | 2 |
| 2 | 2, 4, 8, 6 | 4 |
| 3 | 3, 9, 7, 1 | 4 |
| 7 | 7, 9, 3, 1 | 4 |
| 8 | 8, 4, 2, 6 | 4 |
For 7^222, divide the exponent by the period: 222 = 4 × 55 + 2. The answer is the second entry in the row for 7, which is 9. If the remainder is 0, take the last entry in the row.
Only the final digit of the base matters. The number 1237^222 ends in 9 for the same reason.
Why a cycle is guaranteed
The repetition is no coincidence. There are only finitely many remainders modulo n, so the list a, a², a³ and so on must eventually produce a value it has produced before. This is the pigeonhole principle. From that moment the list repeats forever, because each term is determined by the one before it.
The cycle need not include the first few terms. Modulo 8, the powers of 2 are 2, 4, 0, 0, 0 and so on. When the base is coprime to the modulus, however, you can run the multiplication backward, and so the cycle starts right at the first term.
To find a cycle by hand, keep multiplying by the base and stop at the first repeated value. Note where that value appeared earlier. The distance between the two appearances is the period. Then locate your exponent inside the repeating part by taking a remainder.
Two digits with Euler's theorem
Euler's theorem states that if gcd(a, n) = 1, then a^φ(n) ≡ 1 (mod n), where φ(n) counts the integers from 1 to n coprime to n. For n = 100 we have φ(100) = 40. So for any base not divisible by 2 or 5, exponents can be reduced modulo 40.
Take 3^1000. Since 1000 = 25 × 40, we get 3^1000 ≡ 1, so it ends in 01.
In fact a shorter period always works. Every number coprime to 100 satisfies a^20 ≡ 1 (mod 100). The value 20 is called the Carmichael function of 100. For three digits, φ(1000) = 400 but the Carmichael value is 100, so reducing exponents modulo 100 is enough.
For particular bases the cycle can be shorter still. The powers of 7 modulo 100 run 07, 49, 43, 01, a cycle of length 4. Since 2026 leaves remainder 2 on division by 4, the number 7^2026 ends in 49.
Repeated squaring: the all-purpose method
Write the exponent as a sum of powers of 2, square again and again, and multiply the pieces you need. Here is 3^45 modulo 100, with 45 = 32 + 8 + 4 + 1.
3^1 = 03
3^2 = 09
3^4 = 81
3^8 = 61 from 81² = 6561
3^16 = 21 from 61² = 3721
3^32 = 41 from 21² = 441
3^45 = 41 · 61 · 81 · 03
41 · 61 = 2501 → 01
01 · 81 → 81
81 · 03 = 243 → 43 The answer is 43. Cross-check with the period: 45 leaves remainder 5 modulo 20, and 3⁵ = 243 also ends in 43.
Repeated squaring needs no theory and no coprime condition. An exponent with a million binary digits would take at most about two million multiplications. The same routine is the engine inside RSA and many primality tests.
When the base shares a factor with 10
Euler's theorem does not apply to 2^1000 modulo 100, and applying it anyway would wrongly suggest 01. Split 100 into 4 × 25.
- Modulo 4: 2^1000 is divisible by 4, so the remainder is 0.
- Modulo 25: φ(25) = 20 and gcd(2, 25) = 1. Since 1000 = 50 × 20, the remainder is 1.
Now find the number from 0 to 99 that is divisible by 4 and leaves remainder 1 modulo 25. The candidates are 1, 26, 51 and 76, and only 76 is divisible by 4. So 2^1000 ends in 76. This recombination is the Chinese remainder theorem.
The powers of 2 do become periodic modulo 100, with period 20, but only from 2² onward. The first term, 02, never returns. For example 2^31 ends like 2^11 = 2048, in 48, so the prime 2^31 − 1 ends in 47.
Going to three digits
The same tools work modulo 1000. Find the last three digits of 3^2026. Since 3 is coprime to 1000 and the Carmichael period is 100, reduce the exponent to 26.
3^10 = 59049 → 049
3^20 → 49² = 2401 → 401
3^6 = 729
3^26 → 401 × 729 = 292329 → 329 So 3^2026 ends in 329. For an even base, split 1000 into 8 × 125. For 2^100, the remainder modulo 8 is 0. Since φ(125) = 100, the remainder modulo 125 is 1. The numbers below 1000 that leave remainder 1 modulo 125 are 1, 126, 251, 376 and so on, and the first divisible by 8 is 376. Therefore 2^100 ends in 376.
Choosing a method
Several routes lead to the same digits, and the quickest depends on the numbers in front of you.
| situation | quickest tool | what to check |
|---|---|---|
| one final digit | the cycle table | remainder of the exponent by 1, 2 or 4 |
| base coprime to 10, two or three digits | reduce the exponent by the period | gcd of base and 10 is 1 |
| base even or a multiple of 5 | split into prime powers and recombine | exponent large enough for one part to vanish |
| base next to a multiple of 10 | binomial expansion | which terms disappear |
| anything else | repeated squaring | reduce after every product |
When two methods apply, use the second as a check. A disagreement almost always traces to an exponent reduced by the wrong number.
The binomial shortcut
Bases next to a multiple of 10 yield to the binomial theorem. Write 11^n = (10 + 1)^n. Every term with 10² or higher is divisible by 100, leaving
11^n ≡ 10n + 1 (mod 100)
11^2026 ≡ 20261 ≡ 61 Similarly 101^n ≡ 100n + 1 (mod 1000). Bases such as 49 or 51 can be written as 50 minus or plus 1 and treated the same way.
Towers of exponents
What are the last two digits of 7^(7^7)? The exponent is 823543, though you do not even need it. Powers of 7 repeat with period 4 modulo 100, so you only need 7^7 modulo 4. Since 7 ≡ −1 (mod 4), 7^7 ≡ (−1)^7 ≡ 3. The answer matches 7³ = 343, so the tower ends in 43.
The pattern for taller towers is the same: work from the top down, each time asking for the exponent modulo the period of the level below. The periods shrink quickly, which is why the final digits of very tall towers stop changing as you add floors. This idea matters when people discuss the ending digits of Graham's number, a quantity far too large to write out.
Sums with huge terms
Remainders also respect addition, so a long sum can be handled term by term. What are the last two digits of 1! + 2! + 3! + ... + 100!? Here n! is the product of the whole numbers from 1 to n.
From 10! onward each factorial contains two factors of 5 and plenty of factors of 2, so it ends in 00. Only the first nine terms count: 1 + 2 + 6 + 24 + 120 + 720 + 5040 + 40320 + 362880 = 409113. The answer is 13.
The lesson carries over to powers: before computing anything, ask which parts of the expression can influence the final digits at all.
Mistakes to avoid
- Reducing the exponent modulo 100. Exponents reduce by the period, which is 20, 4 or something else, never automatically by the modulus.
- Using Euler's theorem when gcd(base, modulus) is not 1.
- Reading a remainder of 0 on the exponent as "the zeroth power". It means the last entry of the cycle, except for a true exponent of 0.
- Dropping leading zeros. A result of 1 modulo 100 means the digits are 01.
- Expecting this to reveal the first digits. Leading digits depend on the fractional part of n × log₁₀(base), a different computation involving logarithms.
What the last digits can tell you
Final digits are a cheap test of larger claims. Every square ends in 0, 1, 4, 5, 6 or 9, so a number ending in 7 is never a square. A fourth power of a number not divisible by 2 or 5 ends in 1. Someone who reports a huge value for 3^100 ending in 7 has made a mistake, because 100 is a multiple of 4 and the last digit must be 1.
The converse does not hold. A number ending in 1 need not be the right answer, or a square, or anything else. Matching digits can only fail to disprove a claim. The same logic of remainders is used to show that some whole-number equations have no solutions.
Curiously, some endings are stable under powers. Numbers ending in 25 keep ending in 25 when raised to any positive power, and so do numbers ending in 76. In both cases the two-digit ending squares to itself: 25² = 625 and 76² = 5776.
Practice problems
- Last digit of 8^99: since 99 leaves remainder 3 modulo 4, take the third entry of 8, 4, 2, 6. The digit is 2.
- Last two digits of 9^100: the exponent is a multiple of 20 and gcd(9, 100) = 1, so the answer is 01.
- Last digit of 3^50 + 4^50: 50 leaves remainder 2 modulo 4, so 3^50 ends in 9. The exponent is even, so 4^50 ends in 6. The sum ends in 5.
Whenever you finish one of these, test the method on a small exponent that you can compute directly. A thirty-second check catches most errors in a cycle that is off by one.