A whole number n > 1 is prime if and only if none of the integers from 2 through ⌊√n⌋ divides it.
That condition tests one candidate. To find a list, apply a rule across a range or use the Sieve of Eratosthenes, the algorithm behind the Prime Number Generator. A formula can define primality, while a sieve efficiently produces every prime up to a chosen limit.

The formula for identifying one prime
Write the square-root divisibility test as n is prime ⇔ n > 1 and n mod d ≠ 0 for every integer d satisfying 2 ≤ d ≤ ⌊√n⌋. Here, “mod” gives the remainder after division. If any candidate divisor leaves a remainder of zero, n is composite.
Why does the test stop at the square root? If a number is composite, it can be written as n = a × b, with a no greater than b. At least one of those factors must be no greater than √n. Therefore, checking divisors through ⌊√n⌋ is enough to reveal every possible composite number.
A useful filtering rule is that every prime greater than 3 has the form 6k ± 1. This reduces the candidates you examine, but it is not a complete primality test: a number of that form still needs its divisors checked.
Wilson’s theorem gives an exact formula
Wilson’s theorem states that, for an integer n > 1, n is prime ⇔ (n − 1)! ≡ −1 (mod n). The symbol ≡ means “is congruent to,” while the exclamation mark denotes a factorial.
This is an exact mathematical characterization, but it is not a practical formula for producing long prime lists. Factorials become enormous, and modular calculations become cumbersome quickly. The square-root test is more practical for one number, while a sieve is better for many numbers.
Generate a complete prime list
Use the Prime Number Generator when you want an exact list rather than testing candidates one at a time.
- Choose a mode. Select “Primes up to N” to list every prime at or below a limit, or “First N primes” to request an exact number of primes.
- Enter N and generate. Type your value into the input box, then press “Generate primes” or hit Enter.
- Read the output. Review the complete prime-number list, total count, sum of all returned primes, and largest prime. You can also copy the entire list with one click.
The generator runs in your browser, so nothing is uploaded and there is no queue or server-side limit. Browser performance limits still apply: “Primes up to N” accepts values through N = 10,000,000, while “First N primes” supports requests for as many as 100,000 primes. Larger values are blocked to keep the tool fast and responsive.
Choose the mode that matches your question
The two modes use the same letter, N, for different purposes, so choosing the correct mode before entering a value matters.
| Goal | Mode | Meaning of N | Maximum supported N |
|---|---|---|---|
| List every prime below a boundary | Primes up to N | N is the inclusive upper limit | 10,000,000 |
| Obtain a fixed number of primes | First N primes | N is the number of primes requested | 100,000 |
For example, “Primes up to N” answers the question “Which primes are at or below this boundary?” In contrast, “First N primes” answers “What are the first N entries in the prime sequence?” For that mode, the tool uses a proven upper bound for the Nth prime so its sieve knows how far it must search.
Worked example: finding the primes through 30
Select “Primes up to N,” enter 30, and generate the list. The output contains exactly 10 primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. The count field reads 10, and the largest prime in the result is 29.
Now apply the square-root formula to 29. Since ⌊√29⌋ = 5, the only possible divisors to test are 2, 3, and 5. The remainders are 29 mod 2 = 1, 29 mod 3 = 2, and 29 mod 5 = 4. None divides 29, so 29 is prime.
Checking each candidate this way works for a small range, but repeating the work becomes inefficient as the range grows. The sieve applies the same underlying factor logic collectively, removing multiples as it moves through the list instead of testing every candidate from scratch.
How the sieve finds every prime
The Sieve of Eratosthenes begins with all integers from 2 through the chosen bound. It retains 2 and crosses out later multiples of 2, then retains 3 and crosses out its remaining multiples, followed by 5 and the other primes that need processing. A number that survives has no smaller factor and is therefore prime.
Only sieving primes through the square root of the bound are needed because every composite number has a factor in that range. The sieve runs in roughly O(n log log n) time, which is substantially faster than trial division and allows the generator to work with limits in the millions.
For a more detailed look at the crossing-out process, see how to find prime numbers quickly using the sieve. The same algorithm supports both generator modes, with the “First N primes” mode using an upper bound when no numerical limit is entered.
Checks that confirm a correct result
A prime is a whole number greater than 1 with exactly two distinct divisors: 1 and itself. Consequently, 0 and 1 are not prime, 2 is the smallest prime, and 2 is the only even prime. These checks can catch an off-by-one error or the wrong interpretation of a result list.
| Verification point | Expected result |
|---|---|
| Number of primes up to 30 | 10 |
| Number of primes below 100 | 25 |
| 25th prime | 97 |
| 100th prime | 541 |
| 1,000th prime | 7,919 |
| 10,000th prime | 104,729 |
The count-based checks are suited to “Primes up to N,” while the position-based checks help confirm “First N primes.” Use one or two independent anchors rather than checking every entry by hand.
Match the method to the result you need
Different prime-related tasks call for different methods:
- Check one candidate: use the divisor test from 2 through ⌊√n⌋.
- Study the mathematical characterization: use Wilson’s theorem and interpret the result modulo n.
- List every prime at or below a limit: use the Sieve of Eratosthenes or the generator’s “Primes up to N” mode.
- Request a fixed sequence position: use “First N primes” to obtain exactly the requested count in order.
- Break one composite number into factors: use a factorization method instead of a prime-list generator.
If the real objective is to identify the prime factors of one integer, follow how to determine the prime factorization of any number. A prime list answers “Which numbers are prime?” while prime factorization answers “Which primes multiply together to make this particular number?”