Prime Number Generator | First 1000 Primes

Generate prime lists and explain why a short divisibility test can settle a single candidate.

Quick Answer

The actual nth prime must be calculated or bounded more carefully, but the approximation is useful when building a generator because it helps estimate how far the sieve must go in order to collect the first n primes.

A number grid with counters marking prime candidates

Prime Number Generator

Generate the first 1000 prime numbers, list primes up to a limit, find primes in a range, check whether a number is prime, calculate the nth prime, and export prime lists instantly. Built for students, teachers, math practice, coding projects, and number theory learning.

First 1000 primes Primes up to limit Range generator Prime checker Nth prime finder Random prime Copy CSV Download list MathJax formulas

1. Choose Prime Tool

Enter an integer of up to 1000 digits. Below 2^64 (18,446,744,073,709,551,616), the selected Miller–Rabin bases give an exact result. At or above 2^64, a passing result means probable prime, not a proof.

N: 1–350,000. Limits and range endpoints: up to 5,000,000; range start must not exceed range end. Use digits or correctly grouped thousands commas; decimals and exponent notation are not accepted.

2. Prime Results

Default output First 1000 prime numbers

Click Generate to refresh the prime list, change the mode, or export the result.

Prime Count 1000
First Prime 2
Last Prime 7919
Largest Gap 34
\[ p \text{ is prime if } p>1 \text{ and its only positive divisors are } 1 \text{ and } p. \]

Generated Prime Numbers

The first 1000 prime numbers are generated by default because this page is designed for quick access to the first 1000 primes online. You can change the tool mode to generate primes up to a limit, inside a range, or find a specific nth prime. Use the multiplication and factor examples to check factors by multiplying them back together.

Prime Number Generator Diagram

The diagram below shows the core idea behind the Sieve of Eratosthenes. Instead of testing every number separately from scratch, the sieve marks multiples of each prime. When the algorithm reaches a number that has not been marked composite, that number is prime.

On a small screen, scroll the diagram sideways to read each step.

Sieve of Eratosthenes: Prime Generation Flow Start with 2, 3, 4, 5, ... n Pick next unmarked prime p Cross out p², p²+p, p²+2p 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Unmarked numbers after sieving are prime: 2, 3, 5, 7, 11, 13, ...

Prime Number Definition and Formulas

A prime number is a whole number greater than 1 that has exactly two positive divisors: 1 and itself. The smallest prime number is 2. It is also the only even prime number, because every even number greater than 2 is divisible by 2 and therefore has more than two divisors.

\[ p \text{ is prime } \Longleftrightarrow p>1 \text{ and } \operatorname{Divisors}(p)=\{1,p\} \]

A composite number is a whole number greater than 1 that is not prime. For example, \(12\) is composite because \(12=2\times6=3\times4\). The number \(1\) is neither prime nor composite. This distinction matters because prime factorization depends on primes as building blocks, while 1 does not add new factor structure.

\[ n \text{ is composite if } n=ab \text{ for integers } a,b \text{ where } 1<a<n \text{ and } 1<b<n. \]

One of the most useful prime-testing ideas is the square-root rule. If a number \(n\) is composite, it must have at least one factor less than or equal to \(\sqrt{n}\). This means you do not need to check every possible divisor up to \(n-1\). You only need to check possible divisors up to \(\sqrt{n}\).

\[ n=ab,\quad a\le b \quad\Rightarrow\quad a\le \sqrt{n} \]

The Sieve of Eratosthenes is efficient for generating many primes. Instead of checking each number by trial division, it starts with a list of integers and repeatedly marks multiples of known primes. The crossing-out process can begin at \(p^2\), because smaller multiples of \(p\) have already been handled by smaller primes.

\[ p^2,\quad p^2+p,\quad p^2+2p,\quad p^2+3p,\ldots \]

The prime counting function \(\pi(x)\) counts how many primes are less than or equal to \(x\). For example, \(\pi(10)=4\), because the primes up to 10 are \(2,3,5,7\). The prime number theorem gives an important long-term approximation:

\[ \pi(x)\sim \frac{x}{\ln x} \]

