Nth prime calculator
Find the prime at any position in the list of primes: the 10th prime is 29, counting 2 as the first. Any position from 1 to 100,000 works, and the answer is exact every time. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 10
- Prime
- 29
- Index
- 10
- Max n
- 100,000
The n-th prime calculator answers a classic number-theory question: which prime sits at position n when primes are listed in increasing order starting at two? Give a one-based index — one for the first prime, two for the second, and so on — and the tool returns that prime exactly. It uses a deterministic sieve of Eratosthenes sized by a proven upper bound on the n-th prime, so the same index always yields the same value with no floating-point guessing, no random sampling, and no network call.
What the n-th prime is and what you get
By convention the sequence of primes begins 2, 3, 5, 7, 11, and so on. The index n is one-based: n equals one returns two, n equals two returns three, and n equals ten returns twenty-nine. That ordering is the same one used in textbooks, OEIS A000040, and programming contest problems that ask for the k-th prime.
This calculator returns the requested index, the prime itself as an integer, a redundant index field for callers that prefer an explicit name, and the published maximum supported n so clients can validate before they send a batch. If you need factors of a known integer rather than the prime at a rank, use a factorization tool instead; this page answers only the rank-to-prime question.
How the index is read and how the sieve stays exact
Optional leading plus signs are allowed; embedded spaces, hex prefixes, and exponential notation are rejected with a clear message so a bad cell does not become a wrong prime. To size the sieve, the implementation uses a classical upper bound on the n-th prime for n at least six — roughly n times the sum of the natural log of n and the log of that log — with a small additive cushion, then runs the sieve of Eratosthenes and collects primes until the n-th is known.
For the tiny indices below six a fixed ceiling covers the first few primes without special cases in the bound formula.
Where rank-based primes fit in study, code, and teaching
Teachers can pre-generate answer keys for a problem set without trusting floating-point calculators that blur large integers. Developers call the same contract from scripts to seed hash-table sizes, to build deterministic test vectors for number-theory helpers, or to satisfy programming-challenge statements that demand the exact k-th prime rather than the next prime after a bound. Contest practice often needs a fast, offline source of ranked primes so solutions can be checked without downloading tables.
What you can do with it
Homework and exam preparation
Look up the exact n-th prime for textbook exercises and contest problems that list primes by rank rather than by magnitude.
FAQ
What does the nth prime calculator cost?
It is free in your browser on this page.
Is the first prime 2 or is indexing zero-based?
Indexing is one-based and the first prime is 2.
What is the maximum n I can request?
The supported range is 1 through 100000 inclusive. Larger indices fail with a clear message that n exceeds the supported range.
Is the algorithm randomized?
No. It uses a deterministic sieve of Eratosthenes sized by a fixed upper bound on the n-th prime. The same n always yields the same prime.
How is this different from prime factorization?
Factorization splits a given integer into prime powers. This tool goes the other way: you supply a rank n and receive the prime that sits at that position in the ordered list of primes.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/numth/nth-prime \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":10}'const res = await fetch("https://api.kit.forhosting.com/numth/nth-prime", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 10
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/nth-prime",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 10
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/nth-prime", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":10}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":10}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/nth-prime", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 10
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.nth_prime",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_n | 100000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
What the n-th prime means and what the response contains
There is no probabilistic Miller–Rabin step and no approximate prime-number-theorem estimate presented as truth: the engine either finds the exact prime inside the supported range or rejects the input with invalid_input. Rejected cases include missing n, non-integers, fractions, scientific notation, values below one, and values above the documented ceiling.
How the index is read and how the sieve stays exact
The preferred field is n as a JSON integer, but decimal strings and the aliases index and k are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. The engine enforces a hard maximum of one hundred thousand on n, which keeps memory and latency inside a predictable budget on the free browser path and on the edge Worker: the one-hundred-thousandth prime is a bit over one million, and a sieve of that size finishes quickly in modern JavaScript.
Where rank-based primes fit in study, code, and teaching
Students use the n-th prime when a worksheet asks for the fifteenth prime, when they plot p_n against n ln n to see the prime-number theorem visually, or when they verify that twin-prime gaps sit at known ranks. On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result.
Integration use cases
Deterministic test fixtures
Generate reproducible prime sequences for unit tests, property checks, and CI assertions without embedding large static tables.
Teaching the prime-number theorem
Compare p_n with n ln n for increasing ranks and show how the sieve result tracks classical asymptotic estimates.