Free · Instant · 7 views · BigInt · Ulam spiral · π(x) chart

Prime Number Checker — Test Any Number Instantly with Steps, Factorization, Ulam Spiral & π(x) Chart

Test any whole number for primality in real time. Get a clear PRIME / COMPOSITE verdict with the exact divisor that proves it, a visual rectangle proof, step-by-step trial division up to √n, full prime factorization with divisor statistics, prime lists across any range, neighbouring primes and gaps, an interactive Ulam spiral, a π(x) comparison against the prime number theorem, and a playground with Goldbach, Collatz, Fermat and Wilson experiments. Handles numbers far beyond 2⁵³ − 1 using BigInt.
⚡ Instant verdict 🔍 Step-by-step proof 🧩 Factorization & divisors 📊 Range sieve & heatmap 🌀 Ulam spiral 📈 π(x) chart 🧮 BigInt for huge numbers 🔒 Runs in your browser

Prime Number Checker

Seven views: check · factorize · range · explore · visualize · playground · batch.

Prime Number Checker Report

AIToolsPros · prime number checker

Commas and spaces are ignored. Numbers above 2⁵³ − 1 are handled with BigInt. Primality is only defined for integers greater than 1.

Try
PRIME
97
97 has exactly two positive divisors: 1 and 97.

Quick divisibility checks

Number facts

Base conversions (click any row to copy)

Visual proof — can the number form a rectangle?

A prime can only be arranged as a single row of 1 × n. If any grid with two or more rows fits exactly, the number is composite. Each rectangle below is a divisor pair.

🧮 Step-by-step trial division

Recent checks

No checks yet — type a number above.

What this prime number checker does

A prime number checker answers one question: does this whole number have any positive divisor other than 1 and itself? If it does not, the number is prime. If it does, the number is composite. That definition sounds simple, but a correct answer for arbitrary input requires choosing the right algorithm — trial division for everyday numbers, a sieve when you need every prime in a range, and a deterministic variant of Miller–Rabin once the number grows past what trial division can handle in reasonable time.

This tool layers those algorithms behind a single input box. Type a number and you get an instant verdict, the exact divisor that proves compositeness when one exists, a visual proof in the form of divisor rectangles, and a numbered walkthrough of the trial division that would be performed by hand. When a number is prime, the tool shows you the bound — √n — where the search stopped, which is the part most people find hardest to reason about on paper. The tool also displays the number written in English words, in binary, octal, hexadecimal and base 36, and how long the primality test actually took on this device.

Beyond the single-number check there are six more views. Factorize breaks a composite into its prime factors and lists every divisor along with σ(n), the aliquot sum and the abundance classification, plus an amicable-pair finder and a coprime check against a second number. Range runs a sieve of Eratosthenes across any interval up to two million and renders the result as a heatmap, a density chart and a copyable list. Explore finds the neighbouring primes, measures the gap, tests for twin, cousin, sexy, Sophie Germain and safe-prime relationships, and can locate the n-th prime. Visualize draws the Ulam spiral and plots the true prime counting function π(x) against the prime-number-theorem estimate. Playground runs Goldbach partitions, Collatz sequences, Fermat test demonstrations with Carmichael numbers, and Wilson's theorem. Batch checks a whole pasted column at once and exports to CSV or JSON.

Everything runs in your browser. Numbers are parsed into BigInt the moment they exceed JavaScript's safe integer range, so a 40-digit input is handled with the same arithmetic guarantees as a 2-digit one.

What is a prime number?

A prime number is a whole number greater than 1 whose only positive divisors are 1 and itself. The first primes are:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

Every whole number greater than 1 is either prime or composite — there is no third option. A composite number has at least one divisor besides 1 and itself: 12 has 2, 3, 4 and 6; 100 has 2, 4, 5, 10, 20, 25 and 50.

Why 1 is not a prime number

1 sits outside both categories. It is neither prime nor composite. The reason is not arbitrary: a prime is defined as having exactly two distinct positive divisors, and 1 has only one (itself). More importantly, if 1 were prime, the fundamental theorem of arithmetic would fail. That theorem states that every integer greater than 1 has a unique prime factorization. If 1 counted as prime you could write 6 = 2 × 3, or 1 × 2 × 3, or 1 × 1 × 2 × 3 — uniqueness would collapse. Mathematicians chose the definition that keeps the theorem clean.

