Math & Science· 5 min read

Prime Number Generator: Sieve of Eratosthenes and Nth Prime Lists

You will learn how to generate prime number lists using two different algorithms and understand when each one is more efficient.

By EasyMath Team Last updated: 2026-08-23.

Why this matters

Prime numbers are the atomic units of integer arithmetic — every integer greater than 1 is either prime or can be factored uniquely into primes. This fundamental theorem of arithmetic makes primes essential in number theory, and their properties underpin modern cryptography systems like RSA and Diffie-Hellman key exchange. Generating a list of primes is one of the most common tasks in mathematical computing, whether you are building a lookup table for a crypto implementation, testing an algorithm's performance, or exploring number theory patterns.

The choice of algorithm matters significantly depending on what you are trying to generate. If you need the first N primes, trial division with a 6k plus-or-minus 1 wheel optimization is straightforward and memory-efficient because it only checks divisibility against known primes up to the square root. If you need all primes below a given ceiling, the Sieve of Eratosthenes is dramatically faster because it marks composites in a single array pass rather than testing each candidate individually. This tool offers both modes, so you can pick the approach that matches your use case.

The generator supports producing up to 10,000 primes in the first-N mode, or all primes below 1,000,000 in the sieve mode. The output includes the full list with a copy-to-clipboard button, plus the total count and the largest prime found, which are useful reference values for verifying the result against known sequences.

See it in action

Reference table

ModeAlgorithmBest for
First N primesTrial division with 6k +/- 1 wheelGenerating a specific count of primes
Primes up to limitSieve of EratosthenesListing all primes below a ceiling
100th prime541Quick reference check
1,000th prime7,919Quick reference check
10,000th prime104,729Quick reference check
Max first-N10,000 primesPractical performance limit
Max sieve ceiling1,000,000Practical performance limit

How to use it

Choose a mode: 'First N primes' to generate a specific count, or 'Primes up to limit' to list all primes below a number.

Enter N (for example, 100) or an upper bound (for example, 1000) in the input field.

The prime list appears with the total count and the largest prime displayed above the list.

Use the copy button to grab the entire list to your clipboard for use in code or spreadsheets.

Testing your result

Verify the output against known prime counts. The first 10 primes should be 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. Check that the 100th prime is 541 and the 1,000th is 7,919. In sieve mode, enter a ceiling of 100 and confirm that exactly 25 primes are returned, which is the known prime-counting function value for pi(100). If any composite number appears in the output, the result is incorrect — every number in the list must be divisible only by 1 and itself.

Common mistakes

Confusing the two modes and entering a ceiling value when 'First N primes' is selected, which produces far more primes than expected.

Forgetting that 2 is the only even prime, and mistakenly expecting other even numbers to appear in the output.

Assuming the sieve mode and first-N mode always produce identical results for the same numeric input — they serve different purposes.

Requesting an extremely large limit that exceeds the practical performance threshold, causing the browser tab to freeze.

Edge cases and options

The 6k plus-or-minus 1 wheel optimization used in the trial-division mode skips all numbers divisible by 2 or 3, since those can never be prime (except 2 and 3 themselves). This reduces the number of candidates to roughly one-third of all integers, which significantly speeds up the generation. The Sieve of Eratosthenes works by creating a boolean array and iteratively marking multiples of each prime starting from 2. Its time complexity is O(n log log n), which makes it extremely efficient for dense ranges. The practical limits of 10,000 primes and a 1,000,000 ceiling are set to keep the tool responsive on typical hardware.

Real-world use cases

Generating prime lookup tables for cryptographic implementations that require precomputed prime lists.

Building educational materials that illustrate the distribution and density of prime numbers.

Providing input data for algorithm benchmarks or competitive programming practice problems.

Creating hash table sizes that are prime numbers to minimize collision rates in custom data structures.

Frequently asked questions

Q: What algorithm is used?

A: For 'first N primes', the tool uses trial division with a 6k +/- 1 wheel. For 'primes up to a limit', it uses the Sieve of Eratosthenes — much faster for dense ranges.


Q: How many primes can I generate?

A: Up to 10,000 primes, or primes up to 1,000,000. Beyond that, performance depends on your device.


Q: What is the 100th prime?

A: The 100th prime is 541. The 1,000th is 7,919 and the 10,000th is 104,729.


Q: Why are primes important?

A: Primes are the building blocks of integers (fundamental theorem of arithmetic) and the basis of modern cryptography (RSA, Diffie-Hellman).


Q: Can I export the list as a file?

A: The tool provides a copy-to-clipboard button for the full list. You can paste it into a text file or spreadsheet from there.


Q: Are my inputs uploaded?

A: No — the math runs entirely in your browser.

Start using it now

Try the Prime Number Generator tool. See also Prime Number Checker and Prime Factorization Calculator.

Need help using this tool?

Read our complete Prime Number Generator tutorial for step-by-step guidance.

Ready to try the tool?

No accounts. No uploads. No limits. Start now.