Powers of Two (2^p - 1)

Mersenne Prime Calculator

Test whether the Mersenne number 2p - 1 is prime using the fast Lucas-Lehmer squaring test.

Test Exponents:
Lucas-Lehmer Test
M₇ = 127 is Prime
2⁷ - 1 = 127
Exponent p p = 7 (Prime)
Decimal Digits 3 digits
Test Method Lucas-Lehmer Test
01

Watch the Lucas-Lehmer Test: Step-by-Step Squaring

The Lucas-Lehmer test starts at 4 and repeats p - 2 squaring steps. In each step, it squares the previous result, subtracts 2, and keeps only the remainder after dividing by 2p - 1. If the final step lands on exactly 0, the number is 100% prime! Test any exponent up to 31 below:

Quick Traces:
02

Mersenne Primes and Even Perfect Numbers

A perfect number is a number that equals the sum of its divisors (excluding itself). For example, 6 = 1 + 2 + 3. Over 2,000 years ago, Greek mathematician Euclid proved that whenever 2p - 1 is prime, multiplying it by 2p-1 produces an even perfect number! Leonhard Euler later proved that all even perfect numbers follow this exact pattern.

Even Perfect Number Generator

Euclid-Euler Rule

Choose a known Mersenne prime to see its matching even perfect number:

Historical timeline curve showing the discovery of record Mersenne prime exponents from Euclid through GIMPS
Historical Growth of Record Mersenne Primes From ancient M2 = 3 through GIMPS distributed computing, each newly verified Mersenne prime yields a matching even perfect number 2^(p-1)(2^p - 1).
03

Famous Mersenne Primes & World Records

Click any landmark Mersenne number below to test it directly in the calculator above:

Exponent p Number (2^p - 1) Digits Status History / Discoverer Action
p = 2 3 1 Prime (M₁) Smallest Mersenne prime; exponent 2
p = 3 7 1 Prime (M₂) Creates perfect number 28
p = 5 31 2 Prime (M₃) Creates perfect number 496
p = 7 127 3 Prime (M₄) Creates perfect number 8,128
p = 11 2,047 4 Composite First prime exponent yielding a composite: 23 × 89
p = 13 8,191 4 Prime (M₅) Creates 5th perfect number: 33,550,336
p = 17 131,071 6 Prime (M₆) Verified by hand in 1588
p = 19 524,287 6 Prime (M₇) Verified by hand in 1588
p = 23 8,388,607 7 Composite Factored by Fermat: 47 × 178,481
p = 29 536,870,911 9 Composite Factored by Fermat: 233 × 1,103 × 2,089
p = 31 2,147,483,647 10 Prime (M₈) Euler proved prime by hand; maximum 32-bit game score
p = 61 2.305 × 10¹⁸ 19 Prime (M₉) Proved prime by Father Pervushin
p = 67 1.475 × 10²⁰ 21 Composite Cole famously factored without speaking at a math meeting
p = 89 6.189 × 10²⁶ 27 Prime (M₁₀) Verified by Powers in 1911
p = 107 1.622 × 10³² 33 Prime (M₁₁) Discovered just before WWI
p = 127 1.701 × 10³⁸ 39 Prime (M₁₂) Largest prime ever discovered by hand calculation!
p = 521 6.864 × 10¹⁵⁶ 157 Prime (M₁₃) First prime discovered using an electronic computer
p = 4,423 2.855 × 10¹³³¹ 1,332 Prime (M₂₀) First prime with over 1,000 decimal digits
p = 82,589,933 2^82589933 - 1 24,862,048 Prime (M₅₁) Held world record from 2018 to 2024 (24.8M digits)
p = 136,279,841 2^136279841 - 1 41,024,320 World Record (M₅₂) Current World Record; discovered using GPU cloud cluster
04

Why Mersenne Numbers Are Special

1. Why the Exponent p Must Be Prime

If an exponent has factors (for example, if n = 4 or n = 6), the number 2n - 1 can always be split apart using simple algebra:

2^(a × b) - 1 can always be divided by (2^a - 1)

Because it can always be broken down into smaller whole numbers, 2n - 1 cannot be prime unless the exponent itself is a prime number.

2. Why the Lucas-Lehmer Test Is So Reliable

Discovered in 1876 by Édouard Lucas and simplified in 1930 by Derrick Lehmer, this test doesn't need to test every divisor. Instead, it tests whether a specific sequence of squared numbers lands on zero. If it reaches zero, mathematical proofs guarantee that the number is 100% prime.

3. Euler's Factor Shortcut Rule

Mathematician Leonhard Euler proved that any factor of 2p - 1 must be 1 more than a multiple of 2p:

Potential Factors = (2 × p × k) + 1

