Prime Counting Calculator

pi(1,000,000) - primes up to x78,498
Estimate x / ln(x)72,382 (-7.8% off)
Average gap between primes near x12.74
Primes between 500,000 and 1,000,00036,960
How this was calculated
  1. Counting primes up to 1,000,000 with the sieve of Eratosthenes: cross out multiples of each prime up to sqrt(x) and count what remains.
  2. pi(1,000,000) = 78,498 exactly.
  3. The prime number theorem estimate x / ln(x) gives 72,382, which is 7.8% below the true count; the logarithmic integral is closer still.
  4. Primes thin out as numbers grow: the average gap near 1,000,000 is 12.74, and 36,960 primes lie in the top half of the range alone.

The prime counting function, written pi(x), tells you how many primes are at or below a whole number x. This prime counting function calculator gives you that exact count for the number you enter. There are exactly 25 primes at or below 100, and 10 of them lie between 50 and 100. The counts here are exact, produced by the sieve of Eratosthenes rather than an approximation. For comparison, pi(1,000,000) = 78,498, while the prime number theorem estimate x / ln(x) gives 72,382. At ten million the true count is pi(10,000,000) = 664,579, with 316,066 primes in the top half of the range alone, while the estimate is 620,421, still visibly below the true count. The average gap between primes grows from 4.00 near 100 to 12.74 near a million and 15.05 near ten million.

The sieve of Eratosthenes is the accepted standard for this kind of calculation because it identifies primes directly by marking off multiples, so every prime at or below x is counted and none is estimated. That is why the results are exact rather than approximate, and why they can differ from simpler estimates such as x / ln(x). This page shows the formula, step-by-step workings, worked examples and sources so you can follow how each count is reached and check the result yourself.

Worked examples

Primes up to 100

(100)

pi(100) - primes up to x25
Estimate x / ln(x)22 (-13.1% off)
Average gap between primes near x4.00
Primes between 50 and 10010

Primes up to a million

(1000000)

pi(1,000,000) - primes up to x78,498
Estimate x / ln(x)72,382 (-7.8% off)
Average gap between primes near x12.74
Primes between 500,000 and 1,000,00036,960

Primes up to ten million

(10000000)

pi(10,000,000) - primes up to x664,579
Estimate x / ln(x)620,421 (-6.6% off)
Average gap between primes near x15.05
Primes between 5,000,000 and 10,000,000316,066

How the prime counting function works

The prime counting function, written π(x), answers one question: how many primes are there at or below a given number x? It is not an estimate and not a formula you evaluate — it is a count. A prime counting function calculator gets that count by actually finding the primes and tallying them, which is why the results you see here are exact rather than rounded.

The method behind the count is the sieve of Eratosthenes. You list every whole number from 2 up to x, then cross out multiples of 2, then multiples of 3, then multiples of 5, and so on. You only need to sieve with primes up to the square root of x, because any composite number at or below x must have a factor no larger than that square root. Once every composite has been crossed out, the numbers still standing are the primes, and counting them gives π(x). For x = 100, the sieve only needs the primes 2, 3, 5 and 7, since the square root of 100 is 10. The survivors number exactly 25, so π(100) = 25. Ten of those 25 primes lie between 50 and 100. Scale the same process up to one million and the survivors number 78,498, so π(1,000,000) = 78,498.

The sieve also shows how the primes thin out as the numbers grow. The average gap between primes is 4.00 near 100, rises to 12.74 near a million, and reaches 15.05 near ten million. The counts grow, but more slowly than x itself. At ten million the sieve finds 664,579 primes, and 316,066 of them sit in the top half of the range alone — the upper half of the list is where most of the work happens, which is why sieving is done carefully rather than by hand.

The prime number theorem offers a shortcut estimate, x / ln(x), and comparing it with the true count shows why exact sieving matters. For one million the estimate is 72,382 against the true 78,498. For ten million the estimate is 620,421, still visibly below the true 664,579. The estimate is useful for intuition, but it is not the count. Every figure produced by this prime counting function calculator comes from the sieve of Eratosthenes, so the totals are exact.

