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

  1. Choose a mode: Select Range (primes between two numbers), First N (the first N primes), or Check a Number (test primality and see factorization).
  2. 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.
  3. Click Generate: The tool instantly computes the primes and displays them as colour-coded chips.
  4. Review highlights: Twin primes appear in amber, Mersenne primes in purple. Numbers that are both twin and Mersenne get a gradient highlight.
  5. 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.

Sieve of Eratosthenes — Algorithm
1. Create a list of consecutive integers from 2 to N
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 1002525%
Up to 1,00016816.8%
Up to 10,0001,22912.3%
Up to 100,0009,5929.6%
Up to 1,000,00078,4987.8%
Up to 10,000,000664,5796.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.

Frequently asked questions

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.
This tool uses the Sieve of Eratosthenes algorithm, one of the oldest and most efficient methods for finding all prime numbers up to a given limit. For checking a single number, it uses trial division and produces the full prime factorization. Everything runs locally in your browser.
Twin primes are pairs of prime numbers that differ by exactly 2, such as (3, 5), (5, 7), (11, 13), and (17, 19). This tool automatically detects and highlights twin primes in your results with amber-coloured chips. The Twin Prime Conjecture — that there are infinitely many such pairs — remains unproven.
A Mersenne prime is a prime number of the form 2^n − 1, where n is itself a prime number. Examples include 3 (2²−1), 7 (2³−1), 31 (2⁵−1), and 127 (2⁷−1). This tool marks Mersenne primes in purple. The largest known prime numbers are always Mersenne primes.
Yes. You can generate all primes between any two numbers, find the first N primes, or check whether a specific number is prime. Switch between the three modes using the tabs above the input fields.
The tool handles ranges up to 1,000,000 efficiently. For very large ranges, generation may take a moment, but it will still complete in your browser without needing a server. The first N mode caps at 10,000 primes to keep the display responsive.
The largest known prime as of 2024 is 2^136,279,841 − 1, a Mersenne prime with over 41 million digits. It was discovered by the Great Internet Mersenne Prime Search (GIMPS) project. There is no largest prime — Euclid proved over 2,000 years ago that there are infinitely many.
1 has only one factor (itself), not two. The definition of a prime requires exactly two distinct factors: 1 and the number itself. Excluding 1 is also essential for the Fundamental Theorem of Arithmetic — every integer greater than 1 has a unique prime factorization, but this would break if 1 were counted as prime.
Yes. 2 is a prime number — the smallest, and the only even prime. Its only factors are 1 and 2. Every other prime is odd, which is why prime numbers larger than 2 can be treated as a special case in many algorithms.
Yes, completely free. No signup, no watermark, no hidden charges. Use it as many times as you want, for homework, work, or personal projects.
Absolutely. Everything runs in your browser using JavaScript. The numbers you enter never leave your device — there is no server processing, no logging, and no data storage. Close the tab and it's gone.