This approximation does not mean that primes appear in a perfectly regular pattern. Prime gaps can vary, and primes become less dense as numbers grow larger. However, the formula gives a powerful estimate of how many primes are expected up to a large value. Use the why 1 is not a prime number to see how including 1 would affect the uniqueness of prime factorization.

\[ p_n \sim n\ln(n) \]

The formula above estimates the size of the nth prime. The actual nth prime must be calculated or bounded more carefully, but the approximation is useful when building a generator because it helps estimate how far the sieve must go in order to collect the first \(n\) primes.

Complete Guide to Prime Numbers

Prime numbers are one of the most important ideas in mathematics because they act like the atoms of whole numbers. Every whole number greater than 1 can be written as a product of prime numbers in exactly one way, apart from the order of the factors. This result is called the Fundamental Theorem of Arithmetic. For example, \(84=2^2\times3\times7\). You could write the factors in another order, such as \(7\times3\times2^2\), but the prime ingredients are the same. This is why prime numbers appear throughout algebra, number theory, cryptography, coding, modular arithmetic, divisibility, fractions, least common multiples, greatest common divisors, and mathematical proofs.

The Prime Number Generator on this page is built for a practical purpose: you can instantly create prime lists without manually checking each number. The default setting generates the first 1000 primes, because many students and teachers need a clean first-1000 prime list for worksheets, mental math drills, coding practice, and classroom reference. The 1000th prime is 7919, so the default list ends at 7919. You can also switch to generating all primes up to a limit, generating primes in a range, checking one number, finding the nth prime, or selecting a random prime from a range.

A useful way to understand primes is to compare them with composite numbers. The numbers \(2,3,5,7,11,13\) are prime because each has only two positive divisors. The numbers \(4,6,8,9,10,12\) are composite because each can be split into smaller whole-number factors. The number 2 is prime because its only positive divisors are 1 and 2. The number 9 is not prime because its positive divisors are 1, 3, and 9. The number 15 is not prime because \(15=3\times5\). The number 1 is a special case: it has only one positive divisor, so it is not prime.

Prime numbers are infinite. Euclid’s classic argument is one of the clearest proofs in all of mathematics. Suppose there were only finitely many primes: \(p_1,p_2,p_3,\ldots,p_k\). Multiply them all together and add 1:

\[ N=p_1p_2p_3\cdots p_k+1 \]

If you divide \(N\) by any prime in the list, the remainder is 1. Therefore, none of the primes in the assumed complete list divides \(N\). That means either \(N\) is prime, or \(N\) has a prime divisor not in the original list. Either way, the original list was not complete. So there must be infinitely many prime numbers.

The Sieve of Eratosthenes is the most classroom-friendly algorithm for generating primes. It is also strong enough for fast browser-based prime generation up to reasonably large limits. The process begins with all integers from 2 up to a chosen limit. The first unmarked number is 2, so 2 is prime. Then every multiple of 2 greater than 2 is marked composite. The next unmarked number is 3, so 3 is prime. Then every multiple of 3 greater than 3 is marked composite. The next unmarked number is 5, and the same process continues.

A key optimization is to begin marking multiples of \(p\) at \(p^2\), not at \(2p\). For example, when \(p=5\), the multiples \(10,15,\) and \(20\) have already been marked by 2 or 3. The first new composite number that must be marked by 5 is \(25\). This is why the sieve is faster than repeated trial division for bulk prime lists.

\[ \text{Mark composites from }p^2\text{ to }n\text{ in steps of }p. \]

Trial division is still useful when checking a single small or medium-sized number. To decide whether \(n\) is prime, first reject values less than 2, then handle 2 and 3, then test divisibility by possible factors up to \(\sqrt{n}\). Since every composite number has a factor no larger than its square root, this approach is exact. It is easy to understand and works well for educational examples.

For larger integers, modern primality testing often uses faster methods such as Miller-Rabin. In many practical cases, Miller-Rabin is used as a probable-prime test. It does not work by trial dividing up to the square root. Instead, it uses modular exponentiation and properties that prime numbers must satisfy. This page includes a large-number checker for convenience, but the main prime list generator uses the sieve because the sieve is the correct tool when generating many primes in a row.

