Skip to content
CalcHub

Prime Number Calculator

Check whether a number is prime, and get its prime factorization, number of divisors, and the nearest prime numbers above and below it.

Prime Number CalculatorLive

How to use this calculator

  1. 1Enter any whole number greater than zero.
  2. 2Read whether it is prime or composite.
  3. 3If composite, see its unique prime factorization and how many divisors it has.
  4. 4Use the nearest primes above and below to explore the number line around it.

How it works

Primality and factorization

prime = a whole number > 1 divisible only by 1 and itself
test: no integer from 2 to √n divides n → n is prime
factorization: n = p₁^a × p₂^b × …
divisor count = (a+1)(b+1)…

A prime number is a whole number greater than 1 whose only divisors are 1 and itself; every other whole number above 1 is composite and can be written as a product of primes. To test primality you only need to try dividing by integers up to the square root of n — if none divides evenly, n is prime, because any factor larger than the square root must pair with one smaller than it. The prime factorization, guaranteed unique by the Fundamental Theorem of Arithmetic, is the number's fingerprint: from it you can read off how many divisors the number has by adding one to each prime's exponent and multiplying the results.

Worked example

60 is not prime: dividing by 2 works, so it is composite. Its prime factorization is 2² × 3 × 5, from which the divisor count is (2+1)(1+1)(1+1) = 12. The nearest primes are 59 below and 61 above — a twin-prime pair straddling 60.

Prime Number Calculator: the complete guide

What makes a number prime

A prime number is a whole number greater than 1 that cannot be formed by multiplying two smaller whole numbers — its only divisors are 1 and itself. The first few are 2, 3, 5, 7, 11, 13, and they thin out but never stop; Euclid proved over two thousand years ago that there are infinitely many. Two is the only even prime, since every other even number is divisible by 2, which makes it a frequent exception in proofs.

The number 1 is deliberately excluded from the primes. This is not an oversight but a choice that keeps the mathematics tidy: if 1 were prime, then prime factorizations would no longer be unique, because you could tack on any number of 1s. Treating 1 as neither prime nor composite preserves the Fundamental Theorem of Arithmetic, which says every whole number above 1 has exactly one prime factorization. That uniqueness is the foundation on which much of number theory is built.

Why you only test up to the square root

Checking whether a number is prime by trying every possible divisor sounds slow, but there is a shortcut that cuts the work dramatically: you only need to test divisors up to the square root of the number. The reason is symmetry. If n has a factor larger than its square root, then dividing n by that factor gives a second factor smaller than the square root — so any composite number must have a divisor at or below √n. Find none there, and none exists anywhere.

This is why testing a number near a million takes only about a thousand trial divisions rather than a million. For the far larger numbers used in cryptography, even the square-root shortcut is too slow, and mathematicians use probabilistic tests that can judge a several-hundred-digit number's primality in a fraction of a second. But for everyday numbers, trial division up to the square root — exactly what this calculator does — is both fast and completely certain.

Primes as the atoms of arithmetic

Primes are often called the building blocks of the whole numbers, and the metaphor is precise: just as every molecule is built from atoms, every whole number is built from primes in exactly one way. This prime factorization is a number's true identity. It determines how many divisors it has, whether two numbers share common factors, and how fractions reduce. The greatest common divisor and least common multiple both fall straight out of comparing factorizations.

This structure is not just elegant; it is useful and even valuable. The difficulty of factoring very large numbers back into their primes — easy to multiply, brutally hard to reverse — is what secures much of modern encryption. When you shop or bank online, prime numbers hundreds of digits long are quietly protecting the connection. The same simple objects a child meets while learning multiplication turn out to underpin the security of the entire internet.

Frequently asked questions

How do I know if a number is prime?

Try dividing it by every whole number from 2 up to its square root. If none divides evenly, the number is prime; if any does, it is composite. You only need to check up to the square root because any larger factor pairs with a smaller one below it.

Is 1 a prime number?

No. A prime must have exactly two distinct divisors, 1 and itself, but 1 has only one divisor. It is classed as neither prime nor composite. Excluding it keeps prime factorization unique, which is why the convention exists.

What is prime factorization?

It is writing a number as a product of prime numbers, like 60 = 2² × 3 × 5. By the Fundamental Theorem of Arithmetic every whole number above 1 has exactly one such factorization, which acts as the number's fingerprint and reveals its divisors and common factors.

Why are prime numbers important?

They are the building blocks of all whole numbers, so they underpin divisibility, fractions, and factors. They also secure modern encryption: multiplying two large primes is easy, but factoring the result back is so hard it protects online banking and communication.