Prime Checker

Tests whether a number is prime and shows its factors when it is not. Prime numbers are the multiplicative atoms of arithmetic and the foundation of most public-key cryptography, which is a lot of weight for something defined by what it cannot be divided by.

Live demo · real result from this tool
Any size. Proof-grade (deterministic) below 3.3 × 10²⁴.
Result1,000,000,007 is prime
Previous prime
999,999,937
Next prime
1,000,000,009

Method

Trial division by primes up to 1,000, then the Miller–Rabin test with the first 13 prime bases, which is deterministic for every n below 3,317,044,064,679,887,385,961,981.

Processed on your device — nothing is uploaded.

How to use Prime Checker

  1. Enter a whole number.
  2. Read whether it is prime, and its factors if it is not.
  3. 1 is not prime, and neither is any number below it; 2 is the only even prime.
  4. Trial division only needs to reach the square root of the number.
  5. Very large numbers exceed exact integer representation in JavaScript — cryptographic-scale primality testing needs arbitrary-precision arithmetic.

How primality is actually tested

Not by trying every number below it. You only need to test divisors up to the square root, because any factor above the square root must pair with one below it — so checking up to √10000 = 100 settles a five-digit number. Skipping even numbers after 2 halves the work again, and testing only 6k±1 candidates removes multiples of 3 as well. For genuinely large numbers, trial division is hopeless and probabilistic tests such as Miller-Rabin are used instead: they can be wrong, with a probability you choose, and you make it smaller than the chance of a cosmic ray flipping the answer.

Why 1 is not prime

It looks like an arbitrary exclusion and it is a load-bearing one. The fundamental theorem of arithmetic says every integer above 1 has a unique prime factorisation — and if 1 were prime, 12 could be 2²×3 or 1×2²×3 or 1⁵×2²×3, and uniqueness would be lost. Mathematicians did count 1 as prime into the early twentieth century; it was excluded precisely because keeping it broke more theorems than it served.

The primes that keep the internet working

RSA multiplies two large primes to get a public modulus, and its security rests on factoring that product being hard while multiplying was easy. A 2048-bit RSA key uses two primes of about 300 digits each, found by generating random odd numbers and testing them — the prime number theorem says roughly one in every 700 numbers that size is prime, so this takes seconds. Nobody has factored a 2048-bit modulus, and a sufficiently large quantum computer would, which is the entire motivation for post-quantum cryptography.

Curiosities worth knowing

There are infinitely many primes — Euclid proved it around 300 BC with an argument that still fits in two lines. They thin out but never stop: the density near n is about 1/ln(n). Twin primes such as 11 and 13 appear to go on forever, but nobody has proved it. Mersenne primes, of the form 2ⁿ−1, are where the largest known primes come from, and the current record has over 41 million digits.

Frequently asked questions

What makes a number prime?
A prime number greater than 1 has exactly two divisors: 1 and itself, so it cannot be evenly divided by any other number.
How is primality tested?
The checker tests divisibility by integers up to the square root of the number — enough to confirm primality efficiently.
Is 1 a prime number?
No. A prime has exactly two distinct divisors, 1 and itself, and 1 has only one. The deeper reason is that unique prime factorisation would fail if 1 counted — every number would have infinitely many factorisations differing only by factors of 1.
What is the fastest way to check if a number is prime?
Test divisibility by 2 and 3, then by candidates of the form 6k±1 up to the square root. That is enough for anything you would type by hand. Numbers of cryptographic size use probabilistic tests such as Miller-Rabin instead.
Why do prime numbers matter for encryption?
Because multiplying two large primes is fast and factoring the result is not, as far as anyone knows. RSA builds a public key from that asymmetry. The security is an assumption about difficulty rather than a proof, which is why a quantum algorithm that factors efficiently would break it.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close