Why does a number like $2^n\bmod 7$ have a repeating pattern? I am struggling with the formal understanding of why a number like $2^n\bmod7$ have a repeating pattern? $1, 2, 4, 1, 2 ,4\ldots$

The repeating pattern show up in many places of modular arithmetic, what is the primary reason for this?

Thank you
Consider a sequence $a^1, a^2, a^3,\ldots$, all taken $\mod{n}$. We only assume a  finite number of values (at most $n$), and the sequence is infinite, so after at most $n+1$ many terms we have a repetition, say $a^i = a^j$ ($\mod{n}$,for some $i &lt;j$). But this means that the sequence will repeat after $j$ again: $a^{j+1} = a^{i+1}$ and so on, till we have again $j-i$ terms, after which we are back again etc. Because you have a prime modulus in your example, $a^{n-1} = 1$, so we actually cycle back to the starting value. In general you might get a start sequence and then the repeating part (between $a^i$ and $a^j$).
$1\cdot 1=1=0\cdot7+1$

$1\cdot 2=2=0\cdot7+2$

$1\cdot 4=4=0\cdot7+4$

$2\cdot 2=4=0\cdot7+4$

$2\cdot4=8=1\cdot7+1$

$4\cdot4=16=2\cdot7+2$