Primes are central in modular arithmetic. In modular arithmetic, numbers wrap around after reaching a modulus. For example, in modulo 7 arithmetic, \(9\equiv2\pmod7\). When the modulus is prime, many arithmetic properties become cleaner. Every nonzero residue modulo a prime has a multiplicative inverse. This is one reason primes are important in algebra, coding theory, and cryptography.

\[ a^{p-1}\equiv1\pmod p \quad\text{when }p\text{ is prime and }p\nmid a \]

The formula above is Fermat’s little theorem. It is not the same as a complete prime definition, but it gives a powerful test-like property. If a number behaves incorrectly under this modular relationship, it cannot be prime. Some composite numbers can still pass certain versions of Fermat-style tests, so robust primality testing needs extra care.

Prime numbers also help simplify fractions. To reduce a fraction, you can factor the numerator and denominator and cancel common prime factors. For example:

\[ \frac{84}{126} = \frac{2^2\cdot3\cdot7}{2\cdot3^2\cdot7} = \frac{2}{3} \]

The same prime factorization idea helps calculate greatest common divisors and least common multiples. If two numbers are written in prime-power form, the GCD uses the smaller exponent of each shared prime, while the LCM uses the larger exponent of each prime that appears. In the formulas below, a and b are positive integers, and missing prime factors have exponent 0. Use the place value, primes and factors lessons to practise how factors and multiples describe different relationships.

\[ \gcd(a,b)=\prod p_i^{\min(\alpha_i,\beta_i)} \qquad \operatorname{lcm}(a,b)=\prod p_i^{\max(\alpha_i,\beta_i)} \]

In school mathematics, primes usually appear first in divisibility lessons. Students learn that numbers ending in 0, 2, 4, 6, or 8 are divisible by 2; numbers whose digit sum is divisible by 3 are divisible by 3; numbers ending in 0 or 5 are divisible by 5; and a number is divisible by 11 exactly when its alternating sum of digits is divisible by 11 (including 0). These tests are useful for quickly rejecting composite numbers before using a formal method.

Prime gaps are another interesting topic. A prime gap is the difference between consecutive primes. For example, the gap between 3 and 5 is 2, the gap between 7 and 11 is 4, and the gap between 89 and 97 is 8. Prime gaps tend to become larger on average as numbers increase, but they are not perfectly predictable. The tool above calculates the largest gap inside your generated list so you can observe this behavior.

Twin primes are pairs of primes that differ by 2, such as \((3,5)\), \((5,7)\), \((11,13)\), and \((17,19)\). Many deep questions about primes remain open in mathematics, including whether infinitely many twin primes exist. This tool is not designed to solve open research problems, but it makes it easy to observe patterns and generate examples.

The prime number theorem explains the broad density of primes. It says that the number of primes up to \(x\) is approximately \(x/\ln x\). This does not predict the exact location of the next prime, but it gives a strong long-range estimate. For example, primes are common among smaller numbers and gradually become sparser among larger numbers. This is why generating the first million primes requires going much farther than one million.

If you are using this page for coding practice, the prime generator is a strong project because it combines algorithm design, loops, arrays, boolean marking, optimization, formatting, and user interface decisions. A beginner can start with trial division. An intermediate developer can implement the sieve. An advanced developer can compare segmented sieves, wheel factorization, probabilistic primality tests, and memory-efficient bitsets.

If you are using this page for math teaching, you can ask students to generate the first 100 primes, highlight twin primes, identify prime gaps, compare primes up to 100 with primes up to 1000, or explain why every even number greater than 2 is composite. You can also use the range mode to investigate whether primes are evenly spread. Students quickly see that primes are structured enough to study but irregular enough to remain fascinating.

If you are using this page for cryptography background, remember that real cryptographic prime generation is more specialized than classroom prime generation. Cryptographic systems require carefully generated large primes, secure random number generation, strong primality tests, and protection against implementation attacks. This educational tool is for learning, reference, lists, and practice; it should not be used as the only method for generating production cryptographic keys.

The first 1000 primes are useful because they cover many common classroom and programming needs. They are small enough to inspect visually, but large enough to use for hashing exercises, modular arithmetic experiments, factorization practice, divisibility drills, and algorithm testing. Since the list ends at 7919, students can see that prime density decreases: there are 1000 primes within the first 7919 positive integers, not within the first 1000 integers.

