Check if any number is prime with instant Miller-Rabin primality test. Find the next and previous primes, detect twin primes, batch-check a list of numbers, and see a Sieve of Eratosthenes visualisation for all primes up to 200.
Type any positive integer. The tool instantly tests it for primality. For large numbers it uses an efficient deterministic test. The result shows prime or composite, the next prime above, the previous prime below, and whether it forms a twin prime pair (differ by 2 from another prime).
Toggle to batch mode and paste a list of numbers (comma or line separated) to check all at once. Results are shown in a table with prime/composite status, number of divisors (for composites), and smallest prime factor. Download results as CSV.
The interactive sieve grid shows all numbers from 2 to 200. Primes are highlighted in blue. You can watch the sieve animate — each prime strikes out all its multiples. Hover any cell to see the number's factorisation. The sieve is one of the oldest known algorithms (≈240 BC).
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29… The number 2 is the only even prime. There are infinitely many primes (proved by Euclid around 300 BC): if you list all primes p₁, p₂, …, pₙ, then (p₁×p₂×…×pₙ)+1 is either prime or has a prime factor not in the list, contradiction. As of 2024, the largest known prime is 2^136279841 − 1 (about 41 million digits), found by the GIMPS distributed computing project.
Twin primes are pairs of primes that differ by exactly 2: (3,5), (5,7), (11,13), (17,19), (29,31), (41,43), (59,61), (71,73)… The Twin Prime Conjecture, one of mathematics' oldest unsolved problems, states there are infinitely many twin prime pairs. Despite significant progress (Yitang Zhang proved in 2013 that there are infinitely many prime pairs differing by at most 70 million, later reduced to 246), the conjecture remains unproven. The largest known twin prime pair has over 388,000 digits.
To find all primes up to n: Write all integers from 2 to n. Start with p=2 (first prime). Cross out all multiples of p (4, 6, 8…) that are greater than p. Find the next uncrossed number — this is the next prime. Repeat until p² > n. All uncrossed numbers are prime. The sieve runs in O(n log log n) time, making it very efficient for finding all primes up to a given limit. The algorithm was described by the Greek mathematician Eratosthenes of Cyrene around 240 BC and remains one of the most efficient ways to generate all primes up to a bound.
The Miller-Rabin test is a probabilistic primality test that is much faster than trial division for large numbers. For a number n, it checks: write n−1 = 2^s × d. For several random bases a, compute a^d mod n and check specific conditions. If any condition fails, n is definitely composite. If all conditions pass for enough bases, n is very likely prime. For n < 3,215,031,751, testing bases {2, 3, 5, 7} gives a deterministic result. This calculator uses a deterministic set of bases covering all numbers up to 3.3 × 10²⁴ — no false positives are possible.
The prime counting function π(x) counts how many primes are ≤ x. The Prime Number Theorem (proved independently by Hadamard and de la Vallée Poussin in 1896) states that π(x) ≈ x/ln(x) for large x. This means primes become rarer as numbers get larger, but never disappear. More precise: π(100)=25, x/ln(x)≈21.7. π(1000)=168, x/ln(x)≈144.8. The Li(x) (logarithmic integral) is an even better approximation. The Riemann Hypothesis, if proved, would give the most precise known error bounds for π(x).
A composite number is a positive integer greater than 1 that has at least one factor other than 1 and itself. The smallest composite is 4 = 2×2. Every composite number can be expressed as a product of primes (Fundamental Theorem of Arithmetic). To test if n is composite, you only need to check for factors up to √n — if no factor is found up to √n, then n is prime. For example, to test 97: √97 ≈ 9.8. Test primes 2, 3, 5, 7 — none divide 97. Therefore 97 is prime. The number 1 is neither prime nor composite by definition.