A Mersenne prime is a prime of the form $2^n-1$.

A Fermat prime is a prime of the form $2^n+1$.

Despite the two being superficially very similar, it is conjectured that there are infinitely many Mersenne primes but only finitely many Fermat primes.

Is there an intuition that can help me appreciate the nature of that seemingly paradoxical difference?

  • 1
    $\begingroup$ ... which is of the form $2^n+1$ :) $\endgroup$
    – user139000
    Jun 18, 2014 at 17:09
  • 1
    $\begingroup$ Well, but you're really pushing the similarity like that. Any number is of the form $n$ for some $n$! $\endgroup$
    – Pedro
    Jun 18, 2014 at 17:10
  • 4
    $\begingroup$ It is easy to show that if $2^n+1$ is prime, then $n$ must be a power of $2$. The powers of $2$ are sparse, so the Fermat candidates for primality grow very very rapidly. $\endgroup$ Jun 18, 2014 at 17:10
  • 2
    $\begingroup$ @PedroTamaroff: $2^n + 1$ is prime only when $n$ is a power of $2$. And $2^n - 1$ is prime only when $n$ is a prime numer. So the Mersenne primes are precisely those primes of the form $2^n - 1$, and the Fermat primes precisely those of the form $2^n + 1$. (This is differnet from a hypothetical like "primes of the form $n$", as that would include more primes.) $\endgroup$ Jun 18, 2014 at 17:26
  • 2
    $\begingroup$ What separated primes of the form $n^2-1$ from primes of the form $n^2+1$? Those are superficially very similar, yet it is trivial to see that only $p=3$ is of the first form, yet hard to study the primes of the second type. $\endgroup$
    – N. S.
    Jan 23, 2020 at 23:21

4 Answers 4


It's easy to get that for Mersenne primes $n$ must be prime, and for Fermat primes $n$ must be a power of 2. Let's go to the hueristics.

Being prime is of course not random, but it is often useful to think of it as a random property of numbers. The prime number theorem tells us that a large number $n$ is prime with probability approximately $\frac{1}{ln(n)}$, using this lets compute the expected number of Mersenne primes throwing out the ones we know can't be prime.

$$\sum_{p \text{ prime}} \frac{1}{ln(2^p-1)} \sim c\sum_{p \text{ prime}}\frac{1}{p}$$

Which we know diverges, hence we expect infinitely many Mersenne primes. Moreover the rate of divergence tells us about how many Mersenne primes to expect up to a certain size. On the other hand, if we do the same analysis for Fermat primes:

$$\sum_{n} \frac{1}{ln(2^{2^n}+1)} \sim c\sum_{n}\frac{1}{2^n}$$