Historically this was not always so. Until the early twentieth century some texts did list 1 as prime. The modern convention settled on excluding it, and every serious calculator — including this one — follows that convention.

Why 2 is the only even prime

Every even number is divisible by 2 by definition. For 2 itself, the only divisors are 1 and 2, which makes it prime. For every other even number — 4, 6, 8, 100, 1,000,000 — the divisor 2 is neither 1 nor the number itself, so those numbers are composite. That is why 2 is the single exception to the familiar shortcut "any number ending in 0, 2, 4, 6 or 8 is composite".

How to check if a number is prime

The classical method is trial division: divide the number by 2, then by 3, then by 5, and keep going until either a divisor is found or you pass the square root of the number.

The square-root stopping point is not a heuristic — it is a proof. If n = a × b with both a and b greater than √n, then a × b would be greater than √n × √n = n, which is impossible. So whenever n is composite, at least one of its factors must be less than or equal to √n. If no divisor exists up to that bound, no divisor exists at all.

Worked example: is 97 prime?

√97 ≈ 9.85, so the only divisors worth testing are 2, 3, 5 and 7.

  • 97 ÷ 2 = 48 remainder 1 → not divisible by 2.
  • 97 ÷ 3 = 32 remainder 1 → not divisible by 3 (digit sum 9 + 7 = 16, not a multiple of 3).
  • 97 ÷ 5 ends in 7, not 0 or 5 → not divisible by 5.
  • 97 ÷ 7 = 13 remainder 6 → not divisible by 7.

No divisor exists up to √97, so 97 is prime. Four divisions settle the question completely.

Worked example: is 91 prime?

√91 ≈ 9.54, so again the candidates are 2, 3, 5 and 7.

  • 91 is odd → not divisible by 2.
  • 9 + 1 = 10, not a multiple of 3 → not divisible by 3.
  • 91 ends in 1 → not divisible by 5.
  • 91 ÷ 7 = 13 exactly → divisible by 7.

So 91 = 7 × 13 and is composite. 91 is one of the most commonly misidentified numbers in school arithmetic because it looks prime, is odd, and its factors are both larger than any of the obvious small primes except 7.

Worked example: is 51 prime?

51 ÷ 3 = 17 exactly, and the digit-sum test confirms it instantly: 5 + 1 = 6, which is divisible by 3. So 51 = 3 × 17 and is composite. The same digit-sum shortcut catches 87 (8 + 7 = 15, so 87 = 3 × 29) and 57 (5 + 7 = 12, so 57 = 3 × 19).

The four algorithms this tool uses

Different inputs need different algorithms. Using a sieve to test one number is wasteful; using trial division on a 30-digit input is hopeless. The tool picks the right one automatically.

AlgorithmBest forComplexityUsed by this tool when…
Trial divisionSmall single numbersO(√n)n is below about 10¹²
Wheel factorization (6k ± 1)Speeding up trial division~3× faster than plainSkipping multiples of 2 and 3
Sieve of EratosthenesEvery prime up to a limitO(n log log n)Range and n-th prime views
Deterministic Miller–RabinVery large single numbersO(k log³ n)n is above 10¹²

Trial division and the 6k ± 1 wheel

Plain trial division tests every integer from 2 upward. That wastes time on multiples of 2 and 3, which are trivially composite. After checking 2 and 3 explicitly, every remaining prime candidate can be written as 6k − 1 or 6k + 1 for some integer k — the numbers in between (6k, 6k + 2, 6k + 3, 6k + 4) are all divisible by 2 or 3. Testing only those two residues per block of six cuts the work by roughly a factor of three.

Sieve of Eratosthenes

To find every prime up to a limit, trial division is the wrong tool because it redoes work for each number. The sieve instead allocates a byte per number, assumes everything is prime, then walks upward: when it reaches a number still marked prime, it crosses out every multiple of that number starting from its square. Multiples below the square were already crossed out by a smaller prime, so starting at p² is both correct and necessary for the O(n log log n) running time.

This is exactly what powers the Range tab. For two million numbers the sieve finishes in a few tens of milliseconds and the memory cost is two megabytes.

Deterministic Miller–Rabin

