Nth Prime Calculator
Number
- Rosser's theorem bounds the nth prime below n x (ln n + ln ln n) = 617 for n = 100.
- A sieve of Eratosthenes up to 617 marks every composite, leaving the primes in order.
- Counting through the sieve, prime number 100 is 541.
- Its neighbours are 523 below and 547 above, a prime gap of 6 to the next prime.
This nth prime calculator tells you which prime number sits at a given position in the sequence of primes. Enter a position n and it returns the exact nth prime, not an estimate. For example, the 25th prime is 97, sitting between 89 and 101; the 100th prime is 541, sitting between 523 and 547, with a prime gap of 6 to the next prime; and the 1,000th prime is 7,919. The calculator first sizes the search using Rosser's theorem, which guarantees that the nth prime lies below n(ln n + ln ln n) for n of 6 or more. That gives a bound of 617 for n = 100 and a bound of 8,844 for n = 1,000, so the sieve never searches further than it needs to.
The method behind the answer is a sieve of Eratosthenes, which finds every prime up to the bound by crossing out multiples. Because it works through the whole range up to that bound, the nth prime it returns is exact rather than estimated, which is why the sieve is the accepted standard for this kind of calculation. This page shows the formula, the step-by-step workings, worked examples and sources, so you can follow how each result is produced and check it yourself.
Worked examples
The 100th prime
(100)
| Prime #100 | 541 |
| Previous prime | 523 |
| Next prime | 547 |
| Gap to next prime | 6 |
The 1,000th prime
(1000)
| Prime #1,000 | 7,919 |
| Previous prime | 7,907 |
| Next prime | 7,927 |
| Gap to next prime | 8 |
The 25th prime
(25)
| Prime #25 | 97 |
| Previous prime | 89 |
| Next prime | 101 |
| Gap to next prime | 4 |
Why a bound comes first
A sieve of Eratosthenes works by crossing out multiples, and it can only do that inside a range you have already chosen. That makes the limit the first decision in any nth prime calculator: the sieve needs a ceiling before it can start. Set the ceiling too low and the nth prime may fall outside the range entirely, so the sieve finishes with nothing to return. Set it far too high and the sieve crosses out multiples across a range much larger than necessary, spending time and memory on numbers that never mattered. Getting the nth prime is easy once the bound is right; the real work is choosing the bound.
Rosser's theorem solves that problem with a proved upper bound rather than a guess. It guarantees that the nth prime lies below n(ln n + ln ln n) for n of 6 or more. That expression gives a ceiling that is high enough to contain the answer by proof, and close enough that the sieve stays a reasonable size. The bound is not an estimate of where the prime sits; it is a limit the prime is guaranteed not to exceed, which is exactly what a sieve needs to know before it begins.
The numbers show how tight this is in practice. For n = 100, the theorem gives a sieve bound of 617, and the 100th prime is 541, sitting between 523 and 547, a prime gap of 6 to the next prime. The bound clears the answer with room to spare but does not balloon the range. For n = 1,000, the 1,000th prime is 7,919, found under a sieve bound of 8,844. Again the ceiling sits above the true value, so the sieve is guaranteed to reach it, without covering a range many times larger than needed.
Because the sieve of Eratosthenes finds every prime up to the bound by crossing out multiples, the nth prime returned is exact, not estimated. The bound does not decide the answer; it only sets the space in which the answer is guaranteed to appear. Once the sieve has marked every composite up to that ceiling, the primes that remain are counted in order, and the nth one is read off directly. A smaller bound would risk stopping before the nth prime appears, and a larger one would only add work, so the theorem's bound is the balance point between missing the prime and wasting effort.
Smaller cases follow the same logic. The 25th prime is 97, between 89 and 101, and it too must sit under a ceiling chosen in advance. Whether n is 25, 100, or 1,000, the sequence is the same: pick a proved bound, sieve up to it, and count. That is why a bound comes first.
The sieve of Eratosthenes
The sieve of Eratosthenes is the simplest exact method for finding every prime up to a chosen limit, and it is the engine behind an nth prime calculator. You start with a list of whole numbers from 2 up to your limit and treat every number as a candidate. Two is prime, so you keep it and cross out every multiple of 2 above it: 4, 6, 8, 10, and so on. The next number still standing is 3, which is prime, so you keep it and cross out 6, 9, 12, 15, and the rest of its multiples. The next survivor is 5, then 7, then 11. Each time, the smallest number not yet crossed out must be prime, because any smaller factor would already have crossed it out. When you finish, every number left standing is prime, and counting them in order gives you the nth prime directly.
The method only works if you choose the limit in advance, and that is where a bound comes in. Rosser's theorem guarantees that the nth prime lies below n(ln n + ln ln n) for n of 6 or more, which sizes the sieve exactly. For n = 100, that bound works out to 617, so a sieve run to 617 is guaranteed to contain the 100th prime. You do not need to guess how far to count, and you do not need to test numbers one at a time with trial division. The bound tells you where to stop before you begin.
Running the sieve to 617 and counting the survivors, the 100th prime is 541. It sits between 523 and 547, which is a prime gap of 6 to the next prime. The count is exact, not an estimate: every composite below 617 has been crossed out by one of its factors, so the hundredth number remaining is 541 and nothing else. The same procedure scales. The 25th prime is 97, between 89 and 101. The 1,000th prime is 7,919, found under a sieve bound of 8,844. In each case the sieve returns the exact prime, because crossing out multiples removes every composite from the list.
The counting step is what turns the sieve into an nth prime answer. After the crossing-out pass, you walk the remaining numbers in increasing order and keep a running tally; when the tally reaches n, the current number is the answer. Nothing about that final number is approximated or inferred from a pattern. It is the nth survivor of an exhaustive elimination, which is why the result for n = 100 is 541 and not a nearby guess.
| n | Sieve bound | nth prime | Neighboring primes |
|---|---|---|---|
| 25 | — | 97 | 89 and 101 |
| 100 | 617 | 541 | 523 and 547 (gap of 6 to the next prime) |
| 1,000 | 8,844 | 7,919 | — |
Prime gaps
A prime gap is the distance between one prime and the next prime after it. The 100th prime, 541, sits between 523 and 547, so the gap on its right side — from 541 to the next prime, 547 — is 6. Compare that with the 25th prime, 97, which falls between 89 and 101: the step from 97 to the next prime is 14. Gaps are not fixed. They rise and fall irregularly as you move up the number line, and the size of any single gap tells you nothing reliable about the ones nearby.
The growth becomes easier to see with a larger example. The 1,000th prime is 7,919, and its neighbors on either side are 7,907 and 7,927. The gap from 7,919 to the next prime is 8 — smaller than the gap after 97, even though 7,919 is vastly larger. This is the pattern worth holding on to: individual gaps jump around, but the average gap between consecutive primes tends to grow as the numbers get bigger. A run of small gaps can follow a large one, and a large one can appear where you least expect it.
This is why an nth prime calculator does not try to guess the nth prime from a formula. Instead it fixes a ceiling that is guaranteed to be high enough, then sieves every number below that ceiling. Rosser's theorem guarantees that the nth prime lies below n(ln n + ln ln n) for n of 6 or more, which sizes the sieve exactly: for n = 100 the bound is 617, comfortably above the 100th prime of 541. For n = 1,000 the sieve bound is 8,844, and the 1,000th prime, 7,919, is found beneath it.
A sieve of Eratosthenes finds every prime up to the bound by crossing out multiples, so the nth prime returned is exact, not estimated. The calculator counts the primes the sieve leaves standing and stops at the nth one. That means the gaps described above — 6 after 541, 8 after 7,919 — are read directly off a complete list of primes, not inferred from an approximation. If you want to inspect the neighbors of a result, the same sieve gives you the previous and next prime for free.
When you use an nth prime calculator, the gap figures are a useful check on the answer. If the tool reports that the 100th prime is 541, the primes on either side should be 523 and 547, and the gap to the next prime should be 6. If it reports 7,919 for n = 1,000, the neighbors should be 7,907 and 7,927, with a gap of 8. Matching those numbers confirms the count is aligned correctly.
- 25th prime: 97, between 89 and 101
- 100th prime: 541, between 523 and 547 — gap of 6 to the next prime
- 1,000th prime: 7,919, between 7,907 and 7,927 — gap of 8 to the next prime
How far this goes
This nth prime calculator works up to n = 10,000. That ceiling is a practical one, and it is worth understanding why, because the same reasoning explains how the tool gets its answers. To return the nth prime exactly, the calculator first needs a sieve large enough to contain it. Rosser's theorem guarantees that the nth prime lies below n(ln n + ln ln n) for n of 6 or more, and that inequality sizes the sieve precisely rather than by guesswork. For n = 100, the formula gives a bound of 617 — comfortably above the 100th prime of 541, which sits between 523 and 547, a prime gap of 6 to the next prime.
The pattern holds as n grows. The 1,000th prime is 7,919, found under a sieve bound of 8,844. The bound is always somewhat generous, and that slack is deliberate: it is what lets the sieve be certain of enclosing the answer without checking each candidate one at a time. Even for small n the same machinery applies. The 25th prime is 97, between 89 and 101, and it falls well inside a bound computed the same way.
Prime-counting functions can estimate this same territory approximately — they tell you roughly how many primes lie below a number, or roughly where the nth one should fall. But an estimate is not a prime. A sieve of Eratosthenes finds every prime up to the bound by crossing out multiples, so the nth prime returned is exact, not estimated. That distinction is the whole point of the tool: when you ask for the 1,000th prime, you get 7,919, a specific prime, not a value near it.
So "how far this goes" is really two answers. The hard limit is n = 10,000, the range the calculator is built to handle. Within that range, every result is exact, because the sieve does not approximate — it eliminates. If you need a prime beyond 10,000, the method still works in principle, but this calculator stops there, and the bound it computes would grow with n accordingly.
- n = 25 → 97, between 89 and 101
- n = 100 → 541, between 523 and 547, a prime gap of 6 to the next prime; sieve bound of 617
- n = 1,000 → 7,919, found under a sieve bound of 8,844
- Maximum n handled here: 10,000
- Every result is exact: the sieve crosses out multiples up to the bound, so the nth prime is found, not estimated
FAQs
What is the 100th prime number?
The 100th prime number is 541. Its neighbors in the prime sequence sit close by: 523 is the prime just below it, and 547 is the prime just above it. You can confirm this by listing primes in order and counting to position 100, which is what the calculator does.
What is the 1,000th prime?
The 1,000th prime is 7,919. The prime immediately below it is 7,907, and the prime immediately above it is 7,927. Counting primes in order up to the thousandth position lands exactly on 7,919, so any tool that returns a different value for this position is wrong.
How does the calculator find it?
It uses a sieve up to a bound taken from Rosser's theorem: 617 for n = 100 and 8,844 for n = 1,000. The sieve marks composites by elimination across that range, then the calculator counts the remaining primes in order until it reaches the nth one.
What is a prime gap?
A prime gap is the distance from one prime to the next. After 541 the gap is 6, since the next prime is 547. After 7,919 the gap is 8, since the next prime is 7,927. After the 25th prime, 97, the gap is 4.
Why not just test numbers one by one?
You can test candidates one at a time, but it is slower. A sieve tests all candidates at once by elimination, crossing out multiples rather than checking each number individually. At n in the thousands, that makes the sieve far faster than one-by-one testing.
Is the nth prime formula exact?
There is no simple exact formula for the nth prime. Approximations such as n(ln n + ln ln n) only estimate it. That is why this calculator uses that expression solely as a sieve bound, then counts the primes in order to reach the exact nth prime.