Last updated March 2026

Prime Number Checker

Enter any number up to 10,000,000 to check if it is prime, view its prime factorization, all factors, and nearest primes.

Is Prime? --
Prime Factorization --
All Factors --
Previous Prime --
Next Prime --

What Is a Prime Number?

A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. In other words, a prime number has exactly two distinct positive divisors: 1 and itself. The number 7 is prime because the only way to write it as a product of positive integers is 1 × 7. The number 6, however, is not prime (it is composite) because it can be written as 2 × 3.

The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, and 97. Notice that 2 is the only even prime number. Every even number greater than 2 is divisible by 2, so it cannot be prime. This makes 2 unique among primes and is why mathematicians sometimes call it the oddest prime.

Prime numbers are the building blocks of all natural numbers. The Fundamental Theorem of Arithmetic states that every integer greater than 1 is either a prime itself or can be represented as a unique product of prime numbers, regardless of the order of the factors. For example, 84 = 2 × 2 × 3 × 7, and no other combination of primes multiplies to give 84. This property makes primes foundational to number theory, algebra, and modern cryptography.

How to Check if a Number Is Prime

The simplest method for testing whether a number is prime is called trial division. To determine if a number n is prime, check whether it is divisible by any integer from 2 up to the square root of n. If no divisor is found, the number is prime. The reason you only need to check up to the square root is that if n = a × b, then at least one of a or b must be less than or equal to √n.

For a number n, test divisibility by all primes p where p ≤ √n

Example: Is 97 prime? The square root of 97 is approximately 9.85. So we only need to test primes up to 9: 2, 3, 5, and 7. Since 97 is odd (not divisible by 2), not divisible by 3 (9 + 7 = 16, which is not a multiple of 3), does not end in 0 or 5 (not divisible by 5), and 97 / 7 ≈ 13.86 (not a whole number), we conclude that 97 is prime.

For very large numbers, trial division becomes impractical. Mathematicians and computer scientists use more efficient algorithms such as the Miller-Rabin primality test, the AKS primality test, and the Lucas-Lehmer test. The Miller-Rabin test is a probabilistic method that can quickly determine whether a number is composite, with a very small chance of error that decreases with each additional test round. The AKS test, published in 2002 by Agrawal, Kayal, and Saxena, was the first deterministic primality test proven to run in polynomial time, a landmark achievement in computational number theory.

This calculator uses an optimized trial division algorithm that checks divisibility by 2 and 3 first, then tests potential factors of the form 6k ± 1 up to the square root of n. This optimization works because all primes greater than 3 are of the form 6k ± 1, allowing us to skip many candidate divisors and significantly speed up the check for numbers up to 10 million.

Prime Factorization Explained

Prime factorization is the process of breaking down a composite number into the product of its prime factors. Every composite number can be expressed as a unique product of primes, a fact guaranteed by the Fundamental Theorem of Arithmetic. Finding the prime factorization is a fundamental operation in mathematics with applications in simplifying fractions, finding greatest common divisors (GCD), computing least common multiples (LCM), and solving problems in cryptography.

The standard algorithm for prime factorization uses repeated division. Start by dividing the number by the smallest prime, 2, as many times as possible. Then move to 3, then 5, then 7, and so on, dividing each time until the quotient is 1.

Example: Find the prime factorization of 360.

So 360 = 2³ × 3² × 5. This factorization is unique; no other set of primes multiplies to give 360.

Prime factorization has practical uses beyond pure mathematics. In computing, the RSA encryption algorithm relies on the difficulty of factoring very large numbers that are the product of two large primes. While it is easy to multiply two 300-digit primes together, factoring the resulting 600-digit product back into its two prime components would take classical computers longer than the age of the universe. This asymmetry between multiplication and factoring is what makes RSA encryption secure.

Factors vs. Prime Factors

It is important to distinguish between factors and prime factors. The factors (or divisors) of a number are all the whole numbers that divide it evenly with no remainder. The prime factors are the subset of those factors that are themselves prime numbers.

Example: The number 36 has the following factors: 1, 2, 3, 4, 6, 9, 12, 18, and 36. Among these, the prime factors are only 2 and 3. The prime factorization is 2² × 3² = 36. The total number of factors can be calculated from the prime factorization by adding 1 to each exponent and multiplying: (2+1) × (2+1) = 9 factors, which matches our list.

This formula for counting factors is useful in many areas of mathematics. If n = p1a × p2b × p3c, then the total number of factors is (a+1)(b+1)(c+1). For example, 720 = 24 × 32 × 51, so the number of factors is (4+1)(2+1)(1+1) = 30. Numbers with many factors relative to their size are called highly composite numbers, and they appear frequently in practical applications like gear ratios, musical tuning systems, and time measurement (60 minutes in an hour, 360 degrees in a circle).

Famous Prime Numbers and Records

The search for large prime numbers has fascinated mathematicians for centuries and continues to push the boundaries of computational power. The largest known primes are Mersenne primes, which have the form 2p – 1, where p itself is prime. Not all numbers of this form are prime, but when they are, they tend to be extraordinarily large.

