Prime Number Generator
Generate prime numbers in any range, find the first N primes, or check whether a specific number is prime. Includes factorization, twin prime detection, and Mersenne prime marking. Free, private, and runs entirely in your browser.
Configure Generation
Choose a mode, set your parameters, and click Generate to see prime numbers.
What does this Prime Number Generator do?
This free online prime number generator finds prime numbers in any range, lists the first N primes, or checks whether a specific number is prime. It uses the Sieve of Eratosthenes — one of the oldest and most efficient algorithms for finding all primes up to a given limit.
A prime number is a natural number greater than 1 that has exactly two factors: 1 and itself. Examples include 2, 3, 5, 7, 11, 13, and so on. Numbers with more than two factors are called composite numbers. The number 1 is neither prime nor composite.
Beyond simple generation, this tool automatically detects twin primes (pairs of primes that differ by 2) and Mersenne primes (primes of the form 2^n − 1). It also factors any number into its prime components, showing you exactly why a number is or isn't prime.
Everything runs locally in your browser. The numbers you enter never leave your device — no server, no logs, no tracking. Generate as many lists as you want, with no limits and no signup.
How to generate prime numbers
- Choose a mode: Select Range (primes between two numbers), First N (the first N primes), or Check a Number (test primality and see factorization).
- Enter your parameters: For range mode, set the start and end values. For first N mode, enter how many primes you want. For check mode, enter a single number.
- Click Generate: The tool instantly computes the primes and displays them as colour-coded chips.
- Review highlights: Twin primes appear in amber, Mersenne primes in purple. Numbers that are both twin and Mersenne get a gradient highlight.
- Copy or download: Use the toolbar buttons to copy the list to your clipboard or download it as a text file.
That's it. No signup, no email, no waiting. The entire process takes seconds.
How prime numbers are generated
This tool uses the Sieve of Eratosthenes, a simple and elegant algorithm developed by the ancient Greek mathematician Eratosthenes around 240 BCE. It works by iteratively marking the multiples of each prime as composite.
2. Start with p = 2, the smallest prime
3. Mark all multiples of p (2p, 3p, 4p, …) as composite
4. Find the next unmarked number > p — it's the next prime
5. Repeat from step 3 until p² > N
6. All remaining unmarked numbers are prime
For checking a single number, the tool uses trial division: test divisibility by all primes up to √n. If none divide evenly, the number is prime. This is efficient for individual checks and also produces the full prime factorization.
Why the sieve is fast
Rather than testing each number individually (which would require O(n√n) operations), the sieve marks composites in bulk. Its time complexity is O(n log log n) — for n = 1,000,000, that's roughly 3 million operations instead of 1 billion. This is why the tool can generate all primes up to a million almost instantly.
Types of prime numbers
Mathematicians have identified many special categories of primes. This tool highlights two of the most well-known types directly in your results.
| Type | Definition | First few examples |
|---|---|---|
| Regular primes | Any natural number > 1 with exactly two factors | 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 |
| Twin primes | Pairs of primes that differ by exactly 2 | (3,5), (5,7), (11,13), (17,19), (29,31) |
| Mersenne primes | Primes of the form 2^n − 1 where n is also prime | 3 (2²−1), 7 (2³−1), 31 (2⁵−1), 127 (2⁷−1) |
| Sophie Germain primes | Primes p where 2p + 1 is also prime | 2, 3, 5, 11, 23, 29, 41, 53 |
| Palindromic primes | Primes that read the same forwards and backwards | 2, 3, 5, 7, 11, 101, 131, 151 |
| Emirp primes | Primes whose reverse is a different prime ("prime" backwards) | 13, 17, 31, 37, 71, 73, 79, 97 |
Twin primes in detail
Twin primes are pairs like (3, 5), (11, 13), and (41, 43). The Twin Prime Conjecture — that there are infinitely many such pairs — is one of the oldest unsolved problems in mathematics. In 2013, Yitang Zhang proved that there are infinitely many prime pairs with a gap of at most 70 million; later work reduced this bound to 246. But proving the gap is exactly 2 remains open.
Mersenne primes in detail
Mersenne primes take the form 2^n − 1. Not every n works — n must itself be prime, and even then, most give composite results. As of 2024, only 52 Mersenne primes have been discovered. The largest known prime number is always a Mersenne prime, because there's a specialised test (the Lucas-Lehmer test) that makes them far easier to verify than other numbers of similar size.
How prime numbers are distributed
Primes become rarer as numbers get larger, but they never run out — Euclid proved over 2,000 years ago that there are infinitely many primes. The Prime Number Theorem describes how quickly they thin out: the number of primes up to x is approximately x / ln(x).
| Range | Approx. count of primes | Density |
|---|---|---|
| Up to 100 | 25 | 25% |
| Up to 1,000 | 168 | 16.8% |
| Up to 10,000 | 1,229 | 12.3% |
| Up to 100,000 | 9,592 | 9.6% |
| Up to 1,000,000 | 78,498 | 7.8% |
| Up to 10,000,000 | 664,579 | 6.6% |
Notice how the density steadily declines. By the time you reach 10 million, less than 7% of numbers are prime. But the absolute count keeps growing — there are always more primes to find, just spread further apart.
Why use this prime number generator?
Instant results
No server round-trip means your primes appear the moment you click Generate. Zero waiting.
Twin & Mersenne detection
Automatically highlights twin primes and Mersenne primes in your results with colour-coded chips.
Full factorization
Check any number and see its complete prime factorization, not just whether it's prime.
100% private
Everything runs in your browser. The numbers you enter never leave your device.
No limits
Generate as many lists as you want. No daily caps, no watermarks, no "upgrade to pro".
Works offline
Once the page loads, you can generate primes without an internet connection. Bookmark it for exam prep.
What can you use prime numbers for?
Education and learning
- Homework help — verify your prime lists and check factorization
- Explore patterns in prime distribution and gaps
- Study twin primes, Mersenne primes, and other special types
- Practice mental math by predicting the next prime
Cryptography
- Understand the foundations of RSA encryption, which relies on large primes
- Generate small primes for testing cryptographic algorithms
- Explore how prime factorization becomes harder as numbers grow
Programming and math
- Test prime-checking functions in your own code
- Generate test data for algorithms involving primes
- Verify results from your own sieve implementations
- Benchmark performance of different prime algorithms
Recreational mathematics
- Search for twin primes and record-setting gaps
- Find palindromic primes and emirps
- Explore the distribution of primes in different ranges
Tips for working with primes
- Start small. If you're learning, generate primes up to 100 first. Once you see the pattern, try 1,000, then 10,000.
- 2 is the only even prime. Every other prime is odd. This is why the sieve can skip even numbers after marking 2.
- Use the range mode for gaps. Generating primes between 100 and 200, for example, shows you exactly how far apart consecutive primes can be.
- Check factorization to understand composites. If a number isn't prime, the tool shows its prime factors — which is often more instructive than just knowing it's composite.
- Watch for twin primes. As numbers grow larger, twin primes become rarer. Try generating a large range and see how many you find.
- Remember: 1 is not prime. It has only one factor, not two. This is one of the most common mistakes students make.