We get a convergent geometric series, hence we only expect finitely many such primes.

  • $\begingroup$ So again, we have to rely on the "random" assumption. Are these heuristics the only reason to believe that there are infinitely many Mersenne primes and finitely many Fermat primes? $\endgroup$
    – user139000
    Jun 19, 2014 at 7:06
  • 2
    $\begingroup$ @pew: The "random" heuristic is a very powerful one, coming from the deep and profound prime number theorem. With appropriate modifications, it is consistent with all results proved so far about prime numbers. See for instance here, here, here... $\endgroup$ Jun 19, 2014 at 9:01
  • 1
    $\begingroup$ The way I interpret these random hueristics is by translating the sentence "there are infinitely many Fermat primes" into "There is a reason why prime numbers strongly prefer to be one more than a power of two" and the sentence "There are finitely many Fermat primes" as "Prime numbers don't give a **** about powers of two". $\endgroup$
    – Nate
    Jun 19, 2014 at 21:15
  • $\begingroup$ $ln$ instead of $\log$ makes me cringe. :( $\endgroup$
    – Dzoooks
    Mar 18, 2020 at 2:34

There is this observation:

$2^n-1$ is a candidate prime (no obvious factors) whenever $n$ is prime.

$2^n+1$ is a candidate prime only when $n=2^r$ (if $n$ is divisible by an odd prime $p$, so $n=pq$ one can extract a factor $2^q+1$, because $x^p+1$ has a factor $x+1$ - use $x=2^q$)

The candidates for Mersenne Primes occur considerably more frequently than the candidates for Fermat Primes.

  • 1
    $\begingroup$ +1, though this argument presupposes that whether a "candidate" number fulfills the condition (in this case, being prime) is essentially a random process, so the more candidates one brings, the more numbers fulfilling the condition one gets. Is there a further argument that can support this line of reasoning? $\endgroup$
    – user139000
    Jun 18, 2014 at 17:20
  • $\begingroup$ @pew Others are writing notes on that. One fact is that as time has gone on and computing resources and mathematical insights have developed, people have managed to find more and more Mersenne primes, but no more Fermat Primes have been discovered beyond $65537$. $\endgroup$ Jun 18, 2014 at 17:28
  • $\begingroup$ One important reason for why so many Mersenne primes were discovered is that a very efficient primality test exists for them, the Lucas-Lehmer test. $\endgroup$
    – user139000
    Jun 19, 2014 at 7:09
  • $\begingroup$ The Mersenne analysis can even be used to approximate the number of Mersenne primes $\le n$ as $\sum_{k=1}^{\ln n/\ln 2}\frac{1}{k\ln 2}\sim c\ln\ln n$. $\endgroup$
    – J.G.
    Jan 31, 2020 at 20:50

Nearly everything:

Exponent required

Mersenne prime exponents only, and not on first kind cunningham chains except two places.

Fermat power of two exponent

Factor type

Mersenne $q=2kp+1$ for prime exponent $p$, $q\equiv \pm 1 \pmod 8$ restricting $k$ ( modified P-1 used as well as TF)

Fermat $j\cdot 2^{n+2} +1$ with restrictions on $j$ fully dependent on $n$

Primality test

Mersenne iterating $x^2-2$ from a starting value of 4, $p-2$ times, attempting to show $s_{p-2}\equiv 0\pmod {2^p-1}$ ( traditionally, now pretested via a PRP and checked with error checking)

Fermat repeated squaring to show $3^{{F_n-1 \over 2}}\equiv -1\pmod {F_n}$


Mersenne numbers( non prime exponent definition) double and add 1.

Fermat numbers $F_n=(F_{n-1}-1)^2+1$ or in comparison to a Double Mersenne ( a Mersenne number with Mersenne exponent) $F_n=2\cdot M_{M_n}+3$

Double Mersenne facts : $M_{M_n}=2M_{M_{n-1}}^2+4\cdot M_{M_{n-1}}+1$ prime final exponents $p$ have factors that are of form $2j(2kp+1)+1= 4kjp+(2j+1)$

There are heuristics you can throw around, but in the end heuristic arguments are hard to test for Fermat numbers due to size ( We'll probably factor $M_{M_{127}}$ before $F_{127}$)

  • $\begingroup$ course if you want a prime factor ( aka smallest) of a Mersenne of prime exponent, you'll find $k\equiv 0,-p\pmod 4$ just for starters. $k\equiv 0,-p\pmod 3$ for another. that's not even using $j\not\equiv \lfloor {p\over 2}\rfloor \pmod p$ for Double Mersennes at least in theory. $\endgroup$
    – user645636
    Jan 24, 2020 at 14:47

I think Nate's answer is missing something vital. Actually, a Fermat number is a number of the form $2^{2^n} + 1$ whereas a Mersenne number is any number of the form $2^n - 1$. It can easily be shown that $2^n + 1$ can only be prime when $n$ is a power of 2 and $2^n - 1$ can only be prime when $n$ is a prime number. Despite this, n still doesn't have to be prime in order for $2^n - 1$ to be called a Mersenne number. There is something extra special about Fermat numbers and Mersenne numbers with prime exponent that may make you question its probability of being prime as I will describe later. It is a well known theorem that the multiplication modulo group of any prime number is a cyclic group of order one less than that prime number.

The only possible factors of $2^{2^n} + 1$ are 1 more than a multiple of $2^{n + 1}$. I believe I once read on the internet that Fermat conjectured that all Fermat are prime because of the extreme restrictions on what their prime factors can be. It turns out that the argument is flawed. I believe the proportion of prime numbers that are 1 more than a multiple of $2^{n + 1}$ is $2^{-n}$. When $(k \times 2^{n + 1}) + 1$ is prime, the only way for it to be a factor of $2^{2^n} + 1$ is when $2^n$ is congruent to -1 modulo $(k \times 2^{n + 1}) + 1$ and the probability of that is $\frac{1}{2k}$.

There is actually a theorem that for any odd prime number p, 2 is a square modulo p when and only when p is congruent to 1 or 7 modulo 8. This skews the probabilities so that when k is odd, the probability of $2^n$ being congruent to -1 modulo $(k \times 2^{n + 1}) + 1$ is zero and when k is even, the probability of $2^n$ being congruent to -1 modulo $(k \times 2^{n + 1}) + 1$ is $\frac{1}{k}$.

Similarly, for any odd prime number $p$, all prime factors of $2^p - 1$ must be 1 more than a multiple of 2p. When $2pk + 1$ is congruent to 3 or 5 modulo 8, the probability of $2pk + 1$ being a factor of $2^p - 1$ is zero. When $2pk + 1$ is congruent to 1 or 7 modulo 8, the probability of $2^p$ being congruent to 1 modulo $2pk + 1$ is $\frac{1}{k}$.


You must log in to answer this question.