This page also includes export tools. The copy button requests clipboard access and offers manual copying if blocked, while the download button saves it as a CSV file. This makes the calculator useful for worksheets, spreadsheets, classroom handouts, coding data, and math reference tables. The display option lets you choose a grid, plain text, or a table view depending on how you want to read or reuse the result.

How to Use the Prime Number Generator

  1. Select a mode. Choose first N primes, primes up to a limit, primes in a range, prime checker, nth prime, or random prime.
  2. Enter your values. Use \(N=1000\) for the first 1000 primes, a limit such as 10000, or a start and end range.
  3. Choose output style. Select grid, text/CSV, or table. You can also show or hide prime indexes.
  4. Click Generate. The calculator creates the result, summary cards, and formula explanation.
  5. Copy or download. Use the copy and CSV buttons to reuse the prime list in worksheets, spreadsheets, or coding projects.
Tool Mode Best Use Case Example Output
First N primes Get a fixed number of primes from the beginning of the prime sequence. First 1000 primes 2, 3, 5, 7, ... , 7919
Primes up to a limit Find all prime numbers less than or equal to a maximum value. Primes up to 10000 All primes \(\le 10000\)
Primes in a range Explore prime distribution between two values. Primes from 500 to 1000 Prime list inside the interval
Prime checker Test whether one integer is prime, composite, or neither. Check 7919 Prime / composite result
Nth prime Find a specific prime position. 1000th prime \(p_{1000}=7919\)
Random prime Generate a random prime for exercises, games, and practice. Random prime from 1000 to 9999 One random prime in the range

Course, Exam, and Score Note

This Prime Number Generator is a mathematics learning and calculation tool, not an official exam score calculator. Therefore, there is no universal score table, score boundary, or next exam timetable attached to this page. It can support arithmetic, pre-algebra, algebra, number theory, coding, AP/IB/GCSE/IGCSE math practice, and teacher worksheet creation, but official exam dates and scoring rules must always come from the relevant exam board, school, or course provider.
Requested Item Status for This Tool Correct Guidance
Score guidelines Not applicable This page generates and analyzes prime numbers. It does not calculate an official scaled score.
Score table Not applicable There is no single score table for prime number generation.
Next exam timetable Not applicable Check the official exam board or school calendar for course-specific exam dates.
Course relevance Highly relevant Useful for arithmetic, algebra, number theory, discrete mathematics, coding, and cryptography introductions.

Prime Number FAQ

What is a prime number?

A prime number is a whole number greater than 1 with exactly two positive divisors: 1 and itself. Examples include \(2,3,5,7,11,13,17,19\).

Is 1 a prime number?

No. The number 1 is not prime because it has only one positive divisor. A prime number must have exactly two positive divisors.

What is the first prime number?

The first prime number is \(2\). It is also the only even prime number.

What is the 1000th prime number?

The 1000th prime number is \(7919\). This calculator generates the first 1000 prime numbers by default.

How does the Sieve of Eratosthenes work?

The sieve lists numbers from 2 to a chosen limit, then marks multiples of each prime as composite. The numbers that remain unmarked are prime.

Can I download the generated prime numbers?

Yes. Use the Download CSV button to save the generated prime list as a CSV file. You can also use the Copy Result button to copy the list to your clipboard.

Can I use this tool for cryptographic prime generation?

This page is an educational prime number generator. It is useful for learning, worksheets, and coding practice, but it should not be used as the only method for production cryptographic key generation.

Sources

The checker uses the seven-base Miller–Rabin result for integers below 2^64. Beyond that boundary, passing the selected bases is only evidence of probable primality, not a proof.

Advertisement

Decide whether ninety-seven is prime

The square root of ninety-seven lies between nine and ten. Any composite factorization would therefore have a prime factor no larger than nine. Test two, three, five and seven. Ninety-seven is odd, its digits sum to sixteen, its final digit is neither zero nor five, and seven times thirteen is ninety-one while seven times fourteen is ninety-eight. None of those primes divides it, so ninety-seven is prime. The square-root bound explains why the test can stop there.

Applying Divisibility Rules

