Skip to content

Mersenne Prime Checker

    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.

    The checker evaluates Mp = 2p − 1. Only positive whole-number exponents are accepted.
    Ready to test an exponent or a whole number.

    Result

    Waiting for input
    Classification
    Exponent
    Expression
    Decimal digits
    Exponent status
    Method
    Iterations
    Final residue
    Known-prime rank

    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.

    What the checker decides: it separates four different outcomes—Mersenne prime, composite Mersenne number, a number outside Mersenne form, and a candidate that is too large for a practical browser test. Those outcomes should never be treated as interchangeable.

    Mersenne Numbers and Mersenne Primes

    For a positive whole number p, the expression below defines a Mersenne number:

    Mp = 2p − 1

    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.

    Small Mersenne numbers and their classifications
    Exponent pMersenne numberClassificationReason
    23Mersenne prime3 is prime.
    37Mersenne prime7 is prime.
    531Mersenne prime31 is prime.
    7127Mersenne prime127 is prime.
    112,047Composite2,047 = 23 × 89.
    138,191Mersenne primeThe 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:

    29 − 1 = 511 = 7 × 73

    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.

    A prime exponent does not guarantee a Mersenne prime. The exponent 11 is prime, but 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:

    sn = (sn−12 − 2) mod (2p − 1)

    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.

    Lucas–Lehmer sequence for 27 − 1
    StepResidue modulo 127
    Start4
    114
    267
    342
    4111
    50

    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.

    Selected known Mersenne prime exponents
    RankExponent pDecimal digits in 2p − 1
    121
    231
    352
    473
    5134
    83110
    1212739
    204,4231,332
    30132,04939,751
    4020,996,0116,320,430
    5077,232,91723,249,425
    52136,279,84141,024,320
    52 known exponentsThe bundled lookup contains the verified sequence from 2 through 136,279,841.
    41,024,320 digitsThe largest listed Mersenne prime is far too long to print usefully on a web page.
    p − 2 iterationsA direct Lucas–Lehmer run grows with the exponent and the size of each modular square.

    Counting the Digits Without Printing the Number

    The number of decimal digits in 2p − 1 can be calculated before producing its full decimal expansion:

    digits = floor(p × log102) + 1

    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:

    2p−1(2p − 1)

    When p = 5, the Mersenne prime is 31. The matching perfect number is:

    24 × 31 = 496

    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.

    Result integrity: a canceled or unfinished calculation is never converted into a primality result. The checker reports what was tested, what was matched from known data, and what remains outside its browser range.

    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.

    📌

    Complete guide: Prime Number Tools