Prime Number Checker & Factorizer

Check whether a number is prime, break it into prime factors, list every prime up to N and find the next one.

How to use

  1. Choose a mode: check one number, factor it, list the primes up to N, or find the neighbouring primes.
  2. Type the number — dots used as thousands separators are accepted and ignored.
  3. The answer appears with the divisions that produced it. Everything is computed in your browser.

About this tool

A prime number has exactly two divisors, 1 and itself. That makes primes the building blocks of arithmetic: every whole number above 1 is a product of primes in exactly one way, which is what the fundamental theorem of arithmetic states. 360 is 2³ × 3² × 5 and nothing else; 91 looks prime but is really 7 × 13; 97 genuinely is prime. Once the factorisation is known, other facts follow for free — the number of divisors is the product of each exponent plus one, so 360 has (3 + 1) × (2 + 1) × (1 + 1) = 24 of them.

Checking primality here is done by trial division, but only up to the square root of the number and only against candidates of the form 6k ± 1, since everything else is already a multiple of 2 or 3. That skips two thirds of the work and settles a number below a trillion in a few hundred thousand divisions, a couple of milliseconds. Above 10¹² even that becomes slow in a browser, so the answer switches to the deterministic Miller-Rabin test with the bases 2 through 37, which is proven exact for every number below 3.3×10²⁴ and therefore for everything this tool accepts, up to 2⁵³ − 1. Listing primes uses a different classic: the sieve of Eratosthenes writes out every number up to N, keeps the smallest unmarked one, crosses out all of its multiples, and repeats until only primes survive.

Prime factorisation is the machinery behind reducing fractions, finding an LCM or a GCD, and simplifying square roots, which is why it is taught early. Beyond school, the difficulty of factoring large numbers is what RSA encryption rests on: multiplying two big primes is instant, undoing it is not, and the gap between the two is the entire security argument. Primes also thin out predictably as numbers grow, though they never run out — Euclid proved that more than two thousand years ago. Numbers up to 2⁵³ − 1 can be tested here, factorisation and the neighbouring primes work up to a trillion, and the prime list goes up to 100,000. Nothing you type leaves your browser.

The formula

Primality by trial division: n is prime when no whole number from 2 up to √n divides it, and it is enough to test 2, 3 and then every candidate of the form 6k ± 1. Factorisation applies the same divisions and records how many times each prime fits; the number of divisors is the product of each exponent plus one. The prime list uses the sieve of Eratosthenes. Above 10^12 the primality answer comes from the deterministic Miller-Rabin test with bases 2 to 37, exact for every number below 2^53.

Frequently asked questions

How do I know whether a number is prime?

Try dividing it by every prime up to its square root: if none divides it exactly, the number is prime. For 97 the square root is under 10, so testing 2, 3, 5 and 7 is enough to settle it.

Is 1 a prime number?

No. A prime must have exactly two distinct divisors, and 1 has only one. Excluding it is also what makes prime factorisation unique, since otherwise any number could be padded with as many 1s as you like.

What is prime factorisation used for?

It is the basis of reducing fractions, computing the GCD and the LCM, simplifying square roots and counting divisors. Writing 360 as 2³ × 3² × 5 immediately gives its 24 divisors and everything it shares with another number.

How large a number can I test?

Up to 9,007,199,254,740,991 — that is 2⁵³ − 1 — for the primality check. Factorisation and the neighbouring primes go up to 1,000,000,000,000, and the prime list up to 100,000, so that every answer stays instant in the browser.

Why is 2 the only even prime?

Because every other even number is divisible by 2, which gives it a third divisor and disqualifies it. That is also why the tool skips even candidates once it has tested 2.

Do my numbers leave my browser?

No. The divisions, the sieve and the Miller-Rabin test all run in JavaScript on your device, with no requests to any server and nothing stored.

Related tools

Long links? Shorten them for free

Vai.la turns any URL into a short link with click statistics, QR Code and your own biolink.

Vai.la is not responsible for how the tools are used or for decisions made based on their results.