InfyCalculator
➗

Prime Number Calculator

Check whether a number is prime, see its prime factorization, and find the next and previous primes — all by trial division.

Number
Loading calculator…

How it works

Prime test: n has no divisor d with 2 ≤ d ≤ √n · Factorization: repeatedly divide by the smallest prime factor

A prime number is a whole number greater than 1 whose only divisors are 1 and itself. To test one, trial division checks for a factor up to the square root of n — if none divides evenly, n is prime, because any factor larger than √n would pair with a smaller one already checked. The factorization strips out the smallest prime factor repeatedly until 1 remains, giving the unique product guaranteed by the fundamental theorem of arithmetic. Note that 0 and 1 are neither prime nor composite.

Worked example

Take 97. Its square root is about 9.85, so it’s enough to test the primes 2, 3, 5 and 7. None divides 97 evenly, so 97 is prime. Its factorization is just itself; the previous prime is 89 and the next is 101. By contrast 20 = 2 × 2 × 5, so it is composite.

Sources: Prime number — Wikipedia

Frequently asked questions

Is 1 a prime number?

No. A prime must have exactly two distinct divisors, 1 and itself. The number 1 has only one divisor, so it is neither prime nor composite — a convention that keeps prime factorizations unique.

Why only test up to the square root?

If n = a × b with both factors above √n, their product would exceed n. So at least one factor of any composite is ≤ √n; finding none there proves n is prime, saving enormous work.

What is a prime factorization?

It’s the unique way to write a number as a product of primes, such as 20 = 2 × 2 × 5. The fundamental theorem of arithmetic guarantees every integer above 1 has exactly one such factorization.

Related calculators

This calculator is for educational purposes. Double-check important results before acting on them.