Proving that $\gcd(2^m - 1, 2^n - 1) = 2^{\gcd(m,n )} - 1$

Somewhere on Stack Exchange I saw the equation

$$\gcd(2^m-1,2^n-1)=2^{\gcd(m,n)}-1.$$

I had never seen this before, so I started trying to prove it. Without success...

Can anyone explain me (so actually prove) why this equation is true?

And can we say the same when replacing the '$2$' by any integer number '$a$'?


In general, if $p=\gcd(m,n)$ then $p=mx+ny$ for some integers $x,y$.

Now, if $d = \gcd(2^m-1,2^n-1)$ then $2^m \equiv 1 \pmod d$ and $2^n \equiv 1\pmod d$ so $$2^p = 2^{mx+ny} = (2^m)^x(2^n)^y \equiv 1 \pmod d$$

So $d\mid 2^p-1$.

On the other hand, if $p\mid m$ then $2^p-1\mid 2^m-1$ so $2^p-1$ is a common factor.

And yes, you can replace $2$ with any $a$.


Hint $\rm\bmod d\!:\ a^{\large m}\!\equiv 1\equiv a^{\large n}\!\iff order(a)\mid m,n\iff order(a)\mid(m,n)\iff a^{\large (m,n)}\!\equiv 1$

Therefore $\rm\ \ d\mid a^{\large m}\!-1,\,a^{\large n}\!-1$ $\iff$ $\rm\:d\mid a^{\large (m,n)}\!-1,\ \,$ hence $\rm\,\ \ (a^{\large m}\!-1,\,a^{\large n}\!-1)\, =\, a^{\large (m,n)}-1$