Prime Number Calculator

Check whether a nonnegative integer is prime and find the nearest prime numbers on either side.

Test a number for primality
Enter a nonnegative whole number no greater than one trillion.

About prime numbers

A prime number is a whole number greater than one with exactly two positive divisors: one and the number itself. Numbers greater than one that have additional divisors are composite. Seven is prime because only one and seven divide it evenly, while nine is composite because three is an additional divisor. Zero and one are neither prime nor composite, a convention that preserves important number-theory results and keeps prime factorization unique. This calculator tests primality by looking for a divisor. Even numbers greater than two can be rejected immediately. For an odd candidate, only odd divisors up to its square root need to be checked. If a composite number equals a times b, at least one of those factors must be no larger than the square root; otherwise both would be larger and their product would exceed the number. Reaching that boundary without finding a divisor proves the candidate is prime. The result also displays the nearest smaller and larger primes. Finding them means testing consecutive integers outward until a prime is reached. Two has no smaller prime because it is the first prime number. Prime gaps vary: some primes are only two apart and form twin-prime pairs, while other neighboring primes have much larger differences. There is always another prime above any chosen integer, as Euclid's classic proof shows that the sequence of primes never ends. Prime numbers are central to arithmetic because every integer greater than one factors uniquely into primes. They support fraction simplification, greatest common divisor methods, modular arithmetic, and many divisibility arguments. Modern public-key cryptography uses operations built around large primes and computationally difficult inverse problems. Hash tables, randomization techniques, error-correcting codes, and cyclic patterns also draw on prime properties. For hand checking, first eliminate divisibility by two, three, and five, then continue with possible prime divisors no greater than the square root. Divisibility rules can make those checks faster, but trial division remains the underlying proof for modest inputs. The calculator applies exact integer remainder tests rather than a statistical estimate, so every answer within the accepted range is deterministic. JavaScript represents ordinary numbers exactly only through its safe integer limit, so the input is restricted to that range. Extremely large cryptographic candidates require specialized big-integer algorithms such as Miller-Rabin followed by stronger proof methods. For schoolwork, factor checks, sequence exploration, and everyday number theory, the exact square-root method used here is straightforward and reliable. Enter any nonnegative integer to classify it and see its nearest prime neighbors.

Prime number examples

A prime has exactly two positive divisors, while a composite number has more.

IntegerClassificationReason
1Neither prime nor compositeOne has only one positive divisor.
2PrimeTwo is the only even prime.
29PrimeNo integer from two through its square root divides it.
91CompositeSeven times thirteen equals ninety-one.

How to use the prime number calculator

  1. Enter the nonnegative whole number you want to test.
  2. Choose Check Number to search for divisors up to the square root.
  3. Read whether the number is prime or not prime.
  4. Use the displayed neighboring primes for sequence or interval work.

Prime number calculator FAQ

Is one a prime number?

No, one has only one positive divisor instead of exactly two. It is classified as neither prime nor composite.

Is two a prime number?

Yes, its only positive divisors are one and two. It is also the only even prime number.

Are negative numbers prime?

Under the standard elementary definition, prime numbers are positive integers greater than one. Negative integers can have prime factors, but are not themselves called prime here.

Why test only through the square root?

Any composite number has a factor pair with at least one member no larger than its square root. If no divisor exists by that point, no larger unpaired divisor can exist.

Are there infinitely many primes?

Yes, Euclid proved that no finite list can contain every prime. Multiplying a proposed list and adding one always produces a number requiring another prime factor.