Prime Number Calculator
Check if any integer is prime or composite with trial division steps, divisor list, next and previous primes, and BigInt precision.
What Is a Prime Number?
A prime number is a positive integer strictly greater than 1 that has exactly two positive integer factors: 1 and the number itself. If a positive integer greater than 1 has more than two factors, it is called a composite number.
For example, 7 is a prime number because its only divisors are 1 and 7. In contrast, 8 is composite because it is evenly divisible by 1, 2, 4, and 8.
Why Are 0 and 1 Not Prime Numbers?
Neither 0 nor 1 meets the mathematical criteria for prime numbers:
- Why 1 is not prime: Under the Fundamental Theorem of Arithmetic, every positive integer greater than 1 can be uniquely factored into a product of prime numbers (up to the order of the factors). If 1 were considered prime, unique factorization would collapse because any number could have infinitely many prime factorizations, such as $6 = 2 \times 3 = 1 \times 2 \times 3 = 1^2 \times 2 \times 3$. Therefore, 1 is formally classified as a unit.
- Why 0 is not prime: Zero has infinitely many divisors because $0 = 0 \times k$ for any integer $k$. Moreover, prime numbers must be strictly positive.
How to Test if a Number Is Prime: The $\sqrt{N}$ Rule
To test if an integer $N$ is prime using trial division, you do not need to check every number up to $N$. You only need to test potential prime factors up to the square root of $N$:
$$d \le \sqrt{N}$$
If $N$ were composite, it would factor into $N = a \times b$. If both $a > \sqrt{N}$ and $b > \sqrt{N}$, then $a \times b > N$, which is impossible. Thus, at least one factor must be less than or equal to $\sqrt{N}$. If no prime factor exists up to $\sqrt{N}$, then $N$ is guaranteed to be prime.
Worked Example: Testing Whether 97 Is Prime
- Check if 97 is even: $97 \div 2 = 48.5$ (not divisible).
- Compute the upper bound: $\sqrt{97} \approx 9.848$. The integer search limit is $\lfloor\sqrt{97}\rfloor = 9$.
- List all prime numbers up to 9: 2, 3, 5, 7.
- Test each prime divisor:
- $97 \div 3 = 32$ remainder 1
- $97 \div 5 = 19$ remainder 2
- $97 \div 7 = 13$ remainder 6
- Since no divisor evenly divides 97, 97 is prime.
The Sieve of Eratosthenes and Primality in Modern Cryptography
For generating lists of primes, the ancient Greek algorithm known as the Sieve of Eratosthenes efficiently eliminates multiples of each discovered prime.
In modern digital security, massive prime numbers with hundreds of digits form the core foundation of public-key encryption schemes like RSA and Diffie-Hellman. Algorithms such as the Miller-Rabin probabilistic test and the AKS deterministic test allow computers to verify primality for enormous numbers in milliseconds.
Explore related arithmetic and number theory tools like our Prime Factors Calculator, the First N Prime Numbers, and the Generate Prime Numbers generator.
Frequently Asked Questions
What is the only even prime number?
The number 2 is the only even prime number. Every even number greater than 2 is divisible by 2, meaning it has at least three distinct divisors (1, 2, and the number itself) and is therefore composite.
What is the largest known prime number?
The largest known prime numbers are Mersenne primes of the form $2^p - 1$. Discovered by the Great Internet Mersenne Prime Search (GIMPS), these primes contain tens of millions of digits.
Are negative numbers ever considered prime?
In standard elementary arithmetic and number theory, primes are defined strictly over the positive integers greater than 1. While abstract algebra discusses irreducible elements in the ring of integers $\mathbb{Z}$, conventional primality tests only apply to positive integers.
What are twin primes?
Twin primes are pairs of prime numbers that differ by exactly 2, such as (3, 5), (11, 13), (17, 19), and (29, 31). The famous Twin Prime Conjecture posits that there are infinitely many such pairs.