Nth prime calculator

Enter n to get the n-th prime number — the 100th prime is 541 — or switch modes and enter a number x to count the primes up to it and see whether x itself is prime and which one it is. The previous and next primes are shown too.

n from 1 to 1,000,000, or x from 1 to 20,000,000.
n-th prime541
Position in the list of primes
100th
Previous prime
523
Next prime
547

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Choose “The n-th prime” and enter n, or choose “How many primes up to x” and enter x.
  2. Read the prime or the count, with the primes just before and after.

How it works

The Sieve of Eratosthenes marks every odd multiple of 3, 5, 7 … as composite, starting at the square of each prime. For the n-th prime the sieve runs up to Rosser’s bound m(ln m + ln ln m) with m = n + 1, which is always beyond the (n + 1)-th prime, so the next prime is found as well; the calculator then counts primes until it reaches the n-th. For π(x) it sieves a little past x so it can also show the next prime.

Worked example

The 100th prime: the bound is 101 × (ln 101 + ln ln 101) ≈ 621, the sieve finds the primes up to it, and the 100th of them is 541. The 99th is 523 and the 101st is 547. In the other direction, π(541) = 100, and 541 is the 100th prime.

Tips

  • By the prime number theorem, π(x) is roughly x / ln x: for x = 1,000,000 that gives about 72,382 against the true 78,498.
  • To test one big number for primality, use the prime number checker, which goes far beyond 20 million.

Frequently asked questions

What is the 100th prime number?

541. The first primes are 2, 3, 5, 7, 11, 13 …; the 10th is 29, the 1000th is 7919, the 10,000th is 104,729 and the millionth is 15,485,863.

How many primes are there below 1000?

168. The prime-counting function π(x) gives the number of primes up to x: π(100) = 25, π(1000) = 168 and π(1,000,000) = 78,498.

How does the calculator find the n-th prime?

It sieves: the Sieve of Eratosthenes crosses out the multiples of each prime up to a bound that is guaranteed to be larger than the answer — Rosser's n(ln n + ln ln n), valid for n ≥ 6 — then counts the primes that remain.

Is 1 a prime number?

No. A prime has exactly two divisors, 1 and itself; 1 has only one. The first prime is 2, the only even prime.

More in Math

All tools in this category: Math ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.