Skip to content
Omnikalc

Prime number theorem calculator: estimate how many primes are below x

Enter a limit x, an interval length and a position n to estimate the number of primes up to x, the chance a number is prime, the average gap and the n-th prime.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Results

Primes up to x, better estimate x / (ln x − 1)

78,030

Primes up to x, simple estimate x / ln x
72,382
Chance that a number near x is prime
7.24%
Average gap between primes near x
13.8
Expected primes in your interval
72.4
Estimate of the n-th prime
104,307

Prime numbers thin out as numbers grow, in a way that is described by the prime number theorem. The prime number theorem calculator takes a limit x, an interval length and a position n and gives two estimates of the number of primes up to x, the chance that a number near x is prime, the average gap between primes, the expected number of primes in an interval and an estimate of the n-th prime.

How the calculation works

  • Simple estimate of the number of primes up to x: π(x) ≈ x ÷ ln x. This is the prime number theorem, and the estimate is always a bit low.
  • Better estimate: π(x) ≈ x ÷ (ln x − 1). The −1 corrects most of the error of the simple formula.
  • Chance that a number near x is prime = 1 ÷ ln x, and the average gap between consecutive primes is about ln x. The expected primes in an interval of length L is L ÷ ln x.
  • n-th prime ≈ n × (ln n + ln ln n − 1). It follows from inverting the better estimate.

Example

For x = 1,000,000, ln x = 13.8155. The simple estimate gives 1,000,000 ÷ 13.8155 ≈ 72,382 primes, and the better one 1,000,000 ÷ 12.8155 ≈ 78,030. The exact count is 78,498, so the better estimate is within 0.6%. A number near one million is prime with a chance of 1 ÷ 13.8155 ≈ 7.24%, with an average gap of about 13.8, so an interval of 1,000 numbers holds about 72.4 primes. The 10,000th prime is estimated at 104,307; the true value is 104,729.

Why it matters

The theorem links number theory to simple analysis, and it is a common topic in mathematics courses. The estimates are also practical: cryptography needs large random primes, and the chance that a random number of a given size is prime tells you how many candidates must be tested.

Good to know

All the results are estimates and not exact counts. They are very good for large x and weaker for small x. The calculator does not test whether a given number is prime, and it does not list primes. For exact counts use a sieve, and for very large x use the logarithmic integral.

The GCD and LCM calculator covers the divisors of two numbers and the Fibonacci calculator explores another famous sequence.

Frequently asked questions

What is the prime number theorem?

The theorem says that the number of primes up to x, written π(x), grows like x ÷ ln x. Put another way, the chance that a random number near x is prime is about 1 ÷ ln x. It was conjectured around 1800 and proved in 1896 by Hadamard and de la Vallée Poussin.

How accurate are the estimates?

The simple formula x ÷ ln x is low by about 8% at one million and by about 5% at one billion. The form x ÷ (ln x − 1) is within 1% from a few thousand upwards. The logarithmic integral Li(x) is better still, but it needs a numerical integral and is not used here.

Do primes become rarer as numbers grow?

Yes, but slowly. About a quarter of the numbers below 100 are prime, about 8% below one million and about 4.8% below one billion. The gaps grow like ln x on average, yet there are still infinitely many primes, as Euclid showed more than 2,000 years ago.

Is the n-th prime formula exact?

No, it is an estimate that improves for large n. For n = 10,000 it gives 104,307 against a true value of 104,729, an error of 0.4%. Exact values require a sieve or a table of primes, which is easy to compute for numbers up to a few billion.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.