Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

Prime Numbers Calculator

How to use Prime Numbers Calculator
  1. Pick a mode with the four tabs across the top of the card: List first N, List a – b, Test a number or Lookup by index; the ? beside each tab describes it. Learn more about the modes
  2. In List first N, type how many terms to show in Show first and click Update; the cards give the count, the largest term and the sum, and the tiles list every term. Learn more about listing terms
  3. In List a – b, type the From index and the To index and click List range; a red box explains a bad range. Learn more about ranges
  4. In Test a number, type a positive integer in Test number and click Check; a green box names the index, a red box says it is not prime. Learn more about the test
  5. In Lookup by index, type the position in Index n and click Get term. Learn more about lookups
  6. The panel on the right explains the current mode and walks through the arithmetic with your own numbers; it changes with every tab and click. Learn more about the panel





Listing the First N Terms

DemoTen terms, thirty terms, the cap, one term
Step 0 of 4
The explorer opens on the List first N tab, one of four tabs across the top of the card; the small ? beside each tab shows what the mode does. Type how many terms you want in the Show first box and click Update or press Enter. Three cards answer at once: Showing gives the count, Largest the last term with its index, and Sum the total of the listed terms, the sum of the first NN primes. Under the cards every term is laid out as a tile with its index above its value, so p1=2p_1 = 2 to pNp_N can be read in order.

The box accepts 11 to 1,0001,000: 1010 gives p10=29p_{10} = 29 with the sum 129129, 3030 gives p30=113p_{30} = 113 with the sum 1,5931,593, and 1,1001,100 is capped at 1,0001,000 terms, ending at p1,000=7,919p_{1,000} = 7,919 with the sum 3,682,9133,682,913; a single term gives p1=2p_1 = 2. Large values are printed with thousands separators. A count of 0, a decimal or an empty box is refused with "Enter a positive integer." There is no Reset button: type a new count and click Update again. The panel on the right, List first N, states the rule the tiles come from, and its walkthrough repeats the last term and the sum with your own NN. What the terms are is explained in what is a prime number.

Listing a Range of Indexes

DemoThe range tab, a new range, two bad ranges
Step 0 of 4
Click the List a – b tab to list the terms between two positions instead of starting from 11. Type the From index and the To index and click List range or press Enter. The cards give the Count b−a+1b - a + 1, the Smallest term pap_a and the Largest term pbp_b, and the tiles below list every term in between with its index. The tab opens with 1010 to 3030, 21 terms from p10=29p_{10} = 29 to p30=113p_{30} = 113; indexes 4040 to 6060 give 21 terms from 173173 to 281281.

Both boxes must hold positive integers, the first no larger than the second, and the range may hold at most 1,0001,000 terms; otherwise a red box explains: "Enter two positive integer indexes", "From-index must be less than or equal to to-index", or "Range too wide — cap is 1,000 terms". The panel on the right, List a – b, explains the mode, and its walkthrough names the smallest and largest term of your range. The rule each tile uses is explained in the fundamental theorem of arithmetic.

Testing a Number

DemoThe test tab, a non-member, a member, 0
Step 0 of 4
Click the Test a number tab to ask whether a given positive integer is prime. Type it in the Test number box and click Check or press Enter. A green box with a tick answers yes and names the index, as for the opening value 9797, which is p25p_{25}; a red box with a cross answers no, as for 9191, and the walkthrough on the right then shows the two nearest prime numbers, p24=89p_{24} = 89 and p25=97p_{25} = 97. A large value is handled the same way: 7,9197,919 is p1000p_{1000}.

The box takes positive integers only; 00, a negative number or a decimal is refused with "Enter a positive integer". The test behind the answer is exact: the explorer looks the number up in its precomputed list of the first 1,0001{,}000 primes (up to 7,9197{,}919); a hit gives the index, a miss shows the two nearest primes, and a number above 7,9197{,}919 is reported as not prime. The panel on the right, Test a number, states this rule, and its walkthrough carries out the arithmetic for your number. The rule itself is explained in primality testing — how the explorer decides.

Looking Up a Term by Index

DemoThe lookup tab, two indexes, n = 0
Step 0 of 4
Click the Lookup by index tab to compute one term directly. Type the position in the Index n box and click Get term or press Enter. Two cards answer: Index repeats nn and Value gives pnp_n with its index as a subscript. The tab opens with n=100n = 100, which gives p100=541p_{100} = 541; n=500n = 500 gives 3,5713,571 and n=1000n = 1000 gives 7,9197,919. The box takes positive integers only; 00 is refused with "Enter a positive integer index".

