Nth Prime Calculator - Find the 1000th Prime Number

Any whole number from 1 to 1,000,000. Position 1 is the prime 2.

Prime number 1,000

7,919

Formula:

p(1,000) = 7,919 · found by sieving to 8,887 and counting survivors

Gap from previous

+12

from 7,907

Gap to next

+8

to 7,927

Average gap here

9.0

ln(7,919) — about 1 in 9 is prime

Digits in pₙ

4

999 primes sit below it

The primes on either side, and the gaps between them

Bar length is the jump from the prime above it. The average near here is 9.0 — individual gaps rarely match it.

p9977,883+4
p9987,901+18
p9997,907+6
p1,0007,919+12
p1,0017,927+8
p1,0027,933+6
p1,0037,937+4

How close do the standard estimates get?

Both formulas approximate pₙ without finding a single prime. Both run low, always.

Actual sieved

7,919exact · +0.00%

Refined n(ln n + ln ln n − 1)

7,840−79 · −0.993%

Textbook n · ln n

6,908−1,011 · −12.77%

n = 1,000 The classic lookup: the 1000th prime is 7,919.

How to Use This Calculator

  1. Pick a mode. Prime at position n answers “what is the 1000th prime?”. Count primes up to x answers the reverse, “how many primes are there below 7,919?”.
  2. Type the number into the Position n field (or the Upper limit x field in count mode), or tap one of the shortcut buttons underneath it.
  3. Read the big number first, then the four cards: the gap on each side, the average gap near that size, and the position check π(pₙ) = n that confirms the answer.
  4. Scroll to the gap bars to see the primes immediately before and after yours — that is where the irregularity shows up.
  5. Compare the estimate bars at the bottom. They show how far n·ln n and Li(x) land from the counted answer, which is the fastest way to see why one formula is used in practice and the other only in textbooks.

Share this calculator

Help others solve their calculations

Found this calculator helpful? Share it with your friends, students, or colleagues who might need it!

An Nth Prime Calculator Has to Count Every Prime Before Yours

About the Author

Marko Šinko - Co-Founder & Lead Developer

Marko Šinko

Co-Founder & Lead Developer, AI Math Calculator

Lepoglava, Croatia
Advanced Algorithm Expert

Croatian developer with a Computer Science degree from University of Zagreb and expertise in advanced algorithms. Co-founder of award-winning projects, ensuring precise mathematical computations and reliable calculator tools.

📅 Published:
Nth Prime Calculator showing the 1000th prime, the gaps to the primes either side of it, and how the estimates compare

An nth prime calculator returns p₁₀₀₀ = 7,919 in about the time it takes to blink, and the explanation for how is slightly deflating: it found the other 999 primes first. There is no shortcut. Nothing takes 1,000 in one end and drops 7,919 out the other.

That one fact shapes the whole tool above — how far it has to sieve before it can answer, why it works harder the higher you climb, and why the estimate printed next to the answer is arguably more interesting than the answer. What follows is the bound that tells a program where to stop looking, two approximations for pₙ that differ twelvefold in accuracy, the counting function π(x) that runs the same question backwards, and the off-by-one that quietly wrecks half the answers people give.

There Is No Formula That Skips Straight to the nth Prime

Formulas do exist on paper. Willans published one in 1964 that expresses pₙ in closed form using nested floor functions and a cosine; Mills proved there is a constant θ ≈ 1.3063 such that ⌊θ^(3ⁿ)⌋ is prime for every n. Neither is usable. Willans’ version needs factorials of numbers around the size of pₙ itself, and θ can only be pinned down to enough decimal places by first knowing the primes it is supposed to produce. That is a circle, not a shortcut.

What actually runs is the sieve of Eratosthenes, unchanged in principle since roughly 240 BC. Write down every integer up to some limit, cross out multiples of 2, then multiples of 3, then 5, and count what survives. Reach a count of 1,000 and the number you are standing on is 7,919. The same crossing-out logic sits under a prime factorization calculator, except there you keep the divisors instead of discarding them.

Scaling is better than people expect. Finding p₁₀₀₀₀₀₀ = 15,485,863 means sieving 16.4 million numbers, but you only ever cross out using primes up to √16,400,000 ≈ 4,050 — about 560 of them. That is why the millionth prime comes back in well under a tenth of a second while a naive “test each number for primality” loop would still be grinding.

How an Nth Prime Calculator Decides Where to Stop Sieving

A sieve needs a finite array, so before it starts it needs an upper bound on pₙ. Rosser supplied one: for every n ≥ 6, pₙ < n(ln n + ln ln n). Sieve to that limit and the nth prime is guaranteed to be inside. Guess lower and you get a wrong answer or a second pass.

nRosser boundActual pₙWasted sieving
1,0008,8417,91911.6%
10,000114,307104,7299.1%
100,0001,395,6401,299,7097.4%
1,000,00016,441,30315,485,8636.2%

The overshoot shrinks as n grows, which is convenient — the cases where wasted work would hurt are exactly the cases where the bound is tightest. Twelve per cent of extra crossing-out at n = 1,000 costs nothing at all; six per cent at a million costs a few milliseconds.

Two Estimates for pₙ, One of Them Twelve Times Better

The approximation everyone learns first is pₙ ≈ n ln n. It is asymptotically correct and practically disappointing. At n = 1,000 it says 6,908 against a true 7,919 — low by 12.8%. The frustrating part is that it barely improves with scale: at a million it is still low by 10.8%.

Add one more term and the character of the estimate changes completely. Using pₙ ≈ n(ln n + ln ln n − 1) the miss drops to 0.99% at n = 1,000 and to 0.29% at a million.