π(100) = 25 · π(1,000,000) = 78,498 · π(10,000,000) = 664,579 — all exact sieve counts, not estimates.

Worked examples

A prime counting function calculator is easiest to trust when you can check its answers against counts that are already known. The three examples below are exact counts, not estimates, and they show how the true number of primes compares with the approximation given by the prime number theorem, x / ln(x).

Up to 100, there are exactly 25 primes. Ten of them lie between 50 and 100, so the lower half of the range holds the other 15. At this small size the average gap between consecutive primes is about 4.00, which is why the primes feel crowded when you list them by hand. The prime number theorem estimate for this range is not shown in the examples, but the pattern is already clear: the exact count is what the calculator reports, and the estimate is only a guide.

Up to 1,000,000, the exact count is pi(1,000,000) = 78,498. The prime number theorem estimate x / ln(x) gives 72,382 for the same range, which is visibly lower than the true count. The average gap between primes near a million has grown to about 12.74. If you want a smaller window, the count between 500,000 and 1,000,000 is 36,960 primes — a useful check that the top half of the range still contains a large share of the total.

Up to 10,000,000, the exact count is pi(10,000,000) = 664,579. The top half of the range alone contains 316,066 primes. The estimate for ten million is 620,421, still visibly below the true count. The average gap near ten million is about 15.05, continuing the slow widening seen at smaller sizes. These figures come from the sieve of Eratosthenes, so they are exact rather than approximate.

  • At or below 100: exactly 25 primes, with 10 between 50 and 100.
  • At or below 1,000,000: exactly 78,498 primes; the x / ln(x) estimate is 72,382.
  • Between 500,000 and 1,000,000: exactly 36,960 primes.
  • At or below 10,000,000: exactly 664,579 primes, with 316,066 in the top half alone; the estimate is 620,421.
  • Average gap between primes: about 4.00 near 100, 12.74 near a million, and 15.05 near ten million.
Every count on this page is exact: the sieve of Eratosthenes produces the true number of primes, while x / ln(x) only estimates it.

The prime number theorem estimate

The prime number theorem gives a simple way to guess how many primes exist up to a number x: divide x by the natural logarithm of x. The formula is easy to compute and captures the right overall trend, but it is only an estimate, and the gaps between the estimate and the truth are large enough to matter. A prime counting function calculator that reports exact counts is therefore more useful than one that stops at the approximation — the approximation is a starting point, not the answer.

At one million the difference is already easy to see. The true count is pi(1,000,000) = 78,498, while x / ln(x) gives 72,382. That is more than 6,000 primes short — roughly an 8 percent underestimate. The formula gets the shape of the curve right but consistently lands below the actual number of primes.

At ten million the same pattern holds. The true count is pi(10,000,000) = 664,579, and the estimate is 620,421, still visibly below the true count. The shortfall has grown in absolute terms to more than 44,000 primes, even though the percentage error stays in a similar range. Scaling up the input does not fix the bias; it just makes the missing primes more numerous.

The logarithmic integral does better. Where x / ln(x) undershoots, the logarithmic integral tracks the true count more closely across the same ranges, which is why it is the preferred estimate when accuracy matters. Neither formula replaces an exact count, though. The counts on this page are exact, produced by the sieve of Eratosthenes rather than an approximation, so you are comparing the estimate against the real thing rather than against another guess.

It also helps to remember what these counts are counting. The average gap between primes grows from 4.00 near 100 to 12.74 near a million and 15.05 near ten million. Primes thin out as the numbers get larger, and that thinning is exactly what the x / ln(x) formula tries to describe. The estimate captures the thinning trend, but the exact sieve captures the actual primes — including details the formula cannot see, such as the 316,066 primes in the top half of the range alone at ten million.

  • At 1,000,000: true count 78,498 vs. estimate 72,382
  • At 10,000,000: true count 664,579 vs. estimate 620,421
  • The logarithmic integral tracks the true count more closely than x / ln(x)
  • Average gap between primes: 4.00 near 100, 12.74 near a million, 15.05 near ten million
The x / ln(x) estimate always undershoots in these examples — by more than 6,000 at a million and more than 44,000 at ten million. Use it as a quick guide, then check the exact sieve count.