The panel on the right has two parts in every mode. How it works names the rule the mode uses, here pnp_n, the nn-th prime, and links to the section of this page that explains it; Walkthrough applies the rule to the numbers you typed, so for the lookup it shows the arithmetic with your nn filled in. Both change as soon as you switch tabs or click a button. The rule and where it comes from are in the fundamental theorem of arithmetic.

What is a Prime Number?

A prime number is a positive integer greater than 1 whose only positive divisors are 1 and itself. The first few primes:

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,…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, \ldots


Why 1 is not prime. The convention excludes 1 to make the fundamental theorem of arithmetic clean: every integer >1> 1 factors uniquely into primes. If 1 were prime, 6=2⋅3=1⋅2⋅3=1⋅1⋅2⋅36 = 2 \cdot 3 = 1 \cdot 2 \cdot 3 = 1 \cdot 1 \cdot 2 \cdot 3 would have multiple representations.

Why 2 is the only even prime. Every other even number is divisible by 2, so cannot be prime. Both being even and being greater than 2 implies non-prime.

Composite numbers. Integers >1> 1 that are not prime are composite. Examples: 4=2⋅24 = 2 \cdot 2, 6=2⋅36 = 2 \cdot 3, 8=238 = 2^3, 9=329 = 3^2, 10=2⋅510 = 2 \cdot 5.

Scope of this explorer. This tool uses a precomputed list of the first 10,000 primes, with maximum value 104,729 (the 10,000th prime). Lookups and membership tests within this range are constant-time. For larger numbers, dedicated primality-testing tools are needed.

For deeper coverage see prime number, fundamental theorem of arithmetic, and primality test.

The definition is given in definition and in prime numbers; the sequence is placed among the others in prime numbers.

Unique factorisation is the subject of prime factorization.

Trial division and its alternatives are compared in primality testing; the sieve is the sieve of Eratosthenes.

The thinning of the primes is stated in the prime number theorem.

Why the primes never run out is proved in infinitude of primes; the named families are in types of primes.

The Fundamental Theorem of Arithmetic

Statement. Every integer greater than 1 either is prime or can be written uniquely (up to ordering) as a product of primes.

For example:

12=22⋅3,100=22⋅52,420=22⋅3⋅5⋅7,1000000=26⋅5612 = 2^2 \cdot 3, \quad 100 = 2^2 \cdot 5^2, \quad 420 = 2^2 \cdot 3 \cdot 5 \cdot 7, \quad 1000000 = 2^6 \cdot 5^6


Why uniqueness matters. Unique factorization is what makes primes "atoms" of arithmetic. The integers have a structure as a unique factorization domain — properties like greatest common divisor, least common multiple, modular arithmetic, and modular inverses all rest on this structure.

Why it's a theorem, not a definition. It's not obvious that factorization is unique. Consider analogous systems where it fails: in Z[−5]\mathbb{Z}[\sqrt{-5}], we have 6=2⋅3=(1+−5)(1−−5)6 = 2 \cdot 3 = (1 + \sqrt{-5})(1 - \sqrt{-5}) — two different factorizations into irreducibles. The integers Z\mathbb{Z} have unique factorization; this is a deep property requiring proof.

Proof sketch. Standard proofs use the Euclidean algorithm: if a prime pp divides a product abab, then pp divides aa or pp divides bb. This "prime property" plus induction gives unique factorization.

Practical consequence. All number-theoretic algorithms (GCD computation, modular inverse, RSA, primality testing) rest on the structure that the fundamental theorem provides. Disrupt unique factorization and most of cryptography breaks down.

Primality Testing — How the Explorer Decides

This explorer uses a precomputed list of the first 10,000 primes (up to 104,729). Three modes interact with the list:

• Browse the first NN primes — direct array access, O(N)O(N) time.
• List a range — direct slice, O(b−a)O(b - a) time.
• Membership test — hash-set lookup, O(1)O(1) time.
• nn-th prime lookup — direct array access, O(1)O(1) time.

Out-of-range behavior. For inputs m>104,729m > 104{,}729, the explorer reports the value as out of range rather than guessing. To test primality of larger numbers, use dedicated primality-testing tools or libraries.