Before we begin our investigation of divisibility, we need to know some facts about important sets of numbers:
  • The counting numbers are referred to as the natural numbers. This set of numbers, {1,2,3,4,…}, is denoted with the symbol ℕ.
  • Another important set of numbers is the integers. The integers are the natural numbers, along with 0, and the negatives of the natural numbers. This set is often written as {…,−3,−2,−1,0,1,2,3,…}. We denote the integers with the symbol ℤ.
  • Notice that ℕ is a proper subset of ℤ, or, ℕ ⊂ ℤ. All the ideas of this section apply to the natural numbers, while only some apply to all the integers.
Divisibility is when the integer n is divisible by m, if n can be written as m times another integer. Equivalently, there is no remainder when n is divided by m. There are many occasions when separating items into equal groups comes into play to ensure an equal distribution of whole items. For example, Francis, a preschool art teacher, has 15 students in one class. Francis has 225 sheets of construction paper and wants to provide each student with an equal number of pieces. To know if he will use all the construction paper, Francis is really asking if 225 can be evenly divided into 15 groups.

Determining if a Number Divides Another Number

Determine if 36 is divisible by 4.
Solution
We could divide 36 by 4 and see if there is a remainder, or we could see if we can write 36 as 4 times another integer. If we divide 36 by 4, we see 36÷4=9 with no remainder. We see that 36 is divisible by 4. We can write 36 as 4 times another integer, 36=4×9. By the definition of divisibility, 36 is divisible by 4.
You can quickly check if a number is divisible by 2, 3, 4, 5, 6, 9, 10, and 12. Each has an easy-to-identify feature, or rule, that indicates the divisibility by those numbers, as shown in the following table.
Divisor Rule
2 Last digit is even
3 Add the digits of the number together. If that sum is divisible by 3, then so is the original number
4 Look at only the last two digits. If this number is divisible by 4, so is the original number
5 Look at only the last digit. If it is a 5 or a 0, then the original number is divisible by 5
6 If the number passes the rule for divisibility by 2 and for 3, then the number is divisible by 6
9 Add the digits of the number together. If that number is divisible by 9, then so is the original number
10 Look at only the last digit. If it is a 0, then the original number is divisible by 10
12 If the number passes the rule for 3 and 4, the number is divisible by 12

Using Divisibility Rules

Using divisibility rules, determine if 245 is divisible by 5.
Solution
Since the last digit is a 5, the number 245 is divisible by 5 because the rule states if the last digit of the number is a 5 or a 0, then the original number is divisible by 5.

Using Divisibility Rules

Using divisibility rules, determine if 25,983 is divisible by 9.
Solution
The divisibility rule for 9 is when the digits of the number are added, the sum is divisible by 9. So, we calculate the sum of the digits.
2+5+9+8+3=27. Since 27 is divisible by 9, so is the original number 25,983.

Using Divisibility Rules

Can 298 coins be stacked into 6 stacks with an equal number of coins in each stack?
Solution
In order for the coins to be in equal-sized stacks, 298 would need to be divisible by 6. The divisibility rule for 6 is that the number passes the divisibility rules for both 2 and 3. Since the last digit is even, 298 is divisible by 2. To determine if 298 is divisible by 3, we first add the digits of the number: 2+9+8=19. Since 19 is not divisible by 3, neither is 298. Because 298 is not divisible by 3, it is also not divisible by 6, which means they cannot be put into 6 equal stacks of coins.

Using Divisibility Rules

Using divisibility rules, determine if 4,259 is divisible by 10.
Solution
The divisibility rule for 10 is that the last digit of the number is 0. Since the last digit of 4,259 is not 0, then 4,259 is not divisible by 10.

Using Divisibility Rules

Using divisibility rules, determine if 936,276 is divisible by 4.
Solution
The divisibility rule for 4 is to check the last two digits of the number. If the number formed by the last two digits of the original number is divisible by 4, then so is the original number. The last two digits make the number 76 and 76 is divisible by 4, since 76=4×19. Since 76 is divisible by 4, so is 936,276.

Prime and Composite Numbers

