# Patterns in the Last Digits of the Positive Powers of Two

Copyright © 2008-2015 Exploring Binary

http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/

The positive powers of two — 2, 4, 8, 16, 32, 64, 128, 256, … — follow an obvious repeating pattern in their ending digit: 2, 4, 8, 6, 2, 4, 8, 6, … . This cycle of four digits continues forever. There are also cycles beyond the last digit — in the last *m* digits in fact — in the powers of two from 2^{m} on. For example, the last two digits repeat in a cycle of length 20 starting with 04, and the last three digits repeat in a cycle of length 100 starting with 008.

In this article, I will show you why these cycles exist, how long they are, how they are expressed mathematically, and how to visualize them.

## Cycle in the Last Digit

The last digit — the ones place — of a decimal integer d is the remainder of the division d/10. Equivalently, the last digit is the result of the operation *d **mod** 10*, when following the convention that the least nonnegative value — the common residue — is returned. Modular arithmetic, combined with iterative generation of the positive powers of two, allows us to show the cycle in the last digit:

- …

We start with 2, compute it mod 10, multiply that result by 2, compute *it* mod 10, etc. From this it’s clear the pattern will repeat, once a previous result — 2 in this case, at step 5 — is obtained. This shows that the numbers 2^{n}, n ≥ 1, cycle through the four ending digits 2, 4, 8, and 6.

The cycle implies that powers of two with the same ending digit are related, their exponents differing by a multiple of four:

**Ends in 2:**2^{1}, 2^{5}, 2^{9}, 2^{13}, 2^{17}, … .**Ends in 4:**2^{2}, 2^{6}, 2^{10}, 2^{14}, 2^{18}, … .**Ends in 8:**2^{3}, 2^{7}, 2^{11}, 2^{15}, 2^{19}, … .**Ends in 6:**2^{4}, 2^{8}, 2^{12}, 2^{16}, 2^{20}, … .

You can express these relationships more succinctly using the laws of exponents, showing explicitly that the ending digit of the first four positive powers of two determine the ending digit of *all* positive powers of two:

**Ends in 2:**2^{1}·2^{4k}, or 2^{1+4k}, k ≥ 0.**Ends in 4:**2^{2}·2^{4k}, or 2^{2+4k}, k ≥ 0.**Ends in 8:**2^{3}·2^{4k}, or 2^{3+4k}, k ≥ 0.**Ends in 6:**2^{4}·2^{4k}, or 2^{4+4k}, k ≥ 0.

You can also relate the positive powers of two to their ending digits based on their exponents (n) mod 4:

**Ends in 2:****Ends in 4:****Ends in 8:****Ends in 6:**

This gives an easy way to determine the last digit of any positive power of two. For example, the last digit of 2^{319} is 8, since .

Power of Two (k ≥ 0) | Exponent (mod 4) | Last Digit |
---|---|---|

2^{1+4k} |
1 | 2 |

2^{2+4k} |
2 | 4 |

2^{3+4k} |
3 | 8 |

2^{4+4k} |
0 | 6 |

In summary, the table says that if , .

## Cycle in the Last Two Digits

A similar analysis, but using **mod 100**, shows that the **last two digits** of the powers of two, **starting at 2 ^{2}**, cycle with a

**period of 20**:

Power of Two (k ≥ 0) | Exponent (mod 20) | Last 2 Digits |
---|---|---|

2^{2+20k} |
2 | 04 |

2^{3+20k} |
3 | 08 |

2^{4+20k} |
4 | 16 |

2^{5+20k} |
5 | 32 |

2^{6+20k} |
6 | 64 |

2^{7+20k} |
7 | 28 |

2^{8+20k} |
8 | 56 |

2^{9+20k} |
9 | 12 |

2^{10+20k} |
10 | 24 |

2^{11+20k} |
11 | 48 |

2^{12+20k} |
12 | 96 |

2^{13+20k} |
13 | 92 |

2^{14+20k} |
14 | 84 |

2^{15+20k} |
15 | 68 |

2^{16+20k} |
16 | 36 |

2^{17+20k} |
17 | 72 |

2^{18+20k} |
18 | 44 |

2^{19+20k} |
19 | 88 |

2^{20+20k} |
0 | 76 |

2^{21+20k} |
1 | 52 |

## Cycle in the Last Three Digits

To determine the cycle in the **last three digits**, repeat the same process using **mod 1000**. It shows that the powers of two, **starting at 2 ^{3}**, cycle with a

**period of 100**:

Power of Two (k ≥ 0) | Exponent (mod 100) | Last 3 Digits |
---|---|---|

2^{3+100k} |
3 | 008 |

2^{4+100k} |
4 | 016 |

2^{5+100k} |
5 | 032 |

2^{6+100k} |
6 | 064 |

2^{7+100k} |
7 | 128 |

2^{8+100k} |
8 | 256 |