Why precomputed. Storing the first 10,000 primes costs only a few kilobytes of memory and gives constant-time answers for the common range of educational and recreational queries. Naive trial division for m≈105m \approx 10^5 would require dozens of divisions per query — not slow, but slower than a lookup.

General-case primality tests (for context, not used here):

• Trial division: divide mm by all primes up to m\sqrt{m}. Slow but exact. Practical up to ∼1012\sim 10^{12}.
• Miller-Rabin: probabilistic test, fast and very reliable. Practical for thousands of digits.
• AKS primality test: deterministic polynomial-time test (2002). Theoretically important but slower than Miller-Rabin in practice.
• Lucas-Lehmer: specialized test for Mersenne primes (2p−12^p - 1). Used by GIMPS to find the largest known primes.

The largest known prime (as of recent record): 282,589,933−12^{82,589,933} - 1, a Mersenne prime with over 24 million digits. Found via GIMPS in 2018.

The Prime Counting Function and Distribution

Let π(x)\pi(x) denote the number of primes less than or equal to xx. Examples:

π(10)=4,π(100)=25,π(1000)=168,π(10000)=1229,π(100000)=9592\pi(10) = 4, \quad \pi(100) = 25, \quad \pi(1000) = 168, \quad \pi(10000) = 1229, \quad \pi(100000) = 9592


The prime number theorem (PNT). π(x)∼xln⁡x\pi(x) \sim \dfrac{x}{\ln x} as x→∞x \to \infty.

Equivalently, the density of primes near xx is approximately 1/ln⁡x1/\ln x. So:

• Near x=1000x = 1000, about 1 in 7 numbers is prime.
• Near x=106x = 10^6, about 1 in 14 numbers is prime.
• Near x=10100x = 10^{100}, about 1 in 230 numbers is prime.