Prime gaps and thinning

Primes do not run out, but they spread out. The average gap between consecutive primes grows as you look at larger numbers, and that growth is the clearest everyday sign of how primes thin out. Near 100, the average gap is 4.00. Near one million it is 12.74, and near ten million it is 15.05. Each step up in size buys you fewer primes per stretch of numbers, and the stretches between them get longer.

The thinning follows a familiar shape: roughly like the natural logarithm of the number you are examining. That is why a prime counting function calculator is useful for checking the pattern rather than guessing at it. The prime number theorem estimate x / ln(x) captures the trend but falls short of the exact count. At one million, pi(1,000,000) is 78,498, while x / ln(x) gives 72,382. At ten million, the true count is 664,579 and the estimate is 620,421, still visibly below the exact figure. The gap between estimate and reality does not shrink away; it is a known feature of the approximation.

What does this mean if you need a prime near a given size? Plan for wider spacing. Around 100, primes are dense enough that a short scan finds one quickly: there are exactly 25 primes at or below 100, and 10 of them lie between 50 and 100. Around one million, with an average gap of 12.74, you should expect to test more candidates before landing on a prime. Around ten million, where the average gap is 15.05, the search widens further. The top half of the range from one to ten million alone holds 316,066 primes, so there are plenty to find, but they are not evenly sprinkled.

Averages hide variation, so treat these gap figures as a guide, not a guarantee. Some consecutive primes sit close together; others are separated by much more than the average. The counts quoted on this page are exact, produced by the sieve of Eratosthenes rather than an approximation, so you can compare the true totals with the x / ln(x) estimate directly. Use the average gaps to set expectations, then let the exact counts confirm what is actually there.

  • Average gap near 100: 4.00
  • Average gap near one million: 12.74
  • Average gap near ten million: 15.05
  • pi(1,000,000) = 78,498; x / ln(x) estimate = 72,382
  • pi(10,000,000) = 664,579; estimate = 620,421
Primes thin out like ln(x): the average gap rises from 4.00 near 100 to 12.74 near a million and 15.05 near ten million, so expect to test more candidates as the numbers grow.

FAQs

How many primes are there below 100?

There are exactly 25 primes below 100. Of those, 10 fall between 50 and 100, so the lower half of the range holds the other 15. This small case is a good sanity check for any prime counting tool: if a calculator returns anything other than 25 for the count at or below 100, something is wrong.

How many primes are there below a million?

There are 78,498 primes below one million. The simple estimate x / ln(x) gives only 72,382 for that same range, which is noticeably low. The gap between the estimate and the true count shows why exact counting matters when you need a precise answer rather than a rough approximation.

How many primes are there below ten million?

There are 664,579 primes below ten million. Of those, 316,066 lie between five and ten million, so nearly half of all primes under ten million appear in that upper stretch. The count keeps growing steadily, but each new block of numbers adds fewer primes than the block before it.

What does pi(x) mean?

pi(x) is the prime counting function: it tells you how many primes are at or below x. For example, pi(100) = 25 means 25 primes are at or below 100. The symbol is the Greek letter pi, unrelated to the circle constant, and the function counts primes rather than measuring anything about them.

How accurate is x / ln(x)?

The estimate x / ln(x) underestimates throughout this range. At ten million it gives 620,421 against the true count of 664,579. The estimate tracks the real count closely in shape but consistently runs low, so treat it as a quick approximation and use exact counting when you need the precise number of primes.

How far apart are primes near a million?

Near 1,000,000 the average gap between consecutive primes is 12.74. Near 10,000,000 that average grows to 15.05. So primes thin out as numbers get larger, and the typical spacing between neighbors increases slowly but steadily as you move up the number line.

Sources

Related calculators

Prime Factorization Calculator
Break any whole number up to a trillion into its prime factors — with divisor count, divisor sum and largest prime factor.
Prime Number Calculator
Primality by trial division, the full prime factorization of composites, and the neighbouring primes on either side.
Factorial Calculator
Exact factorials up to 170! computed with arbitrary-precision integers — no scientific-notation rounding — with the digit count and trailing zeros (Legendre's formula) explained.