Sometimes, a natural number has only two unique divisors, 1 and itself. For instance, 7 and 19 are prime. In other words, there is no way to divide a prime number into groups with an equal number of things, unless there is only one group, or those groups have one item per group. Other natural numbers have more than two unique divisors, such as 4, or 26. These numbers are called composite. The number 1 is special; it is neither prime nor composite.
To determine if a number is prime or composite, you have to determine if the number has any divisors other than 1 and itself. The divisibility rules are useful here, and can quickly show you if a number has a divisor on that list.
However, if none of those divide the number, you still have to check all other possible prime divisors. What are the prime numbers that are possibly divisors of the number you are checking? You need only check the prime numbers up to the square root of the number in question. For instance, if you want to know if 2,117 is prime, you need to determine if any primes up to the square root of 2,117 (which is 46.0 when rounded to one decimal place) divide 2,117. If any of those primes are divisors of the number in question, then the number is composite. If none of those primes work, then the number is itself prime.
We can check divisibility with whatever tool we wish. Divisibility rules are quick for some prime divisors (2 and 5 come to mind) but aren't quick for other values (like 11). In place of divisibility rules, we could just use a calculator. If the prime number divides the number evenly (that is, there is no decimal or fractional part), then the number is divisible by that prime. table is a quick list of the prime numbers up to 50. There are 15 prime numbers less than 50.
Prime Numbers Less than 50
2 3 5 7 11
13 17 19 23 29
31 37 41 43 47

Determining If a Number Is Prime or Composite

Determine if 2,117 is prime or composite.
Solution
The square root of 2,117 is 46.0 (rounded to one decimal place). So, we need to check if 2,117 is divisible by any prime up to 46.
Step 1: First we’ll use the rules of divisibility we learned earlier:
  • We can tell 2,117 is not divisible by 2, as the last digit isn't even.
  • 2,117 is not divisible by 5 (the last digit isn't 0 or 5).
  • Add the digits of 2,117 to get 11, which is not divisible by 3. So, 2,117 is also not divisible by 3.
Step 2: Now we repeat the process for all the primes up to 46.
Using a calculator, we find that 2,117 divided by the prime numbers 7, 11, 13, 17, 19, and 23 results in a remainder, a decimal part. So, we know that 2,117 is not divisible by these prime numbers. (You should check these results yourself.)
Moving on, we check the next prime: 29. Using the calculator to divide 2,117 by 29 results in 73. Since there is no decimal part, 2,117 is divisible by 29.
This means that 2,117 is not a prime number, but rather, a composite number. Writing 2,117 as the product of 29 and another natural number, 2,117=29×73.

Determining if a Number Is Prime or Composite

Determine if 423 is prime or composite.
Solution
The square root of 423 is 20.57 (rounded to two decimal places). So, we need to check if 423 is divisible by any prime up to 20.
Step 1: Check 2. We can tell 423 is not divisible by 2, as the last digit isn't even.
Step 2: Check 5. It is not divisible by 5 (the last digit isn't 0 or 5).
Step 3: Check 3. To check if 423 is divisible by 3, we use the divisibility rule for 3. When we take the sum of the digits of 423, the result is 9. Since 9 is divisible by 3, so is 423.
Since 423 is divisible by 3, then 423 is a composite number. Writing 423 as the product of 3 and another natural number, 423=3×141.

Determining if a Number Is Prime or Composite

Determine if 1,034 is prime or composite
Solution
A quick inspection of 1,034 shows it is divisible by 2 since the last digit is even, and so 1,034 is a composite number.

Determining if a Number Is Prime or Composite

Determine if 2,917 is prime or composite.
Solution
The square root of 2,917 is 50.01 (rounded to two decimal places). So, we need to check if 2,917 is divisible by any prime up to 50.
Step 1: Check 2. We can tell 2,917 is not divisible by 2, as the last digit isn't even.
Step 2: Check 5. It is it divisible by 5 (the last digit isn't 0 or 5).
Step 3: Check 3. Using the divisibility rule for 3, we take the sum of the digits of 2,917, which is 19. Since 19 is not divisible by 3, neither is 2,917.
Step 4: Check the rest of the primes up to 50 using a calculator. When 2,917 is divided by every prime number up to 50, the result has a decimal part.
Since no prime up to 50 divides 2,917, it is a prime number.