For large numbers, trial division is not merely slow — it is hopeless. Testing a 15-digit number by trial division requires up to 31 million divisions. Miller–Rabin instead performs modular exponentiation and is correct with overwhelming probability for random bases, and provably correct when the bases are chosen carefully.

This tool uses the first twelve prime bases (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 and 37). That set is proven to give the correct answer for every integer below about 3.18 × 10²³, which is far beyond any input a browser can meaningfully process anyway. Above that threshold the test remains an extremely strong probabilistic check rather than a proof.

⚠ Why not just use Fermat's little theorem? Because of Carmichael numbers. 561 = 3 × 11 × 17 passes the Fermat test for every base coprime to it, despite being composite. Miller–Rabin rejects Carmichael numbers reliably; a naive Fermat test does not. You can see this happen for yourself in the Playground tab.

Prime factorization and the fundamental theorem

The fundamental theorem of arithmetic says that every integer greater than 1 can be written as a product of primes in exactly one way, up to the order of the factors. That single fact is why prime factorization is well defined — there is no ambiguity about "the" factorization of 360.

360 = 2³ × 3² × 5. To find it by hand you divide repeatedly by the smallest prime that goes in evenly: 360 ÷ 2 = 180, ÷ 2 = 90, ÷ 2 = 45 (so 2³); 45 ÷ 3 = 15, ÷ 3 = 5 (so 3²); 5 is prime, so it stays. Multiply back: 2 × 2 × 2 × 3 × 3 × 5 = 360.

From the factorization you can derive everything else about the divisors:

  • Divisor count τ(n) = (a₁ + 1)(a₂ + 1)… For 360 = 2³·3²·5¹, τ = 4 × 3 × 2 = 24 divisors.
  • Divisor sum σ(n) = (p₁^(a₁+1) − 1)/(p₁ − 1) × … For 360, σ = 15 × 13 × 6 = 1,170.
  • Aliquot sum s(n) = σ(n) − n. For 360 that is 810.
  • Abundance — if s(n) > n the number is abundant (360 is), if s(n) < n it is deficient (all primes and most numbers are), and if s(n) = n it is perfect (6, 28, 496, 8128…).

The Factorize tab computes all of these. Very large semiprimes — the product of two huge primes, exactly the kind used in RSA — may not factor in a browser tab, and the tool tells you that explicitly instead of hanging.

The Ulam spiral — primes along diagonals

In 1963, the Polish-American mathematician Stanisław Ulam was bored during a meeting. He started writing positive integers in a square spiral on a sheet of paper and circled the primes. To his surprise, the primes were not distributed randomly: they formed visible diagonal lines. This is the Ulam spiral, and it has been a striking visual signature of the distribution of primes ever since.

The most famous such diagonal comes from Euler's polynomial f(n) = n² + n + 41. For n = 0 the value is 41 (prime), for n = 1 it's 43 (prime), and it continues producing primes all the way to n = 39, where it finally gives 40² + 40 + 41 = 1,681 = 41². When plotted in the spiral, this whole family of values lines up along one diagonal.

You can view an interactive Ulam spiral in the Visualize tab. Slide the maximum to change how many numbers are plotted; the diagonal streaks become more pronounced as you go further out.

The prime counting function π(x) and the prime number theorem

The prime counting function π(x) is the number of primes less than or equal to x. It is not a smooth function — it increases by exactly 1 at each prime and stays flat in between — but its overall growth is remarkably regular.

The prime number theorem, proved independently by Jacques Hadamard and Charles Jean de la Vallée Poussin in 1896, says that:

π(x) ~ x / ln(x)

That is, the ratio π(x) / (x / ln x) approaches 1 as x grows without bound. The logarithmic integral Li(x) = ∫₂ˣ dt / ln(t) is a much sharper estimate. For 10⁶ the true count is 78,498; x/ln(x) gives 72,382 (off by 8%), while Li(x) gives 78,627 (off by 0.16%).

xActual π(x)x/ln(x)Li(x)
1002521.730.1
1,000168144.8177.6
10,0001,2291,085.71,246.1
100,0009,5928,685.99,629.8
1,000,00078,49872,382.478,627.5
10,000,000664,579620,420.7664,917.4

The Visualize tab plots the actual π(x) curve alongside both estimates so you can see the convergence for yourself.

Goldbach's conjecture — every even number is a sum of two primes

