Skip to content
Math

Prime Number Calculator

Enter any whole number to instantly find out whether it is prime or composite. For composite numbers you also get the complete prime factorization, all divisors, and the next and previous prime.

Your details

Enter any positive integer. The calculator checks primality, finds all factors, and shows neighboring primes.
Choose which results to display.
PrimalityPrime
Prime
Smallest prime factor-
Prime factorization97 (already prime)
Number of divisors2
All divisors1, 97
Previous prime89
Next prime101
Twin prime partnerNo (not part of a twin prime pair)

97 is a prime number.

  • 97 has exactly two positive divisors: 1 and itself, the definition of prime.
  • The nearest primes on either side are 89 and 101.

Next stepTest the next odd number to look for a twin prime pair.

Formula

prime    n>1 and nmodd0  d{2,,n}\text{prime} \iff n>1 \text{ and } n\bmod d \neq 0 \;\forall\, d \in \{2,\dots,\lfloor\sqrt{n}\rfloor\}

Worked example

Test 84: square root is about 9.2. Check 2: 84/2 = 42, so 2 is a factor. Then 42/2 = 21, then 21/3 = 7, and 7 is prime. Prime factorization of 84 = 2^2 x 3 x 7. The divisors of 84 are 1, 2, 3, 4, 6, 7, 12, 14, 21, 28, 42, 84. Previous prime: 83. Next prime: 89. Test 97: no divisor from 2 to 9 works, so 97 is prime. Its neighbors are 89 and 101.

What makes a number prime

A prime number is a whole number greater than 1 that has exactly two distinct positive divisors: 1 and itself. Numbers like 2, 3, 5, 7, 11, and 13 are prime. Any whole number above 1 that is not prime is called composite because it can be built from smaller factors. The number 1 is excluded from both groups by convention, ensuring that every integer above 1 has a unique prime factorization (the Fundamental Theorem of Arithmetic). The number 2 is the only even prime: every other even number divides by 2, giving it at least three divisors.

Why we only test up to the square root

To check whether n is prime, you only need to test divisors up to the square root of n. If n has a factor larger than its square root, the corresponding co-factor must be smaller than the square root, so it would already have been found. This cuts the work dramatically: checking a six-digit number needs at most a few hundred trial divisions instead of hundreds of thousands. This calculator further reduces the work by only trying divisors of the form 2, 3, or 6k plus or minus 1, since every prime above 3 fits that pattern.

Prime factorization and divisors

Every composite number can be written as a unique product of primes. For example, 360 = 2^3 x 3^2 x 5. This is called the prime factorization. Knowing it unlocks a formula for the total number of divisors: multiply together (each exponent + 1). For 360 that is (3+1)(2+1)(1+1) = 24 divisors. This calculator performs repeated trial division to find all prime factors, then lists every divisor for numbers up to ten million. Full divisor enumeration is the most requested feature on competing tools, and is genuinely useful for number-theory problems, GCD and LCM work, and puzzle solving.

Neighboring primes and twin primes

The next prime and the previous prime are found by incrementing or decrementing from the input and testing each candidate. On average, the gap between primes near n is about ln(n), so the search terminates quickly. A twin prime is a prime p such that p + 2 is also prime (or p - 2 is prime). Twin prime pairs include (3, 5), (5, 7), (11, 13), (17, 19), and (41, 43). The Twin Prime Conjecture states that infinitely many such pairs exist, but as of 2026 this remains one of the great unsolved problems in mathematics.

Primes up to 100

Primes in this decade
2, 3, 5, 7
11, 13, 17, 19
23, 29
31, 37
41, 43, 47
53, 59
61, 67
71, 73, 79
83, 89
97

There are exactly 25 prime numbers between 2 and 100.

Frequently asked questions

Is 1 a prime number?

No. A prime must have exactly two distinct positive divisors, but 1 has only one divisor (itself). Mathematicians exclude 1 from the primes so that every integer above 1 has exactly one prime factorization, a property called the Fundamental Theorem of Arithmetic.

What is the smallest and only even prime?

The number 2 is the smallest prime and the only even one. Every other even number is divisible by 2, giving it at least three divisors (1, 2, and itself), so it cannot be prime.

How do I find the prime factorization of a number?

Start by dividing the number by its smallest prime factor and repeat the process with the quotient until you reach 1. For example, 60 divides by 2 to give 30, then 30 divides by 2 to give 15, then 15 divides by 3 to give 5, which is prime. So 60 = 2^2 x 3 x 5. This calculator does all of those steps and shows the work.

What is a twin prime?

Twin primes are pairs of prime numbers that differ by exactly 2, such as (11, 13), (17, 19), or (41, 43). The Twin Prime Conjecture holds that infinitely many such pairs exist, but this has never been proven. The calculator checks whether your number is part of a twin prime pair.

How do I find the next or previous prime?

The calculator checks each integer above (or below) your number in turn until it finds one that passes the primality test. On average, primes near n are spaced about ln(n) apart, so for numbers in the millions you typically only need to check a few dozen candidates.

How many divisors does a prime have compared to a composite?

Every prime has exactly 2 divisors: 1 and itself. Composite numbers have 3 or more. The number of divisors of n = p1^a1 x p2^a2 x ... equals (a1+1)(a2+1).... For example, 12 = 2^2 x 3, so it has (2+1)(1+1) = 6 divisors: 1, 2, 3, 4, 6, 12.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…