Mersenne Prime Calculator

Test whether 2 to the power p minus one is prime, using the Lucas test and showing the full integer.

Math and PercentUpdated 2026-11-183 min read
Mersenne Prime Calculator
A whole exponent from 2 to 61.
Verdict
...
Value of 2^p minus 1...
Exponent check...

What it does

A Mersenne number is one less than a power of two. When that number is prime, it is called a Mersenne prime. The first few are 3, 7, 31 and 127. They are named after Marin Mersenne, a seventeenth century scholar who listed exponents he believed produced primes.

These numbers matter because they are among the largest known primes. The search for new records focuses on them, since special tests exist that are far quicker than testing an arbitrary integer of the same size. The Lucas sequence test is the standard tool for the job.

There is a necessary condition before any test runs. If p is composite, then 2^p minus 1 factors algebraically and cannot be prime. For example p = 4 gives 15, which is 3 times 5. Only prime exponents are worth testing, and the first step in this page is to check that condition.

For a prime exponent p, the Lucas test starts from 4 and repeatedly squares, subtracts two and reduces modulo the Mersenne number. After p minus two rounds, the number is prime exactly when the remainder is zero. The tool carries this out with integer arithmetic that never loses precision.

The exponent limit here is 61, which keeps the displayed value manageable and the computation instant. Larger Mersenne primes exist, but verifying them is a project for specialized software rather than a browser tool.

How to use

  1. Enter a whole exponent p from 2 to 61.
  2. Read the verdict in the main result box.
  3. Check whether the exponent passed the prime test.
  4. Read the full value of 2^p minus 1 beside it.
  5. Use the default p = 5 to reproduce the worked example.
  6. Try p = 11 to see a prime exponent that still gives a composite number.

Formula

M_p = 2^p - 1; for prime p, M_p is prime if and only if s_(p-2) = 0 modulo M_p, where s_0 = 4 and s_(k+1) = s_k^2 - 2
p
The exponent, which must be prime for M_p to have any chance of being prime.
M_p
The Mersenne number 2^p minus 1.
s_k
The k-th term of the Lucas sequence used in the primality test.

Every reduction is taken modulo M_p, so the sequence values never grow beyond the modulus squared. The special case p = 2 gives M_p = 3, which is prime directly. If the exponent is composite, the tool skips the Lucas test and reports that the exponent is not prime, since a composite exponent always produces a composite Mersenne number.

Worked example

Example: exponent 5

The page opens with p = 5, the worked value.

  1. Compute the Mersenne number: 2^5 - 1 = 32 - 1 = 31.
  2. Check the exponent: 5 is prime, so the Lucas test applies.
  3. Start the sequence at s_0 = 4.
  4. After one round s_1 = 4^2 - 2 = 14.
  5. After two rounds s_2 = 14^2 - 2 = 194, which is 8 modulo 31.
  6. After three rounds s_3 = 8^2 - 2 = 62, which is 0 modulo 31.
  7. The tool reports Mersenne prime with value 31 and prime exponent.

Reference table

Mersenne numbers for small exponents
p2^p minus 1ExponentVerdict
23PrimeMersenne prime
37PrimeMersenne prime
415CompositeExponent is not prime
531PrimeMersenne prime
112047PrimeNot a Mersenne prime
138191PrimeMersenne prime

Limits

  • Exponents above 61 are rejected so the displayed value stays readable.
  • The tool decides primality, it does not factor composite Mersenne numbers.
  • It does not search for the next Mersenne prime beyond the given exponent.
  • A prime exponent is necessary but not sufficient, as p = 11 shows.

Common mistakes

  • Assuming every prime exponent produces a prime Mersenne number.
  • Testing a composite exponent with the Lucas sequence and misreading the result.
  • Confusing 2^p minus 1 with 2^(p minus 1).
  • Rounding the displayed value for large exponents.
  • Forgetting that 2047 equals 23 times 89 even though 11 is prime.

Try it yourself

Quick checks. Answers sit tucked under each question.

Is 127 a Mersenne prime?

Yes. With p = 7, 2^7 - 1 = 127 and the Lucas test returns zero, so 127 is prime.

What happens at p = 11?

2^11 - 1 = 2047, which equals 23 x 89. The exponent is prime but the number is not, so the verdict is Not a Mersenne prime.

Why does p = 4 fail?

Four is composite, so 2^4 - 1 = 15 factors as 3 x 5 and can never be a Mersenne prime.

Questions

Why must p be prime?

If p has a factor a, then 2^a minus 1 divides 2^p minus 1, giving a proper factor.

What is the Lucas test?

A recurrence that squares and subtracts two modulo the candidate, needing only p minus two rounds for a Mersenne number.

Are all large primes Mersenne primes?

No. Mersenne primes are one special family, chosen because they have an efficient test.

How are Mersenne primes linked to perfect numbers?

Each Mersenne prime generates an even perfect number through the formula 2^(p-1)(2^p - 1).

What is the largest exponent here?

61. Anything above that returns a clear error message.

Does the tool show the full integer?

Yes. It prints every digit of 2^p minus 1 even at the top of the range.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.