Primality & Factorization
Last reviewed: May 2026
Test primality, find prime factorizations, and generate prime lists. Every integer > 1 is either prime or a unique product of primes. This underpins modern cryptography and number theory.1
| Range | Primes | Count |
|---|---|---|
| 1โ50 | 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 | 15 |
| 51โ100 | 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 | 10 |
| Number | Factors | Form |
|---|---|---|
| 60 | 2,2,3,5 | 2ยฒร3ร5 |
| 100 | 2,2,5,5 | 2ยฒร5ยฒ |
| 360 | 2,2,2,3,3,5 | 2ยณร3ยฒร5 |
A prime number is a natural number greater than 1 that has exactly two factors: 1 and itself. The first primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29... The number 2 is the only even prime โ every other even number is divisible by 2. The number 1 is not prime by convention (it has only one factor, not two). Primes are the "atoms" of arithmetic โ the Fundamental Theorem of Arithmetic states that every integer greater than 1 can be uniquely expressed as a product of primes.
Trial division: Test divisibility by all primes up to โn. If none divide evenly, n is prime. For 97: โ97 โ 9.85, so check 2, 3, 5, 7. None divide 97, so it's prime. This works because if n = a ร b and both a,b > โn, then a ร b > n โ a contradiction. Sieve of Eratosthenes: To find all primes up to N, start with a list of integers 2 to N. Mark 2 as prime, cross out all multiples of 2. Find the next unmarked number (3), mark it prime, cross out its multiples. Continue until you've processed all numbers up to โN. This 2,300-year-old algorithm remains efficient for finding primes up to several million.
Modern internet security relies entirely on prime numbers. RSA encryption (used in HTTPS, email encryption, and digital signatures) works because multiplying two large primes is easy, but factoring their product back into the original primes is computationally infeasible. A typical RSA key uses two 1,024-bit primes (each ~300 digits long) whose product is a 2,048-bit number. No known algorithm can factor a 2,048-bit number in a practical timeframe โ the best estimates suggest it would take billions of years with current technology.
Primes become less frequent as numbers get larger, but they never stop appearing โ Euclid proved there are infinitely many primes around 300 BCE. The Prime Number Theorem (proved in 1896) states that the number of primes up to N is approximately N/ln(N). Among the first 100 numbers, 25 are prime (25%). Among the first 1,000, 168 are prime (16.8%). Among the first million, 78,498 are prime (7.8%). The Riemann Hypothesis โ one of the greatest unsolved problems in mathematics, with a $1 million prize โ concerns the exact distribution pattern of primes.
Twin primes: Pairs differing by 2 (3,5), (11,13), (17,19), (29,31). It's conjectured but unproven that infinitely many twin primes exist. Mersenne primes: Primes of the form 2^p โ 1 (e.g., 2^31 โ 1 = 2,147,483,647). The largest known primes are Mersenne primes โ as of 2024, the record is 2^82,589,933 โ 1, a number with 24,862,048 digits. The Great Internet Mersenne Prime Search (GIMPS) distributes the search across volunteer computers worldwide. Sophie Germain primes: Where p and 2p+1 are both prime โ important in cryptographic key generation.
Prime numbers โ integers greater than 1 divisible only by 1 and themselves โ are the atoms of arithmetic. The Fundamental Theorem of Arithmetic states that every integer greater than 1 can be expressed as a unique product of primes: 360 = 2ยณ ร 3ยฒ ร 5, and no other combination of primes produces 360. This uniqueness property underlies modern cryptography. RSA encryption, which secures online banking, email, and e-commerce, relies on the fact that multiplying two large primes is trivially easy (a computer can multiply two 300-digit primes in microseconds) but factoring the result back into its prime components is computationally infeasible โ current methods would take longer than the age of the universe for sufficiently large numbers. Your web browser uses this asymmetry every time you see the padlock icon on a secure website.
The simplest primality test: divide the candidate by every integer from 2 up to its square root. If none divide evenly, the number is prime. Why only up to the square root? Because if n = a ร b and both a and b were greater than โn, then a ร b > n โ a contradiction. For 97: โ97 โ 9.85, so test divisibility by 2, 3, 5, and 7 (primes up to 9). None divide 97 evenly, so 97 is prime. This method works for small numbers but becomes slow for large ones. Faster algorithms include the Miller-Rabin probabilistic test (used in practice โ it can declare a number "probably prime" with any desired level of certainty) and the AKS algorithm (the first proven polynomial-time deterministic test, published in 2002). For everyday use, trial division handles numbers up to about 10 million in under a second on modern hardware.
Primes become sparser as numbers grow larger, but they never stop appearing โ a fact proven by Euclid around 300 BCE. The Prime Number Theorem, proved in 1896, states that the number of primes below n is approximately n/ln(n). Among numbers near 1,000, roughly 1 in 7 is prime. Near 1,000,000, about 1 in 14. Near 1,000,000,000, about 1 in 21. Despite this thinning, primes exhibit fascinating clustering: twin primes (pairs differing by 2, like 11-13, 17-19, 29-31) appear to continue forever, though this remains unproven โ the Twin Prime Conjecture is one of mathematics' great open problems. The largest known prime, discovered in 2024, has over 41 million digits โ found by the Great Internet Mersenne Prime Search (GIMPS), a distributed computing project that has identified the 15 largest known primes by testing numbers of the form 2^p - 1.
Prime numbers appear in unexpected places outside pure mathematics. Cicadas emerge on prime-numbered year cycles (13 or 17 years) โ biologists hypothesize this minimizes overlap with predator population cycles, since prime periods share few common multiples with shorter cycles. Hash tables in computer science use prime-sized arrays to distribute data more uniformly, reducing clustering that degrades performance. Digital signal processing uses prime-length sequences to design error-correcting codes and avoid harmonic interference. In music, consonant intervals correspond to frequency ratios of small integers (octave = 2:1, fifth = 3:2), while dissonant intervals involve larger primes โ a connection between number theory and acoustics that fascinated Pythagoras and continues to inform musical tuning systems. Even bar code systems and ISBN numbers use modular arithmetic with primes to create check digits that catch transcription errors.
Prime numbers โ integers greater than 1 divisible only by 1 and themselves โ are the atoms of arithmetic. The Fundamental Theorem of Arithmetic states that every integer greater than 1 can be expressed as a unique product of primes: 360 = 2ยณ ร 3ยฒ ร 5, and no other combination of primes produces 360. This uniqueness property underlies modern cryptography. RSA encryption, which secures online banking, email, and e-commerce, relies on the fact that multiplying two large primes is trivially easy (a computer can multiply two 300-digit primes in microseconds) but factoring the result back into its prime components is computationally infeasible โ current methods would take longer than the age of the universe for sufficiently large numbers. Your web browser uses this asymmetry every time you see the padlock icon on a secure website.
The simplest primality test: divide the candidate by every integer from 2 up to its square root. If none divide evenly, the number is prime. Why only up to the square root? Because if n = a ร b and both a and b were greater than โn, then a ร b > n โ a contradiction. For 97: โ97 โ 9.85, so test divisibility by 2, 3, 5, and 7 (primes up to 9). None divide 97 evenly, so 97 is prime. This method works for small numbers but becomes slow for large ones. Faster algorithms include the Miller-Rabin probabilistic test (used in practice โ it can declare a number "probably prime" with any desired level of certainty) and the AKS algorithm (the first proven polynomial-time deterministic test, published in 2002). For everyday use, trial division handles numbers up to about 10 million in under a second on modern hardware.
Primes become sparser as numbers grow larger, but they never stop appearing โ a fact proven by Euclid around 300 BCE. The Prime Number Theorem, proved in 1896, states that the number of primes below n is approximately n/ln(n). Among numbers near 1,000, roughly 1 in 7 is prime. Near 1,000,000, about 1 in 14. Near 1,000,000,000, about 1 in 21. Despite this thinning, primes exhibit fascinating clustering: twin primes (pairs differing by 2, like 11-13, 17-19, 29-31) appear to continue forever, though this remains unproven โ the Twin Prime Conjecture is one of mathematics' great open problems. The largest known prime, discovered in 2024, has over 41 million digits โ found by the Great Internet Mersenne Prime Search (GIMPS), a distributed computing project that has identified the 15 largest known primes by testing numbers of the form 2^p - 1.
Prime numbers appear in unexpected places outside pure mathematics. Cicadas emerge on prime-numbered year cycles (13 or 17 years) โ biologists hypothesize this minimizes overlap with predator population cycles, since prime periods share few common multiples with shorter cycles. Hash tables in computer science use prime-sized arrays to distribute data more uniformly, reducing clustering that degrades performance. Digital signal processing uses prime-length sequences to design error-correcting codes and avoid harmonic interference. In music, consonant intervals correspond to frequency ratios of small integers (octave = 2:1, fifth = 3:2), while dissonant intervals involve larger primes โ a connection between number theory and acoustics that fascinated Pythagoras and continues to inform musical tuning systems. Even bar code systems and ISBN numbers use modular arithmetic with primes to create check digits that catch transcription errors.
Prime numbers โ integers greater than 1 divisible only by 1 and themselves โ are the atoms of arithmetic. The Fundamental Theorem of Arithmetic states that every integer greater than 1 can be expressed as a unique product of primes: 360 = 2ยณ ร 3ยฒ ร 5, and no other combination of primes produces 360. This uniqueness property underlies modern cryptography. RSA encryption, which secures online banking, email, and e-commerce, relies on the fact that multiplying two large primes is trivially easy (a computer can multiply two 300-digit primes in microseconds) but factoring the result back into its prime components is computationally infeasible โ current methods would take longer than the age of the universe for sufficiently large numbers. Your web browser uses this asymmetry every time you see the padlock icon on a secure website.
The simplest primality test: divide the candidate by every integer from 2 up to its square root. If none divide evenly, the number is prime. Why only up to the square root? Because if n = a ร b and both a and b were greater than โn, then a ร b > n โ a contradiction. For 97: โ97 โ 9.85, so test divisibility by 2, 3, 5, and 7 (primes up to 9). None divide 97 evenly, so 97 is prime. This method works for small numbers but becomes slow for large ones. Faster algorithms include the Miller-Rabin probabilistic test (used in practice โ it can declare a number "probably prime" with any desired level of certainty) and the AKS algorithm (the first proven polynomial-time deterministic test, published in 2002). For everyday use, trial division handles numbers up to about 10 million in under a second on modern hardware.
Primes become sparser as numbers grow larger, but they never stop appearing โ a fact proven by Euclid around 300 BCE. The Prime Number Theorem, proved in 1896, states that the number of primes below n is approximately n/ln(n). Among numbers near 1,000, roughly 1 in 7 is prime. Near 1,000,000, about 1 in 14. Near 1,000,000,000, about 1 in 21. Despite this thinning, primes exhibit fascinating clustering: twin primes (pairs differing by 2, like 11-13, 17-19, 29-31) appear to continue forever, though this remains unproven โ the Twin Prime Conjecture is one of mathematics' great open problems. The largest known prime, discovered in 2024, has over 41 million digits โ found by the Great Internet Mersenne Prime Search (GIMPS), a distributed computing project that has identified the 15 largest known primes by testing numbers of the form 2^p - 1.
Prime numbers appear in unexpected places outside pure mathematics. Cicadas emerge on prime-numbered year cycles (13 or 17 years) โ biologists hypothesize this minimizes overlap with predator population cycles, since prime periods share few common multiples with shorter cycles. Hash tables in computer science use prime-sized arrays to distribute data more uniformly, reducing clustering that degrades performance. Digital signal processing uses prime-length sequences to design error-correcting codes and avoid harmonic interference. In music, consonant intervals correspond to frequency ratios of small integers (octave = 2:1, fifth = 3:2), while dissonant intervals involve larger primes โ a connection between number theory and acoustics that fascinated Pythagoras and continues to inform musical tuning systems. Even bar code systems and ISBN numbers use modular arithmetic with primes to create check digits that catch transcription errors.
Prime numbers โ integers greater than 1 divisible only by 1 and themselves โ are the atoms of arithmetic. The Fundamental Theorem of Arithmetic states that every integer greater than 1 can be expressed as a unique product of primes: 360 = 2ยณ ร 3ยฒ ร 5, and no other combination of primes produces 360. This uniqueness property underlies modern cryptography. RSA encryption, which secures online banking, email, and e-commerce, relies on the fact that multiplying two large primes is trivially easy (a computer can multiply two 300-digit primes in microseconds) but factoring the result back into its prime components is computationally infeasible โ current methods would take longer than the age of the universe for sufficiently large numbers. Your web browser uses this asymmetry every time you see the padlock icon on a secure website.
The simplest primality test: divide the candidate by every integer from 2 up to its square root. If none divide evenly, the number is prime. Why only up to the square root? Because if n = a ร b and both a and b were greater than โn, then a ร b > n โ a contradiction. For 97: โ97 โ 9.85, so test divisibility by 2, 3, 5, and 7 (primes up to 9). None divide 97 evenly, so 97 is prime. This method works for small numbers but becomes slow for large ones. Faster algorithms include the Miller-Rabin probabilistic test (used in practice โ it can declare a number "probably prime" with any desired level of certainty) and the AKS algorithm (the first proven polynomial-time deterministic test, published in 2002). For everyday use, trial division handles numbers up to about 10 million in under a second on modern hardware.
Primes become sparser as numbers grow larger, but they never stop appearing โ a fact proven by Euclid around 300 BCE. The Prime Number Theorem, proved in 1896, states that the number of primes below n is approximately n/ln(n). Among numbers near 1,000, roughly 1 in 7 is prime. Near 1,000,000, about 1 in 14. Near 1,000,000,000, about 1 in 21. Despite this thinning, primes exhibit fascinating clustering: twin primes (pairs differing by 2, like 11-13, 17-19, 29-31) appear to continue forever, though this remains unproven โ the Twin Prime Conjecture is one of mathematics' great open problems. The largest known prime, discovered in 2024, has over 41 million digits โ found by the Great Internet Mersenne Prime Search (GIMPS), a distributed computing project that has identified the 15 largest known primes by testing numbers of the form 2^p - 1.
Prime numbers appear in unexpected places outside pure mathematics. Cicadas emerge on prime-numbered year cycles (13 or 17 years) โ biologists hypothesize this minimizes overlap with predator population cycles, since prime periods share few common multiples with shorter cycles. Hash tables in computer science use prime-sized arrays to distribute data more uniformly, reducing clustering that degrades performance. Digital signal processing uses prime-length sequences to design error-correcting codes and avoid harmonic interference. In music, consonant intervals correspond to frequency ratios of small integers (octave = 2:1, fifth = 3:2), while dissonant intervals involve larger primes โ a connection between number theory and acoustics that fascinated Pythagoras and continues to inform musical tuning systems. Even bar code systems and ISBN numbers use modular arithmetic with primes to create check digits that catch transcription errors.
Prime numbers โ integers greater than 1 divisible only by 1 and themselves โ are the atoms of arithmetic. The Fundamental Theorem of Arithmetic states that every integer greater than 1 can be expressed as a unique product of primes: 360 = 2ยณ ร 3ยฒ ร 5, and no other combination of primes produces 360. This uniqueness property underlies modern cryptography. RSA encryption, which secures online banking, email, and e-commerce, relies on the fact that multiplying two large primes is trivially easy (a computer can multiply two 300-digit primes in microseconds) but factoring the result back into its prime components is computationally infeasible โ current methods would take longer than the age of the universe for sufficiently large numbers. Your web browser uses this asymmetry every time you see the padlock icon on a secure website.
The simplest primality test: divide the candidate by every integer from 2 up to its square root. If none divide evenly, the number is prime. Why only up to the square root? Because if n = a ร b and both a and b were greater than โn, then a ร b > n โ a contradiction. For 97: โ97 โ 9.85, so test divisibility by 2, 3, 5, and 7 (primes up to 9). None divide 97 evenly, so 97 is prime. This method works for small numbers but becomes slow for large ones. Faster algorithms include the Miller-Rabin probabilistic test (used in practice โ it can declare a number "probably prime" with any desired level of certainty) and the AKS algorithm (the first proven polynomial-time deterministic test, published in 2002). For everyday use, trial division handles numbers up to about 10 million in under a second on modern hardware.
Primes become sparser as numbers grow larger, but they never stop appearing โ a fact proven by Euclid around 300 BCE. The Prime Number Theorem, proved in 1896, states that the number of primes below n is approximately n/ln(n). Among numbers near 1,000, roughly 1 in 7 is prime. Near 1,000,000, about 1 in 14. Near 1,000,000,000, about 1 in 21. Despite this thinning, primes exhibit fascinating clustering: twin primes (pairs differing by 2, like 11-13, 17-19, 29-31) appear to continue forever, though this remains unproven โ the Twin Prime Conjecture is one of mathematics' great open problems. The largest known prime, discovered in 2024, has over 41 million digits โ found by the Great Internet Mersenne Prime Search (GIMPS), a distributed computing project that has identified the 15 largest known primes by testing numbers of the form 2^p - 1.
Prime numbers appear in unexpected places outside pure mathematics. Cicadas emerge on prime-numbered year cycles (13 or 17 years) โ biologists hypothesize this minimizes overlap with predator population cycles, since prime periods share few common multiples with shorter cycles. Hash tables in computer science use prime-sized arrays to distribute data more uniformly, reducing clustering that degrades performance. Digital signal processing uses prime-length sequences to design error-correcting codes and avoid harmonic interference. In music, consonant intervals correspond to frequency ratios of small integers (octave = 2:1, fifth = 3:2), while dissonant intervals involve larger primes โ a connection between number theory and acoustics that fascinated Pythagoras and continues to inform musical tuning systems. Even bar code systems and ISBN numbers use modular arithmetic with primes to create check digits that catch transcription errors.
โ 2 is the only even prime. All other evens divisible by 2.
โ Test up to โn only. Efficient primality check.
โ Primes get rarer. But there are infinitely many.
โ Twin primes. Pairs like (11,13), (17,19), (29,31).
See also: LCM/GCF ยท Exponent ยท Scientific