In a 1742 letter to Leonhard Euler, Christian Goldbach proposed that every even integer greater than 2 can be written as the sum of two primes. The examples come easily: 4 = 2 + 2, 10 = 3 + 7, 100 = 3 + 97, 1,000 = 3 + 997. Larger numbers often have many representations.

The conjecture has been verified computationally for every even number up to at least 4 × 10¹⁸, but no general proof exists. It is one of the oldest unsolved problems in mathematics and one of the reasons the primes are still studied so actively today. The weak Goldbach conjecture — every odd number greater than 5 is the sum of three primes — was proved by Harald Helfgott in 2013 (with computational verification of the remaining case).

You can explore Goldbach partitions in the Playground tab. Enter any even number up to a few million and the tool lists every partition into two primes.

The Collatz conjecture and the primes

The Collatz conjecture (also called the 3n + 1 problem) says that if you take any positive integer and repeatedly apply the rule if odd, multiply by 3 and add 1; if even, divide by 2, you will always eventually reach 1. For 27 the sequence has 111 steps before hitting 1, reaching a peak of 9,232 along the way — a striking illustration of how chaotic even simple arithmetic can be.

The connection to primes is structural: when starting from a prime, the sequence often visits other primes, and the ways in which primes interact through Collatz-like rules remain deeply unexplained. Like Goldbach, Collatz is verified computationally far beyond any practical bound (past 2⁶⁸ as of 2025) but has no known proof. Paul Erdős famously said of Collatz: "Mathematics is not yet ready for such problems."

Special types of prime numbers

Primes are not all alike. Several named families are defined by how a prime relates to its neighbours or how it is written, and this tool flags them automatically when your number qualifies.

TypeDefinitionExamples
Twin primesTwo primes differing by 2(3, 5), (11, 13), (41, 43)
Cousin primesTwo primes differing by 4(3, 7), (7, 11), (13, 17)
Sexy primesTwo primes differing by 6 (from Latin sex)(5, 11), (7, 13), (11, 17)
Sophie Germain primep is prime and 2p + 1 is also prime2, 3, 5, 11, 23, 29, 41
Safe primep is prime and (p − 1)/2 is also prime5, 7, 11, 23, 47, 59
Mersenne primeOf the form 2p − 1 with p prime3, 7, 31, 127, 8191
Palindromic primeReads the same forwards and backwards11, 101, 131, 151, 313
EmirpPrime whose digit reversal is a different prime13 ↔ 31, 17 ↔ 71, 37 ↔ 73
Circular primeEvery rotation of its digits is prime2, 3, 5, 7, 11, 13, 17, 31, 37, 79
Pythagorean primePrime of the form 4n + 1 (hypotenuse of a right triangle)5, 13, 17, 29, 37, 41, 53

The Twin Prime Conjecture — that infinitely many twin primes exist — remains unsolved. The largest known twin prime pair has hundreds of thousands of digits, and the 2013 breakthrough by Yitang Zhang proved that infinitely many prime pairs exist with a bounded gap, though the bound he established was 70 million rather than 2.

Numbers that look prime but are not

A handful of composites catch people out again and again because they are odd, do not end in 5, and do not have an obvious small factor. Memorising them is genuinely useful for exams and mental arithmetic:

NumberFactorizationWhy it fools people
513 × 17Digit sum 6 is divisible by 3 — the test is easy but easy to skip
573 × 19Digit sum 12, divisible by 3
873 × 29Digit sum 15, divisible by 3
917 × 13Not divisible by 2, 3 or 5 — the factor 7 is easy to miss
1197 × 17Same trap as 91
1337 × 19Same trap
14311 × 13Passes the 2, 3 and 5 tests
18711 × 17Passes the 2, 3 and 5 tests
52717 × 31Both factors exceed the obvious small primes

💡 Two-second triage. Before doing anything else, check three things: is it even (→ composite unless it is 2)? Does it end in 0 or 5 (→ composite unless it is 5)? Is the digit sum a multiple of 3 (→ composite unless it is 3)? Those three tests eliminate roughly three quarters of all composites instantly.

How many primes are there?

Infinitely many. Euclid's proof around 300 BC is one of the most elegant arguments in mathematics: assume there is a finite list of all primes, multiply them together and add 1. The result is not divisible by any prime on your list (it leaves remainder 1 in every case), so it must either be prime itself or have a prime factor not on the list — contradicting the assumption that the list was complete.