Primes become sparser as numbers grow, but never disappear (Euclid's theorem).

Better approximations. The logarithmic integral Li(x)=∫2xdt/ln⁡t\text{Li}(x) = \int_2^x dt/\ln t approximates π(x)\pi(x) more accurately than x/ln⁡xx / \ln x. For x=1015x = 10^{15}, Li(x)\text{Li}(x) matches π(x)\pi(x) to within about 10710^7 (out of ∼3⋅1013\sim 3 \cdot 10^{13} primes).

The Riemann hypothesis. The conjecture that all non-trivial zeros of the Riemann zeta function ζ(s)\zeta(s) lie on the line Re(s)=1/2\text{Re}(s) = 1/2 would give very precise error bounds on π(x)−Li(x)\pi(x) - \text{Li}(x), namely O(xln⁡x)O(\sqrt{x} \ln x). This is the most famous open problem in mathematics.

Inverse: the nn-th prime. pn∼nln⁡np_n \sim n \ln n. Examples: p100=541≈100⋅ln⁡100=460p_{100} = 541 \approx 100 \cdot \ln 100 = 460; p1000=7919≈1000⋅ln⁡1000=6908p_{1000} = 7919 \approx 1000 \cdot \ln 1000 = 6908. The approximation improves for large nn and can be refined using pn≈n(ln⁡n+ln⁡ln⁡n−1)p_n \approx n(\ln n + \ln \ln n - 1).

Famous Conjectures and Open Problems

Despite their elementary definition, primes harbor some of the deepest open problems in mathematics.

Twin prime conjecture. Twin primes are pairs (p,p+2)(p, p + 2) both prime: (3,5),(5,7),(11,13),(17,19),(29,31),…(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), \ldots. Open question: are there infinitely many twin primes? Likely yes; proof remains elusive. The Polymath project and Yitang Zhang's 2013 breakthrough proved infinitely many primes differ by at most some bounded amount; the bound has been reduced to 246 (and conditionally to 6 under stronger hypotheses).

Goldbach conjecture. Every even integer greater than 2 is a sum of two primes. Verified computationally up to 4⋅10184 \cdot 10^{18}; no proof. Examples: 4=2+24 = 2 + 2, 6=3+36 = 3 + 3, 8=3+58 = 3 + 5, 10=3+7=5+510 = 3 + 7 = 5 + 5, 100=3+97=11+89=…100 = 3 + 97 = 11 + 89 = \ldots.

Riemann hypothesis. All non-trivial zeros of ζ(s)\zeta(s) have real part 1/21/2. Equivalent to precise error bounds on the distribution of primes. One of the Millennium Prize Problems (\1$ million for a proof).

Mersenne primes. Primes of the form 2p−12^p - 1 where pp is prime: 3,7,31,127,8191,…3, 7, 31, 127, 8191, \ldots. Open: are there infinitely many? GIMPS finds new ones occasionally; only 51 known.

Fermat primes. Primes of the form 22n+12^{2^n} + 1: 3,5,17,257,655373, 5, 17, 257, 65537. Only these five known; conjectured to be the only ones.

Sophie Germain primes. Primes pp such that 2p+12p + 1 is also prime. 2,3,5,11,23,29,41,…2, 3, 5, 11, 23, 29, 41, \ldots. Open: infinitely many?

Bertrand's postulate (proved): for every n≥1n \geq 1, there is a prime pp with n<p<2nn < p < 2n. Erdős gave an elegant proof at age 19.

Green-Tao theorem (2004): the primes contain arbitrarily long arithmetic progressions. A landmark result with surprising structural depth.

Primes in Cryptography

Primes are the foundation of modern public-key cryptography. Two prominent schemes:

RSA encryption. A user picks two large primes pp and qq (each typically 1024 bits). Their product N=pqN = p q is the public modulus. The security of RSA rests on the difficulty of factoring NN back into pp and qq when only NN is given.

• Encryption: given a message mm and a public key (N,e)(N, e), compute c=me mod Nc = m^e \bmod N.
• Decryption: with the private key dd (derived from ϕ(N)=(p−1)(q−1)\phi(N) = (p - 1)(q - 1)), compute m=cd mod Nm = c^d \bmod N.

Breaking RSA is equivalent to factoring large semi-primes. The best classical algorithms (general number field sieve) are sub-exponential; quantum computers running Shor's algorithm could factor in polynomial time, motivating post-quantum cryptography.

Diffie-Hellman key exchange. Uses a large prime pp and a generator gg of the multiplicative group modulo pp. Two parties exchange ga mod pg^a \bmod p and gb mod pg^b \bmod p publicly; both can compute the shared secret gab mod pg^{ab} \bmod p but an eavesdropper cannot (under the discrete log assumption).

Why primality matters. Both schemes require generating large primes quickly. Probabilistic primality tests (Miller-Rabin) verify candidate primes in milliseconds; the prime number theorem says about 1 in ln⁡(N)≈1000\ln(N) \approx 1000 random 1000-bit numbers is prime, so a few thousand candidates produce a usable prime.

Why primality is necessary. The mathematical structure (cyclic groups, modular inverses, Fermat's little theorem) requires primes or carefully chosen prime-related moduli. Replacing pp with a composite breaks the algorithms in subtle but devastating ways.

Post-quantum cryptography. Lattice-based, code-based, and hash-based schemes aim to replace RSA and Diffie-Hellman without relying on factoring or discrete logs. Active area of standardization (NIST).

The factorisation the ciphers rely on is prime factorization.

Common Mistakes

• Calling 1 a prime. By modern convention, 1 is neither prime nor composite. Historical mathematicians sometimes called it prime, but the convention shifted in the 19th-20th century for clarity of unique factorization.

• Calling 2 not prime because it's even. 2 is the unique even prime. Its evenness is a quirk, not a disqualifier.

• Thinking primes thin out predictably. While density decreases (∼1/ln⁡x\sim 1/\ln x), the distribution is irregular: prime gaps can be small (twin primes) or large (gaps growing as log⁡pn\log p_n on average, but with occasional very large gaps).

• Conflating prime with irreducible. In the integers Z\mathbb{Z}, prime and irreducible are equivalent. In more general algebraic settings, they can differ. Always specify "in Z\mathbb{Z}" when needed.

• Over-trusting trial division for large numbers. Trial division up to N\sqrt{N} is exact but slow for NN above ∼1012\sim 10^{12}. Use Miller-Rabin or AKS for larger inputs.

• Forgetting Wilson's theorem subtleties. (p−1)!≡−1(modp)(p - 1)! \equiv -1 \pmod p for prime pp is a beautiful characterization but impractical as a primality test (the factorial grows too fast).

• Misremembering Goldbach. Goldbach's conjecture is about even integers, not all integers. The corresponding statement for odd integers — every odd ≥7\geq 7 is a sum of three primes — was settled (Helfgott 2013, building on Vinogradov).

• Mersenne-Fermat prime confusion. Mersenne: 2p−12^p - 1. Fermat: 22n+12^{2^n} + 1. Different forms, different open problems.

Index conventions are explained in definition and notation; what counts as prime is settled in definition.