This rules out almost all regular numbers, letting computers check for factors hundreds of times faster.

05

Step-by-Step Worked Walkthroughs

Here are four examples showing how Lucas-Lehmer steps, factor shortcuts, and perfect numbers work:

Walkthrough 1

Testing p = 5 (2⁵ - 1 = 31)

Steps Required: p - 2 = 3 steps.
• s₀ = 4.
• s₁ = (4² - 2) mod 31 = 14 mod 31 = 14.
• s₂ = (14² - 2) mod 31 = 194 mod 31 = 8.
• s₃ = (8² - 2) mod 31 = 62 mod 31 = 0.
Conclusion: The final step is 0! That proves 31 is prime.

Walkthrough 2

Checking Factors for 2¹¹ - 1 = 2047

Shortcut Rule: Factors must equal (2 × 11 × k) + 1 = 22k + 1.
• Try k = 1: 22(1) + 1 = 23.
• Divide: 2047 ÷ 23 = 89 (divides evenly!).
Result: 2047 = 23 × 89. It is composite!

Walkthrough 3

Cole's Famous Silent Speech in 1903

The Background: In 1644, Marin Mersenne claimed 2⁶⁷ - 1 was prime.
The Speech: In 1903, mathematician Frank Nelson Cole walked up to a chalkboard during a math conference without saying a word. On one board he calculated 2⁶⁷ - 1. On the other board, he multiplied 193,707,721 × 761,838,257,287.
Result: Both numbers matched perfectly! He proved it was composite and sat down to a standing ovation without speaking a single word.

Walkthrough 4

Building Perfect Number 8,128

Mersenne Prime: M₇ = 2⁷ - 1 = 127.
Euclid's Formula: 2⁶ × 127 = 64 × 127 = 8,128.
Check: All the factors of 8,128 add up to exactly 8,128. That makes it a perfect number!

06

How Fast Can Computers Test Giant Mersenne Numbers?

Comparing how computers test numbers with millions of digits:

Testing Method Calculation Speed Memory Needed Practical Limit Best Used For
Simple Division Extremely Slow Tiny p ≤ 31 only Basic classroom learning
Standard Lucas-Lehmer (Browser) Fast Small (kilobytes) p ≤ 1,000 in browser Interactive website testing
Supercomputer FFT Test (Prime95) Fastest for Giant Numbers Moderate (gigabytes) p > 136,000,000 Discovering new world-record primes

Related Prime & Exponential Tools

Frequently Asked Questions

What is a Mersenne prime?

A Mersenne prime is a prime number that is one less than a power of two: 2^p - 1. For example, when p = 3, 2³ - 1 = 7, which is prime! For 2^p - 1 to have any chance of being prime, the exponent p must always be a prime number itself.

Why must the exponent p be a prime number?

Because if the exponent is composite (has factors like 4 = 2 × 2 or 6 = 2 × 3), the entire number can always be broken down into smaller pieces. For example, 2⁴ - 1 = 15 (which is 3 × 5) and 2⁶ - 1 = 63 (which is 7 × 9). Only prime exponents can produce prime answers.

What is the Lucas-Lehmer primality test?

The Lucas-Lehmer test is an ultra-fast test designed specifically for numbers shaped like 2^p - 1. It starts at 4 and repeatedly squares the number and subtracts 2. If the final step lands on exactly zero, the number is guaranteed to be 100% prime.

What is the largest known prime number in mathematics?

As of late 2024, the largest known prime number is the 52nd Mersenne prime, 2^136,279,841 - 1, discovered by Luke Durant through GIMPS (Great Internet Mersenne Prime Search). It has an astounding 41,024,320 digits!

How are Mersenne primes related to perfect numbers?

A perfect number equals the sum of its divisors (for example, 6 = 1 + 2 + 3, and 28 = 1 + 2 + 4 + 7 + 14). Over 2,000 years ago, Greek mathematician Euclid proved that every time you find a Mersenne prime 2^p - 1, multiplying it by 2^(p-1) gives an even perfect number!

Why do composite Mersenne numbers have special factors?

Mathematician Leonhard Euler proved that any factor of 2^p - 1 must follow strict rules: it must end up as 1 more than a multiple of 2p. This allows computers to test potential factors hundreds of times faster without checking every odd number.

Why do random number generators use 2^19937 - 1?

Because 2^19937 - 1 is a prime number with over 6,000 digits! Random number algorithms like the Mersenne Twister use it to create sequences that can run for billions of billions of cycles before ever repeating.

Why do computer builders and gamers run Prime95?

Prime95 is software originally created to search for giant Mersenne primes. Testing these huge numbers pushes a computer's processor and memory to their absolute limits, making it the industry standard test for hardware stability.