The largest known prime

As of 2026 the largest known prime is 2136,279,841 − 1, a Mersenne prime with 41,024,320 decimal digits. It was found on 12 October 2024 by Luke Durant, a former Nvidia engineer, working through the Great Internet Mersenne Prime Search (GIMPS) project — the first record in the project's history discovered using GPUs rather than CPUs, and the first new record in almost six years.

Mersenne primes are the focus of the search because they have a dedicated primality test — the Lucas–Lehmer test — that is dramatically faster than general-purpose algorithms for numbers of that shape. Every record-holding prime since 1992 has been a Mersenne prime.

Why primes matter for cryptography

Prime numbers are not only a mathematical curiosity; they are the foundation of modern secure communication. RSA encryption — used by every HTTPS connection you make to a bank or email provider — relies on a simple asymmetry:

  • Multiplying two large primes is easy. Given two 1,024-bit primes, a computer can multiply them in microseconds.
  • Factoring the product back is extremely hard. Given only the 2,048-bit product, no known algorithm factors it in less than billions of years on today's hardware.

An RSA public key is exactly this product. The private key depends on the two original primes. If you could factor the product, you could break the encryption. That is why prime generation — and primality testing to confirm that the generated primes really are prime — sits at the heart of secure systems the world over.

Diffie–Hellman key exchange, elliptic curve cryptography, and other modern protocols build on related number-theoretic hard problems. Primes are the closest thing modern mathematics has to a universal one-way function.

When you actually need a prime number checker

  • School and university maths. Verifying homework, checking a hand-computed factorisation, or demonstrating the √n bound in front of a class.
  • Cryptography study. RSA key generation begins by picking two large primes. Understanding how primality is tested — and why Carmichael numbers matter — is foundational for understanding why the algorithm is secure.
  • Hash table sizing. Many hash table implementations perform best when the bucket count is prime, because it reduces clustering with multiplicative hash functions. Finding the next prime above a chosen size is a routine step.
  • Competitive programming and Project Euler. Prime checking appears in dozens of classic problems. Validating your own implementation against a known-correct one is faster than debugging it from scratch.
  • Generating test fixtures. Need a prime near 10¹² for a unit test? Walk upward from the target and check each candidate.
  • Cryptography-adjacent puzzles and CTFs. Recognising when a modulus is factorable is often the first step in a challenge.
  • Everyday curiosity. "Is 91 prime?" is one of the most-searched number questions on the web, and the answer (7 × 13) surprises a lot of people.

Limitations

  • Factorisation of very large semiprimes is not guaranteed. If you enter the product of two 50-digit primes, the tool will correctly say "composite" but may not be able to find the factors within a reasonable browser time budget. It reports that explicitly rather than freezing.
  • Miller–Rabin above ~3.18 × 10²³ is probabilistic. Below that bound, with the twelve prime bases this tool uses, the result is a mathematical proof. Above it, the probability of a false positive is astronomically small but not zero.
  • The range sieve is capped at 2,000,000. Larger ranges would allocate too much memory for a browser tab on low-end devices. The single-number checker has no such cap.
  • The n-th prime finder is capped at the 200,000th prime (2,750,159). Beyond that the sieve bound grows faster than the interface can stay responsive.
  • The Ulam spiral is capped at 40,000 numbers for canvas performance and readability. The π(x) chart is capped at 100,000 for the same reason.
  • Primality is undefined for negatives, zero and non-integers. The tool explains this rather than returning a misleading "not prime".
  • Browser BigInt performance varies. Very large inputs (hundreds of digits) may take a noticeable moment on older devices.

Frequently asked questions

What is a prime number?

A prime number is a whole number greater than 1 whose only positive divisors are 1 and itself. The first primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 and 31. Every whole number greater than 1 is either prime or composite.

Is 1 a prime number?

No. 1 is neither prime nor composite. A prime must have exactly two distinct positive divisors; 1 has only one. If 1 were counted as prime, the fundamental theorem of arithmetic would break, because you could insert any number of extra 1s into a factorisation.

Is 2 a prime number?

Yes. 2 is the smallest prime and the only even prime. Every other even number is divisible by 2 and therefore composite.

Is 91 a prime number?