As of 2024, the largest known prime number is 2136,279,841 – 1, a Mersenne prime with over 41 million digits. It was discovered by the Great Internet Mersenne Prime Search (GIMPS), a distributed computing project where volunteers donate computing power to test Mersenne candidates. There are currently 52 known Mersenne primes, and discovering a new one is considered a significant mathematical event.

Other notable prime categories include twin primes (primes that differ by 2, such as 11 and 13), palindromic primes (primes that read the same forward and backward, like 131 and 757), and Sophie Germain primes (primes p where 2p + 1 is also prime, such as 11, since 2 × 11 + 1 = 23 is also prime). The Twin Prime Conjecture, which asserts that there are infinitely many twin primes, remains one of the greatest unsolved problems in mathematics.

Primes in Cryptography

Prime numbers are the foundation of modern internet security. Nearly every time you make an online purchase, log into a bank account, or send an encrypted message, prime numbers are working behind the scenes to keep your data safe.

The RSA algorithm, one of the most widely used public-key cryptosystems, works as follows: two large prime numbers (each typically 300 or more digits long) are selected in secret and multiplied together to produce a public key. Anyone can use this public key to encrypt a message, but only someone who knows the two original primes can decrypt it. The security of RSA depends entirely on the fact that factoring the product of two large primes is computationally infeasible with current technology.

The Diffie-Hellman key exchange, another foundational cryptographic protocol, uses modular arithmetic with large primes to allow two parties to establish a shared secret over an insecure channel. Elliptic curve cryptography (ECC), used in modern TLS connections and Bitcoin, also relies on mathematical structures built on prime fields.

The potential future development of quantum computers poses a threat to these systems. A sufficiently powerful quantum computer running Shor's algorithm could factor large numbers exponentially faster than classical computers, potentially breaking RSA encryption. This has spurred research into post-quantum cryptography, which uses mathematical problems believed to be resistant to both classical and quantum attacks.

Distribution of Prime Numbers

One of the most important questions in mathematics is how prime numbers are distributed among the natural numbers. While primes become less frequent as numbers get larger, they never stop appearing entirely. Euclid proved over 2,300 years ago that there are infinitely many primes, using an elegant proof by contradiction: if there were only finitely many primes, you could multiply them all together and add 1 to get a number that is not divisible by any known prime, contradicting the assumption.

The Prime Number Theorem, proven independently by Hadamard and de la Vallee Poussin in 1896, gives an approximate formula for how many primes exist below a given number. It states that the number of primes less than or equal to n is approximately n / ln(n), where ln is the natural logarithm. For example, among the first million numbers, there are 78,498 primes. The formula predicts approximately 1,000,000 / ln(1,000,000) ≈ 72,382, which is in the right ballpark and becomes more accurate for larger values.

The Riemann Hypothesis, formulated in 1859 and still unproven, would provide an even more precise description of prime distribution. It is considered perhaps the most important unsolved problem in all of mathematics, with a million-dollar prize offered by the Clay Mathematics Institute for its proof or disproof.

Practical Uses of Prime Numbers

Beyond pure mathematics and cryptography, prime numbers have several practical applications:

Frequently Asked Questions

What is a prime number?

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first ten primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. A number that is greater than 1 and is not prime is called a composite number. For example, 15 is composite because it equals 3 × 5. The number 2 is the smallest and only even prime number, since every other even number is divisible by 2.

Is 1 a prime number?

No, 1 is not considered a prime number. By the modern mathematical definition, a prime must be greater than 1 and have exactly two distinct divisors. The number 1 has only one divisor (itself), so it does not qualify. Mathematicians excluded 1 from the primes to preserve the uniqueness of prime factorization. If 1 were prime, then 6 could be factored as 2 × 3, or 1 × 2 × 3, or 1 × 1 × 2 × 3, and so on, destroying the uniqueness that makes prime factorization so useful.

How do you find the prime factorization of a number?

To find the prime factorization, repeatedly divide the number by the smallest possible prime. Start with 2 and divide as many times as possible. Then try 3, then 5, then 7, and so on. Continue until the quotient reaches 1. For example, to factor 180: 180 ÷ 2 = 90, 90 ÷ 2 = 45, 45 ÷ 3 = 15, 15 ÷ 3 = 5, 5 ÷ 5 = 1. Therefore, 180 = 2² × 3² × 5.

Why are prime numbers important in cryptography?

Prime numbers are essential to cryptography because the security of algorithms like RSA depends on the difficulty of factoring large numbers. Multiplying two large primes together is computationally easy, but reversing the process and finding the original primes from their product is extraordinarily difficult for sufficiently large numbers. A 2048-bit RSA key involves primes with over 300 digits each, and factoring their product would take classical computers billions of years.

Are there infinitely many prime numbers?

Yes, Euclid proved around 300 BCE that there are infinitely many primes. His proof works by contradiction: assume there are only finitely many primes. Multiply them all together and add 1. The resulting number is not divisible by any of the assumed primes, so it is either a new prime itself or has a prime factor not in the original list. Either way, the assumption is contradicted. Therefore, the list of primes never ends, though they become less frequent as numbers grow larger.

Related Calculators