A prime number is any whole number greater than 1 whose only divisors are 1 and itself — and the fastest practical way to generate a list of primes is to run the Sieve of Eratosthenes, an algorithm that can produce every prime up to 10,000,000 nearly instantly. The classic test for primality, trial division, works fine for small numbers but gets painfully slow as N grows, because every candidate has to be divided by every smaller prime. The sieve flips the problem around: instead of testing each number one by one, it starts with every integer up to N and systematically crosses out the multiples of each prime it finds. Whatever survives the crossings is guaranteed prime. This is the same approach the Prime Number Generator uses, and it runs entirely in your browser, so there is nothing to install, no upload, and no queue — you type a number, press a button, and the full list of primes appears alongside the count, the sum, and the largest prime found.

Why Trial Division Stalls as Numbers Grow
Trial division is what most people learn first, and it is perfectly correct — you test each candidate n by dividing it by every integer from 2 up to √n. If none of those divisions lands evenly, n is prime. The trouble is the workload. By the time you reach a few thousand, you have already performed thousands of divisions per candidate, and most of those candidates turn out to be composite. The Prime Number Theorem tells us that primes thin out as numbers grow, but they never disappear, so the cost of checking each non-prime candidate keeps climbing.
There are a few short-cuts that help a little. You only need to test divisibility by smaller primes, not every integer, because composite factors always reduce to prime factors. You only need to test up to √n, since any divisor larger than that pairs with one smaller than √n. And the small primes 2, 3 and 5 knock out most candidates in a single step. But even with all of these, the number of divisions per candidate is still proportional to the count of primes below √n, which grows without bound. For homework-scale ranges this is fine; for cryptographic-scale numbers it is hopeless.
That is why the sieve exists. Instead of asking "is this single number prime?", the sieve asks "which numbers from 2 to N have no prime divisor smaller than themselves?", and it answers the question by elimination rather than by repeated testing.
How the Sieve of Eratosthenes Lists Primes
The Sieve of Eratosthenes is an ancient algorithm for listing every prime below a fixed limit, and it is still the fastest straightforward method for that job. The procedure is mechanical.
Start with the integers 2, 3, 4, ..., N. Mark 2 as prime and cross out every multiple of 2 — so 4, 6, 8, 10 and so on disappear. Move to the next number that has not been crossed out; that is 3. Mark it prime and cross out every multiple of 3 — 6, 9, 12, 15 and so on. Move to the next survivor, 5, and cross out its multiples. Continue this process. When you reach the square of the current prime, you can stop crossing out and just mark every remaining unmarked number as prime.
The reason this works is simple but powerful. A composite number n always has a prime factor p with p ≤ √n. That prime factor p gets marked prime early in the sieve, and the crossing-out step for p eliminates n. So every number that survives the entire pass has no prime factor at all — which means it has no divisor other than 1 and itself — which means it is prime.
The cost of the sieve is famously close to linear. Each integer gets crossed out at most a handful of times, and the running time is roughly O(N log log N). For N = 1,000,000 this is hundreds of times faster than trial division; for N = 10,000,000 the gap is even larger. That is why the underlying engine behind the Prime Number Generator is the sieve, and why it can return lists of millions of primes almost immediately without any server-side work.
How to Use the Prime Number Generator
This is the practical part. The tool runs in your browser, so everything happens locally and there is nothing to install or sign up for. The full list of operating steps is short and deterministic.
- Choose a mode. Pick "Primes up to N" if you want every prime at most equal to a limit you specify, or "First N primes" if you want exactly N primes in ascending order.
- Type your value for N into the input box. For the first mode this is the upper limit (up to 10,000,000); for the second it is the count of primes you want (up to 100,000).
- Press Generate primes, or simply hit Enter. The full list of primes appears.
- Read the result. Below the list you will see the total count, the sum of all primes in the result and the largest prime that was produced.
- Copy the list if needed. A one-click copy puts the entire prime list on your clipboard so you can paste it into a spreadsheet, a code file or a homework document.
Choosing Between the Two Modes
The two modes solve different questions, and picking the right one saves you from second-guessing the output. Here is a side-by-side comparison.
| Question you are asking | Mode to pick | Example input | What you get |
|---|---|---|---|
| Which primes are ≤ N? | Primes up to N | 100 | All 25 primes below 100, ending at 97 |
| What are the first N primes? | First N primes | 25 | The first 25 primes, ending at 97 |
| List primes in a small range | Primes up to N | 1000 | Every prime below one thousand |
| What is the 1000th prime? | First N primes | 1000 | 7919 as the last entry |
| Generate a long reference table | Primes up to N | 1,000,000 | Every prime below one million |
| Find a specific prime by position | First N primes | 10,000 | The first 10,000 primes, ending at 104,729 |
For most homework and reference tasks, "Primes up to N" is the natural choice because it maps directly to the question "list primes below this number". For benchmark code, Project Euler-style problems and checks of well-known anchor values, "First N primes" is usually what you want because it lets you ask for "the N-th prime" directly. Both modes produce the count, the sum and the largest prime in the result, so you always have something concrete to compare against a hand-computed answer.
Where Prime Numbers Actually Matter
Prime numbers are not just an exercise. They show up in places you would not immediately expect, and generating them quickly is useful in all of them.
Teachers and students reach for prime lists when introducing number theory, building factor trees, practising divisibility or factoring composites. Programmers use a prime generator both as a benchmark — sieves up to a few million are a classic performance exercise — and as a building block for hash tables, pseudo-random sequences and Project Euler-style problems. Cryptography leans most heavily on large primes. RSA, the algorithm that secures most web traffic, depends on the practical difficulty of factoring a product of two very large primes. Generating test primes quickly is part of writing and testing that code.
Beyond the practical, primes are useful for sanity-checking other tools. If you are verifying a factorization tool, a GCF tool or any other number-theory routine, generating a small list of primes and feeding individual entries into the tool under test is a quick way to spot regressions. And curiosities like twin primes — 11 and 13, or 17 and 19 — keep appearing because, even though primes thin out, they never actually run out.
Handy Reference Values to Sanity-Check Results
A few well-known anchor primes are worth keeping in your head (or pinned to a note) because they let you verify any output by hand in moments.
| Position or range | Expected value | Use it to check |
|---|---|---|
| 25th prime | 97 | Confirm "first 25 primes" or "primes up to 100" |
| Primes below 100 (count) | 25 | Same as above |
| Primes up to 30 (count) | 10 | Quick mode test |
| 100th prime | 541 | Mid-range anchor for "first N primes" |
| 1000th prime | 7919 | Common Project Euler target |
| 10,000th prime | 104,729 | Large-anchor sanity check |
| 100,000th prime | 1,299,709 | Upper end of the supported count |
The mode "First N primes" lets you reproduce any of these by asking for that exact N, and "Primes up to N" lets you reproduce the counts by asking for the matching upper limit. If a tool returns a count that disagrees with the row above, you have caught a bug immediately. The Prime Number Generator is built so that its output is internally consistent — the count, the sum and the largest prime all match the list, and the list itself matches the chosen mode — so when you anchor it to one of these well-known values you can trust the rest of the output without re-checking every entry by hand.