No. 91 = 7 × 13, so it is composite. It is one of the most common false primes because it is not divisible by 2, 3 or 5. Testing divisors up to √91 ≈ 9.54 (that is, 2, 3, 5 and 7) finds the factor 7.

Is 51 a prime number?

No. 51 = 3 × 17. The digit sum 5 + 1 = 6 is divisible by 3, so 51 is divisible by 3.

Is 87 a prime number?

No. 87 = 3 × 29. The digit sum 8 + 7 = 15 is divisible by 3.

Is 57 a prime number?

No. 57 = 3 × 19. The digit sum 5 + 7 = 12 is divisible by 3.

Is 97 a prime number?

Yes. √97 ≈ 9.85, so only 2, 3, 5 and 7 need testing. 97 is odd, its digit sum 16 is not a multiple of 3, it doesn't end in 0 or 5, and 97 ÷ 7 = 13 remainder 6. No divisor exists up to √n, so 97 is prime.

Is 561 a prime number?

No. 561 = 3 × 11 × 17. It is the smallest Carmichael number — it passes the Fermat test for every base coprime to it. This tool detects it correctly because it tests small prime factors directly and uses Miller–Rabin rather than a plain Fermat test.

Is 1000000007 a prime number?

Yes. 1,000,000,007 is prime. It is a favourite choice in competitive programming because it is the smallest prime above 10⁹, so arithmetic modulo 10⁹ + 7 fits inside a 64-bit integer without overflow.

How do you check if a number is prime?

Divide the number by every prime up to its square root. If none divides evenly, the number is prime. You only need to go up to √n because if n = a × b with both factors greater than √n, their product would exceed n. For large numbers Miller–Rabin is used instead, because trial division becomes impractically slow.

How many prime numbers are there?

Infinitely many — Euclid proved this around 300 BC. There are 25 primes below 100, 168 below 1,000, 1,229 below 10,000 and 78,498 below 1,000,000.

What is the largest known prime number?

As of 2026 it is 2136,279,841 − 1, with 41,024,320 decimal digits. It was found on 12 October 2024 by Luke Durant through the GIMPS project, and was the first record discovered using GPUs.

What is prime factorization?

Writing a composite number as a product of primes. For example 360 = 2³ × 3² × 5. The fundamental theorem of arithmetic guarantees that every integer greater than 1 has exactly one prime factorization, apart from the order of factors.

What is a Mersenne prime?

A prime of the form 2p − 1 where p is itself prime. Examples: 3 (2²−1), 7 (2³−1), 31 (2⁵−1), 8,191 (2¹³−1). They are the largest primes known because the Lucas–Lehmer test makes them practical to verify.

What are twin primes?

Pairs of primes that differ by 2: (3, 5), (11, 13), (17, 19), (41, 43). Whether infinitely many exist is the Twin Prime Conjecture, one of the oldest unsolved problems in mathematics.

What is a Carmichael number?

A composite that passes the simple Fermat primality test for every base coprime to it. The smallest is 561 = 3 × 11 × 17. Carmichael numbers are why serious primality testing uses Miller–Rabin or Baillie–PSW rather than a plain Fermat test.

What is the Ulam spiral?

A visualisation where the positive integers are arranged in a square spiral and the primes are marked. The primes visibly line up along certain diagonals — the most famous being Euler's polynomial n² + n + 41, which produces primes for every n from 0 to 39. You can view it in the Visualize tab.

What is the prime counting function π(x)?

π(x) is the number of primes at or below x. The prime number theorem says π(x) ≈ x / ln(x); the logarithmic integral Li(x) is a much sharper estimate. For 10,000 the true value is 1,229 and x/ln(x) gives 1,086 — accurate to within about 12%.

What is Goldbach's conjecture?

Every even integer greater than 2 can be written as the sum of two primes. It has been verified computationally up to at least 4 × 10¹⁸ but remains unproven. Explore it in the Playground tab.

What is the Collatz conjecture?

If you take any positive integer and repeatedly apply "if odd, multiply by 3 and add 1; if even, divide by 2", the sequence always eventually reaches 1. It has been verified computationally far beyond any practical bound (past 2⁶⁸ as of 2025) but no general proof is known. Explore it in the Playground tab.

What is Wilson's theorem?

