Twin prime checker
3 and 5 are both prime and differ by two, so they form a twin prime pair, just like 11 and 13. Enter a number to check it against the one two places above, or set a limit to list every pair. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 3
- N plus 2
- 5
- Pair
- 3, 5
Twin primes are prime numbers that differ by exactly two: classic pairs include (3, 5), (5, 7), (11, 13), and (17, 19). They sit at the heart of elementary number theory and of the famous twin prime conjecture, which asks whether infinitely many such pairs exist. This tool answers a concrete, local question: given a positive integer n, are both n and n plus two prime? When you also supply a limit, it lists every twin pair whose smaller member is at most that bound, using a deterministic sieve.
What twin primes are and how this checker decides
A twin prime pair is an ordered pair of primes of the form (p, p + 2). The gap of two is the smallest even gap that can separate primes larger than two, because among any three consecutive odds at least one multiple of three often appears, yet many pairs still survive. Famous early examples are (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), and (41, 43).
Primality for a single candidate uses deterministic trial division: reject non-integers and values below two, handle two and three as primes, eliminate multiples of two and three, then walk divisors of the form six-k plus or minus one up to the square root. That algorithm is exact for every safe JavaScript integer and needs no tables, no randomness, and no external primality service. The pair array echoes [n, n + 2] so clients can display the candidate without recomputing the offset.
Where twin-prime checks show up in real work
Contest programmers and olympiad coaches use twin-pair checks as warm-ups before harder gap and sieve problems, and they need a deterministic oracle that students cannot accidentally diverge from a spreadsheet formula. Cryptography and systems engineers sometimes sanity-check small prime tables or teaching demos for expected twin density without claiming cryptographic strength from the twin conjecture itself. If you later need π(n), the full prime list, or factorization of a large composite, treat those as separate search intents rather than overloading this twin-focused landing.
Twin primes stay the right page when the question is whether n and n plus two are both prime, or which twin pairs appear up to a chosen limit.
What you can do with it
Homework and olympiad warm-ups
Verify whether a given n forms a twin pair with n+2, and list classroom pairs up to a bound for sieve worksheets and contest practice.
FAQ
What is a twin prime pair?
A twin prime pair is two primes that differ by two, written (p, p+2). Examples include (3, 5), (5, 7), and (11, 13). This tool tests that property for your n.
Can I list all twin pairs up to a limit?
Yes. Pass optional limit (2 through 1,000,000). The response adds pairs and count for every (p, p+2) with p ≤ limit.
Is the result deterministic?
There is no randomness, network call, or model involved—only trial division and an optional sieve.
What does it cost?
The browser tool is free and runs locally.
Is 3 part of a twin prime pair?
Yes. 3 and 5 are both prime and differ by exactly two, so they form the pair (3, 5). The number 5 also starts its own pair with 7.
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/twin-primes \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":3}'const res = await fetch("https://api.kit.forhosting.com/numth/twin-primes", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/twin-primes",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/twin-primes", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/twin-primes", 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": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.twin_primes",
"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
min_n | 1 |
max_n | 9007199254740991 |
max_list_limit | 1000000 |
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 twin primes are and how this checker decides
This capability takes a positive integer n, tests whether n is prime, tests whether n + 2 is prime, and reports both flags plus a single boolean is_twin_prime that is true only when both tests pass. When n is one, the tool accepts the input but correctly marks is_twin_prime false because one is not a prime number; only values below one are rejected as invalid_input so forms surface a clear bound error instead of a silent nonsense pair.
Input contract, optional listing, and successful replies
The value must be at least one and at most two below the JavaScript safe-integer maximum so that n + 2 stays exact. Decimals, empty fields, and non-numeric strings fail validation and are not charged. When limit is present, the solver builds a Sieve of Eratosthenes up to limit plus two, then walks every integer p from two through limit and records [p, p + 2] whenever both positions are unmarked. The response then includes the original limit, the pairs array, and count equal to the number of twin pairs found. Send a required integer field n (aliases number and value are accepted). Optionally send limit (aliases upto and max) between two and one million inclusive. Spot checks you can trust without a textbook open: n equals three yields is_twin_prime true with pair [3, 5]; n equals eight yields false because eight is composite; n equals one yields false without error; listing with limit one hundred returns the familiar classroom pairs up to (71, 73) and a stable count. API pricing is the published base of $0.002 per successful item; failed validation does not consume balance.
Where twin-prime checks show up in real work
Because the capability is a pure parse engine, the same n and limit always yield the same JSON with no network dependency and no stored state.
Integration use cases
Deterministic fixtures for number-theory demos
Generate stable twin-pair tables for teaching slides, unit tests, and documentation examples without hand-maintaining JSON.
Pipeline-friendly twin checks
Call the same isomorphic contract from scripts and CI so twin-prime assertions never depend on a casual web form or a model.
Technical questions
Does n below 1 cause an error?
Yes. Values of n less than 1 fail with invalid_input. n equals 1 is accepted but is_twin_prime is false because 1 is not prime.