nActual pₙn · ln nErrorn(ln n + ln ln n − 1)Error
10054146114.9%5135.1%
1,0007,9196,90812.8%7,8401.0%
10,000104,72992,10312.1%104,3070.40%
100,0001,299,7091,151,29311.4%1,295,6400.31%
1,000,00015,485,86313,815,51110.8%15,441,3020.29%

Notice every error is negative. That is not luck. Rosser also proved pₙ > n ln n for all n, so the textbook estimate is a guaranteed floor and never a ceiling. If you need a working number without running a sieve, take n(ln n + ln ln n − 1) and treat it as a lower bound you may need to walk up from.

π(x) Is the Same Question Read Backwards

The prime-counting function π(x) gives how many primes are less than or equal to x. It is the exact inverse of prime indexing: π(pₙ) = n. Ask “which prime is number 1,000” and you get 7,919; ask “how many primes are there up to 7,919” and you get 1,000. Same pair of numbers, opposite direction, and the second mode of the calculator above does it.

Both of those are different from “is 7,919 prime?”. That is a primality test, it involves no counting whatsoever, and the prime calculator settles it for a single number in a few divisions. Keep the three apart: testing asks about one number, counting asks about a range, indexing asks about a position.

Approximating π(x) is where the prime number theorem earns its name — and where the version most people quote turns out to be the weak one. x / ln x is the headline result. The offset logarithmic integral Li(x) = ∫₂ˣ dt/ln t is the same idea done properly, and the difference is not subtle:

xπ(x)x / ln xMissLi(x)Miss
10³16814523177+9
10⁴1,2291,0861431,245+16
10⁵9,5928,6869069,629+37
10⁶78,49872,3826,11678,627+129
10⁷664,579620,42144,158664,917+338
10⁹50,847,53448,254,9422,592,59250,849,234+1,700

At a billion, x / ln x is out by two and a half million primes. Li(x) is out by 1,700 — a relative error of 0.003%. Li also overshoots where x / ln x undershoots, which is a real result rather than a coincidence: Li(x) > π(x) for every x anyone has ever checked, though Littlewood proved in 1914 that the sign flips infinitely often somewhere far above where we can compute. The prime-counting function article on Wikipedia carries the exact values much further, and OEIS A000040 is the canonical list of the primes themselves.

The Jump to the Next Prime Is Not the Jump from the Last One

Around p₁₀₀₀ = 7,919 the average gap is ln(7,919) ≈ 9. Look at the actual neighbours and neither side matches: 7,907 → 7,919 is a jump of 12, and 7,919 → 7,927 is a jump of 8. The average is a statement about millions of primes at once, not about the two on your screen.

Small gaps cluster. Below 1,000 there are 35 twin-prime pairs — primes exactly two apart, like 641 and 643 — which is roughly one pair for every five primes in that range. Large gaps arrive late and dramatically. No gap of 100 or more occurs anywhere below 370,261, and when it finally shows up it is a gap of 112, running clean from 370,261 to 370,373. The largest gap anywhere under a million is 114, the stretch of 113 consecutive composite numbers that starts just after 492,113.

That has a direct practical consequence. If a program needs “a prime near 500,000” and only searches 20 numbers ahead, it will sometimes find nothing — because below a million you may have to walk more than a hundred steps. Search a window of at least 150 and you are safe in that range.

The Off-by-One That Ruins Half the Answers

Three conventions collide here, and each one shifts the answer by exactly one position.

  • p₁ = 2, not 1. The number 1 was still being listed as prime into the early 1900s. It was dropped so that unique factorisation stays true — allow 1 and every number has infinitely many factorisations. So the 1st prime is 2, the 4th is 7, and any list that starts at 1 is permanently one place out.
  • Zero-based versus one-based indexing. Mathematicians count from p₁; arrays count from 0. In a Python list of primes, primes[1000] is 7,927 — the 1001st prime, not the 1000th.
  • π(x) is inclusive. π(7,919) = 1,000 because 7,919 itself counts. π(7,918) = 999. A specification that says “primes below x” may or may not mean the same thing, so check before you trust the number.

Project Euler’s problem 7 is a good stress test of all three: it asks for the 10,001st prime, and the answer is 104,743. The 10,000th is 104,729. One position apart, 14 integers apart — and a great many wrong submissions are simply that gap.

When You Actually Need a Prime by Position

Indexing primes sounds academic until you need a prime that is reproducible rather than merely convenient. A few places it comes up:

  • Hash table sizing. Open-addressing tables behave badly when the modulus shares factors with the keys, so implementations grow to the next prime past a target size. “The next prime after 1,000,000” is 1,000,003 — count mode gives it directly.
  • Reproducible test data. “The 500th prime” is a spec anyone can verify; “a random prime near 3,500” is not. Indexed primes make fixtures portable across languages.
  • Competition and puzzle answers. Project Euler, Advent of Code and most coding-interview prime questions are phrased by position, not by value.
  • Sanity-checking factorisations. If a prime factor calculator hands you a factor you did not expect, checking its position tells you instantly whether it is a small everyday prime or something far out in the tail.

Two related pages sit next door. Primes of the special shape 2ᵖ − 1 are indexed by their exponent rather than their position in the ordinary list, which is why the Mersenne prime calculator counts differently — the 52nd known Mersenne prime is nowhere near the 52nd prime. And if you only want the primes that divide a specific number rather than the primes at a specific rank, the prime factorization calculator is the faster route.

Frequently Asked Questions

Still Have Questions?

The detailed content on this page provides comprehensive explanations and examples to help you understand better.