Mersenne Prime Checker
Enter an exponent p to test 2p − 1, or enter a whole number to see whether it has Mersenne form. Small and medium candidates are checked with the Lucas–Lehmer test inside the browser.
Mp = 2p − 1. Only positive whole-number exponents are accepted.N + 1 = 2p for a whole-number exponent p.Result
- Classification
- —
- Exponent
- —
- Expression
- —
- Decimal digits
- —
- Exponent status
- —
- Method
- —
- Iterations
- —
- Final residue
- —
- Known-prime rank
- —
Show Lucas–Lehmer residues
A Mersenne prime is a prime number that can be written as 2p − 1. The form is easy to recognize, but the primality question needs more care. A prime exponent is required, yet many prime exponents still produce composite numbers.
Mersenne Numbers and Mersenne Primes
For a positive whole number p, the expression below defines a Mersenne number:
The name describes the form, not the result. Every value produced by the formula is a Mersenne number. It becomes a Mersenne prime only when that value has exactly two positive divisors: 1 and itself.
| Exponent p | Mersenne number | Classification | Reason |
|---|---|---|---|
| 2 | 3 | Mersenne prime | 3 is prime. |
| 3 | 7 | Mersenne prime | 7 is prime. |
| 5 | 31 | Mersenne prime | 31 is prime. |
| 7 | 127 | Mersenne prime | 127 is prime. |
| 11 | 2,047 | Composite | 2,047 = 23 × 89. |
| 13 | 8,191 | Mersenne prime | The Lucas–Lehmer residue is 0. |
A number may be prime without being a Mersenne prime. For example, 29 is prime, but 30 is not a power of two, so 29 cannot be written as 2p − 1. A general prime number checker answers whether such a number is prime; this tool answers the narrower Mersenne question.
Why the Exponent Must Be Prime
If p is composite, write it as p = ab with a > 1 and b > 1. Then 2a − 1 divides 2ab − 1. That gives the larger number a nontrivial factor, so it cannot be prime.
Take p = 9:
The checker therefore tests the exponent before starting Lucas–Lehmer iterations. This early rejection is exact. It avoids a longer calculation when the form itself already proves compositeness.
211 − 1 = 2,047 is composite. Prime exponents are candidates, not automatic successes.How the Lucas–Lehmer Test Works
For a prime exponent p > 2, the Lucas–Lehmer test starts with s0 = 4 and repeats this recurrence:
The recurrence runs p − 2 times. If the final residue equals zero, 2p − 1 is prime. If the residue is nonzero, the Mersenne number is composite.
This is a deterministic primality test for Mersenne numbers under the stated conditions. It does not return a “probably prime” label. The special case p = 2 is handled directly because 22 − 1 = 3.
Example: testing p = 7
Here M7 = 127. Five iterations are required because 7 − 2 = 5.
| Step | Residue modulo 127 |
|---|---|
| Start | 4 |
| 1 | 14 |
| 2 | 67 |
| 3 | 42 |
| 4 | 111 |
| 5 | 0 |
The final zero proves that 127 is a Mersenne prime. The calculator can reveal the same residue trail for browser-tested exponents without filling the page with thousands of intermediate values.
Reading the Checker Result
Mersenne prime
The number has Mersenne form, its exponent is prime, and the Lucas–Lehmer sequence ends at zero. For exponents above the browser calculation limit, a verified known-prime match is reported separately.
Composite Mersenne number
The number has the correct form but is not prime. This may follow immediately from a composite exponent, or from a nonzero Lucas–Lehmer residue after testing a prime exponent.
A composite result does not always include a full factorization. Proving that a number is not prime and finding every prime factor are different tasks.
Not a Mersenne number
For a whole number N, the checker examines N + 1. If that value is not an exact power of two, no whole-number exponent satisfies N = 2p − 1.
Valid candidate, browser test not run
A large prime exponent may define a valid Mersenne candidate while still exceeding a sensible in-browser calculation range. In that case, the result remains untested here. It is not labeled prime or composite without evidence.
Known Mersenne Prime Exponents
Mersenne primes are usually identified by their exponents because the decimal values become long very quickly. The checker includes the verified exponent sequence through p = 136,279,841. Small entries are useful for direct browser tests; very large entries are recognized through the bundled known-prime data.
| Rank | Exponent p | Decimal digits in 2p − 1 |
|---|---|---|
| 1 | 2 | 1 |
| 2 | 3 | 1 |
| 3 | 5 | 2 |
| 4 | 7 | 3 |
| 5 | 13 | 4 |
| 8 | 31 | 10 |
| 12 | 127 | 39 |
| 20 | 4,423 | 1,332 |
| 30 | 132,049 | 39,751 |
| 40 | 20,996,011 | 6,320,430 |
| 50 | 77,232,917 | 23,249,425 |
| 52 | 136,279,841 | 41,024,320 |
Counting the Digits Without Printing the Number
The number of decimal digits in 2p − 1 can be calculated before producing its full decimal expansion:
This formula is especially useful for large exponents. It tells the checker how large the result would be while avoiding a huge block of digits. For example, 2127 − 1 has 39 digits, while the exponent 136,279,841 produces a number with more than 41 million decimal digits.
Mersenne Primes and Even Perfect Numbers
Every Mersenne prime produces an even perfect number through the Euclid–Euler formula:
When p = 5, the Mersenne prime is 31. The matching perfect number is:
This connection runs both ways: every even perfect number has this form for a Mersenne prime exponent. It is one reason Mersenne primes remain closely tied to divisor theory rather than being isolated numerical curiosities.
Why Large Tests Need Specialized Software
The recurrence looks short, but each step squares a number that may contain millions of bits. Ordinary browser BigInt arithmetic works well for modest exponents. Record-scale searches use faster multiplication methods, careful error checks, distributed computing, and independent verification.
The calculator sets a practical direct-test limit and divides longer calculations into short browser tasks so the controls remain usable. A known large exponent can still be recognized from the verified list. An unknown exponent above the limit remains undecided on this page.
Questions About Mersenne Prime Testing
Does every prime exponent produce a Mersenne prime?
No. The exponent 11 is prime, but 211 − 1 = 2,047 = 23 × 89. A prime exponent only creates an eligible candidate.
Is the Lucas–Lehmer test probabilistic?
No. For a prime exponent greater than 2, a final residue of zero proves that the matching Mersenne number is prime.
Can a Mersenne number be tested with an ordinary primality test?
Yes, but the Lucas–Lehmer test uses the special form 2p − 1 and is the natural test for this family. General tests do not use that structure as directly.
Why does the checker sometimes use a known-prime lookup?
Very large verified Mersenne primes are not practical to recompute in a normal browser session. A lookup identifies a documented exponent without pretending that a fresh Lucas–Lehmer run occurred.
Can the checker prove that a number is not in Mersenne form?
Yes. If N + 1 is not an exact power of two, then no whole-number exponent can satisfy N = 2p − 1.