2^{9+100k} |
9 | 512 |

2^{10+100k} |
10 | 024 |

2^{11+100k} |
11 | 048 |

2^{12+100k} |
12 | 096 |

2^{13+100k} |
13 | 192 |

2^{14+100k} |
14 | 384 |

2^{15+100k} |
15 | 768 |

2^{16+100k} |
16 | 536 |

2^{17+100k} |
17 | 072 |

2^{18+100k} |
18 | 144 |

2^{19+100k} |
19 | 288 |

2^{20+100k} |
20 | 576 |

2^{21+100k} |
21 | 152 |

2^{22+100k} |
22 | 304 |

2^{23+100k} |
23 | 608 |

2^{24+100k} |
24 | 216 |

2^{25+100k} |
25 | 432 |

2^{26+100k} |
26 | 864 |

2^{27+100k} |
27 | 728 |

2^{28+100k} |
28 | 456 |

2^{29+100k} |
29 | 912 |

2^{30+100k} |
30 | 824 |

2^{31+100k} |
31 | 648 |

2^{32+100k} |
32 | 296 |

2^{33+100k} |
33 | 592 |

2^{34+100k} |
34 | 184 |

2^{35+100k} |
35 | 368 |

2^{36+100k} |
36 | 736 |

2^{37+100k} |
37 | 472 |

2^{38+100k} |
38 | 944 |

2^{39+100k} |
39 | 888 |

2^{40+100k} |
40 | 776 |

2^{41+100k} |
41 | 552 |

2^{42+100k} |
42 | 104 |

2^{43+100k} |
43 | 208 |

2^{44+100k} |
44 | 416 |

2^{45+100k} |
45 | 832 |

2^{46+100k} |
46 | 664 |

2^{47+100k} |
47 | 328 |

2^{48+100k} |
48 | 656 |

2^{49+100k} |
49 | 312 |

2^{50+100k} |
50 | 624 |

2^{51+100k} |
51 | 248 |

2^{52+100k} |
52 | 496 |

2^{53+100k} |
53 | 992 |

2^{54+100k} |
54 | 984 |

2^{55+100k} |
55 | 968 |

2^{56+100k} |
56 | 936 |

2^{57+100k} |
57 | 872 |

2^{58+100k} |
58 | 744 |

2^{59+100k} |
59 | 488 |

2^{60+100k} |
60 | 976 |

2^{61+100k} |
61 | 952 |

2^{62+100k} |
62 | 904 |

2^{63+100k} |
63 | 808 |

2^{64+100k} |
64 | 616 |

2^{65+100k} |
65 | 232 |

2^{66+100k} |
66 | 464 |

2^{67+100k} |
67 | 928 |

2^{68+100k} |
68 | 856 |

2^{69+100k} |
69 | 712 |

2^{70+100k} |
70 | 424 |

2^{71+100k} |
71 | 848 |

2^{72+100k} |
72 | 696 |

2^{73+100k} |
73 | 392 |

2^{74+100k} |
74 | 784 |

2^{75+100k} |
75 | 568 |

2^{76+100k} |
76 | 136 |

2^{77+100k} |
77 | 272 |

2^{78+100k} |
78 | 544 |

2^{79+100k} |
79 | 088 |

2^{80+100k} |
80 | 176 |

2^{81+100k} |
81 | 352 |

2^{82+100k} |
82 | 704 |

2^{83+100k} |
83 | 408 |

2^{84+100k} |
84 | 816 |

2^{85+100k} |
85 | 632 |

2^{86+100k} |
86 | 264 |

2^{87+100k} |
87 | 528 |

2^{88+100k} |
88 | 056 |

2^{89+100k} |
89 | 112 |

2^{90+100k} |
90 | 224 |

2^{91+100k} |
91 | 448 |

2^{92+100k} |
92 | 896 |

2^{93+100k} |
93 | 792 |

2^{94+100k} |
94 | 584 |

2^{95+100k} |
95 | 168 |

2^{96+100k} |
96 | 336 |

2^{97+100k} |
97 | 672 |

2^{98+100k} |
98 | 344 |

2^{99+100k} |
99 | 688 |

2^{100+100k} |
0 | 376 |

2^{101+100k} |
1 | 752 |

2^{102+100k} |
2 | 504 |

## Cycle in the Last m Digits

The last m digits of a positive power of two are taken mod 10^{m}, and have a cycle of period 4·5^{m-1}, starting at 2^{m}. (The proof involves techniques of number theory, and is beyond the scope of this article.)

m | Period (4·5^{m-1}) |
Starts with |
---|---|---|

1 | 4 | 2^{1} |

2 | 20 | 2^{2} |

3 | 100 | 2^{3} |

4 | 500 | 2^{4} |

5 | 2500 | 2^{5} |

6 | 12500 | 2^{6} |

7 | 62500 | 2^{7} |

8 | 312500 | 2^{8} |