n > 1 is prime if and only if (n − 1)! ≡ −1 (mod n). It is a beautiful theoretical characterisation but practically useless because computing (n − 1)! takes O(n) multiplications. The Playground tab demonstrates it for small n.

What is Fermat's little theorem?

If p is prime and a is not a multiple of p, then ap−1 ≡ 1 (mod p). A naïve test uses the contrapositive, but Carmichael numbers like 561 pass it for every coprime base — which is why modern tests use Miller–Rabin instead.

What is the AKS primality test?

Published in 2002 by Agrawal, Kayal and Saxena, AKS was the first deterministic primality test provable to run in polynomial time. Theoretically enormous, practically far slower than Miller–Rabin — browsers and cryptographic libraries still use the older probabilistic algorithms in production.

Why do primes matter for cryptography?

RSA encryption relies on the fact that multiplying two large primes is easy, but factoring their product is extremely hard. A 2048-bit RSA key uses two primes of about 1,024 bits each. If factoring large semiprimes became practical, RSA would collapse overnight — which is why primality testing sits at the heart of modern secure communication.

What is a prime gap?

The difference between two consecutive primes. The smallest gaps are 1 (2 to 3, the only odd gap) and 2 (twin primes). Gaps grow slowly on average — about ln(n) near n — but the maximum gap below 10¹² is 540. Larger gaps occur further out, and finding record gaps is an active area of computational number theory.

Can this tool check very large numbers?

Yes. It uses BigInt, so numbers well beyond 2⁵³ − 1 are supported. Above roughly 10¹² it switches to deterministic Miller–Rabin with the first twelve prime bases, which is provably correct below about 3.18 × 10²³. Factorisation of very large semiprimes may not complete, and the tool says so rather than hanging.

Does this tool work for negative numbers or decimals?

Primality is only defined for integers greater than 1. Negative numbers, zero, one and non-integers are reported as neither prime nor composite with an explanation, rather than being rejected silently.

What is the difference between prime and composite?

A prime has exactly two positive divisors (1 and itself). A composite has more than two. 7 is prime (1, 7); 8 is composite (1, 2, 4, 8). 0 and 1 are neither.

Why only test divisors up to the square root?

If n is composite it can be written as a × b with both greater than 1. At least one of a or b must be ≤ √n — otherwise their product would exceed n. So if no divisor exists up to √n, none exists at all. For 97, √97 ≈ 9.85, so only 2, 3, 5 and 7 need testing.

Does the tool store or upload my numbers?

No. Every calculation runs in your browser. Nothing is uploaded, logged or stored on a server. Your recent checks are kept in this browser's localStorage so you can re-open them quickly, and you can clear them at any time.

Sources & methodology

  • OEIS A000040 — The prime numbers. The canonical sequence of primes, used to validate the sieve and trial-division implementations.
  • Euclid, Elements, Book IX, Proposition 20 — the classical proof that there are infinitely many primes.
  • Hadamard (1896) and de la Vallée Poussin (1896) — independent proofs of the prime number theorem, π(x) ~ x / ln x.
  • Miller, G. L. (1976). "Riemann's hypothesis and tests for primality." Journal of Computer and System Sciences, 13(3), 300–317; Rabin, M. O. (1980). "Probabilistic algorithm for testing primality." Journal of Number Theory, 12(1), 128–138.
  • Jaeschke, G. (1993). "On strong pseudoprimes to several bases." Mathematics of Computation, 61(204), 915–926 — the deterministic witness sets used here, valid below 3.18 × 10²³.
  • Agrawal, M., Kayal, N., Saxena, N. (2004). "PRIMES is in P." Annals of Mathematics, 160(2), 781–793.
  • Great Internet Mersenne Prime Search (GIMPS) — announcement of 2136,279,841 − 1 on 21 October 2024, discovered 12 October 2024 by Luke Durant, with 41,024,320 decimal digits.
  • Carmichael, R. D. (1910). "Note on a new number theory function." Bulletin of the American Mathematical Society, 16(5), 232–238 — the original definition of Carmichael numbers.
  • Ulam, S. M. — the Ulam spiral, first observed in 1963 during a scientific meeting.
  • Helfgott, H. A. (2013). "The ternary Goldbach conjecture is true." arXiv:1312.7748.
  • All computation is performed client-side in JavaScript, with BigInt arithmetic above 2⁵³ − 1.
Scroll to Top