Mersenne Prime Calculator
Test whether 2 to the power p minus one is prime, using the Lucas test and showing the full integer.
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
- Enter a whole exponent p from 2 to 61.
- Read the verdict in the main result box.
- Check whether the exponent passed the prime test.
- Read the full value of 2^p minus 1 beside it.
- Use the default p = 5 to reproduce the worked example.
- Try p = 11 to see a prime exponent that still gives a composite number.
Formula
- 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.
- Compute the Mersenne number: 2^5 - 1 = 32 - 1 = 31.
- Check the exponent: 5 is prime, so the Lucas test applies.
- Start the sequence at s_0 = 4.
- After one round s_1 = 4^2 - 2 = 14.
- After two rounds s_2 = 14^2 - 2 = 194, which is 8 modulo 31.
- After three rounds s_3 = 8^2 - 2 = 62, which is 0 modulo 31.
- The tool reports Mersenne prime with value 31 and prime exponent.
Reference table
| p | 2^p minus 1 | Exponent | Verdict |
|---|---|---|---|
| 2 | 3 | Prime | Mersenne prime |
| 3 | 7 | Prime | Mersenne prime |
| 4 | 15 | Composite | Exponent is not prime |
| 5 | 31 | Prime | Mersenne prime |
| 11 | 2047 | Prime | Not a Mersenne prime |
| 13 | 8191 | Prime | Mersenne 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.