9 | 1562500 | 2^{9} |

10 | 7812500 | 2^{10} |

The periods grow very fast — exponentially — so it is impractical to list tables of ending digits for m greater than three.

## Nesting of Cycles

The cycles in m digit, m-1 digit, m-2 digit, …, 1 digit endings can be viewed as nested, even though their starting points are staggered. You just have shift the starting points of the lesser digit cycles to make them coincide.

For example, one copy of the length 100 cycle of three digit endings has within it five copies of the length 20 cycle of two digit endings; one copy of the length 20 cycle of two digit endings has within it five copies of the length 4 cycle of one digit endings. This works when you view the one digit ending cycle as starting at 8 (shifted two positions), the two digit ending cycle as starting at 08 (shifted one position), and the three digit ending cycle as starting at 008 (not shifted).

The diagram below shows the nesting by shading every other occurrence of a cycle (the 100s place is fully shaded, because only 100 powers of two — one cycle of the last three ending digits — are shown).

## Exploring Ending Digits with PARI/GP

I used PARI/GP to make some of the calculations above and to check my work. Here are three examples:

**Print the first 20 powers of two that end in 2**:?

**for (i=0,19,print("2^",1+4*i,": ",2^(1+4*i)))**2^1: 2 2^5: 32 2^9: 512 2^13: 8192 2^17: 131072 2^21: 2097152 2^25: 33554432 2^29: 536870912 2^33: 8589934592 2^37: 137438953472 2^41: 2199023255552 2^45: 35184372088832 2^49: 562949953421312 2^53: 9007199254740992 2^57: 144115188075855872 2^61: 2305843009213693952 2^65: 36893488147419103232 2^69: 590295810358705651712 2^73: 9444732965739290427392 2^77: 151115727451828646838272**Print the cycle of the last two digits**(the ‘%’ operator returns the remainder, which in effect is how we’re using modular arithmetic):?

**for (i=2,21,print("2^",i," mod(100): ",2^i % 100))**2^2 mod(100): 4 2^3 mod(100): 8 2^4 mod(100): 16 2^5 mod(100): 32 2^6 mod(100): 64 2^7 mod(100): 28 2^8 mod(100): 56 2^9 mod(100): 12 2^10 mod(100): 24 2^11 mod(100): 48 2^12 mod(100): 96 2^13 mod(100): 92 2^14 mod(100): 84 2^15 mod(100): 68 2^16 mod(100): 36 2^17 mod(100): 72 2^18 mod(100): 44 2^19 mod(100): 88 2^20 mod(100): 76 2^21 mod(100): 52(Single-digit results have an implicit leading 0.)

**Print the period of the last 1 to 10 digits**:?

**for (i=1,10,print(i,": ",4*5^(i-1)))**1: 4 2: 20 3: 100 4: 500 5: 2500 6: 12500 7: 62500 8: 312500 9: 1562500 10: 7812500

November 6th, 2009 at 3:08 am

[…] Rick Regan of Exploring Binary finds patterns in the last digits of the positive powers of two. […]

December 15th, 2010 at 1:38 pm

I also noticed the digits of the powers of two cycled with a period growing by a factor of five per digit. Never thought to google the result.

I proved it as well but I did it more simply using group theory. Starting from the assumption that the period didn’t multiply by five per digit I arrived at a non-commutative cyclic group. But we know that all cyclic groups are Abelian.

December 15th, 2010 at 2:53 pm

David,

Yes, my proof is a little long, though I was happy the way it turned out (it took quite a bit of work to do). If your proof is simpler, I’d love to see it, or at least some more of the details.

BTW, would your technique work for proving the cycle length of powers of

fivemod powers of ten? I rather liked how I did that one, with the recursive factoring of differences of squares.January 31st, 2013 at 9:07 pm

How about the pattern of powers of nine?

January 31st, 2013 at 9:51 pm

I discuss powers of two and powers of five (in another article) because they are related to the binary representation of numbers. Any particular reason you are interested in powers of nine?

(In any case you could work it out similarly: last digit cycle is 1, 9; last two digits cycle is 01, 09, 81, 29, 61, 49, 41, 69, 21, 89; … Note I started out with 9

^{0}, so this coversnonnegativepowers.)June 25th, 2013 at 9:54 am

what is the last digit of 7 to the power 73 and explain

October 4th, 2014 at 5:43 pm

You wrote “In summary, the table says that if x = y (mod 4), 2^x = 2^y (mod 10).”, which holds true for y=1,2,3, but not for y=0.

October 4th, 2014 at 7:38 pm

@Chris Shannon,

The article addresses only positive powers of two, so it is implied that x and y are > 0.

January 13th, 2015 at 12:21 pm

hey, can u also show how to get the last three digits of 3 raised to an exponent?

January 13th, 2015 at 12:43 pm

@trella,

Just work it out similarly with 3 instead of 2 as the base.