Prime Number Checker

Enter a whole number of 2 or more (up to 1015) — the result updates as you type.

How it works

Primality is checked by trial division: 2 is tried first, then every odd number up to the integer square root of the value — if none of them divide it evenly, it is prime. The factor list uses the same idea in reverse, repeatedly dividing out the smallest factor found until only 1 is left, so a composite number's factors always multiply back to the original value. A prime number's own factor list is just itself, since a prime has no smaller factor to divide out. Everything runs on BigInt, so integers well beyond 2^53 are checked exactly rather than after silently rounding.

Frequently asked questions

Why does this take a BigInt instead of an ordinary number?

A regular JavaScript number can only represent integers exactly up to 2^53 (9,007,199,254,740,991) — past that, two different whole numbers can round to the very same value, and a primality check on the rounded value would be checking the wrong number without any sign that it happened. BigInt has no such ceiling, so every integer this tool accepts is checked exactly, not approximately.

Why is there an upper limit at all?

Trial division — dividing by 2 and every odd number up to the square root — is simple and always correct, but its cost grows with the square root of the number, not with its digit count. That is fast for anything up to about 10^15, and would take dramatically longer just past it. Checking much larger numbers needs fundamentally different algorithms (Pollard's rho, a quadratic sieve, and similar), which is a different tool from this one.

What does the factor list show when the number IS prime?

Just the number itself. That's the definition of prime — a number greater than 1 with exactly two divisors, itself and 1 — so its own factor list has exactly one entry, itself, rather than an empty list.