Prime Numbers

A prime number is a number greater than 1 that has no divisors other than 1 and itself. Primes are the fundamental building blocks of all integers.

The Fundamental Theorem of Arithmetic: Every integer greater than 1 can be expressed as a unique product of prime numbers.

The Sieve of Eratosthenes

This ancient algorithm, created over 2,000 years ago, efficiently finds all primes up to a given number. Watch as composites get crossed out:

Click "Run Sieve" or "Step" to begin...

Why Primes Matter for Cryptography

Easy: Multiplication

Given two large primes, multiplying them is fast:

61 × 53 = 3233
(instant computation)

Hard: Factoring

Given the product, finding the primes is hard:

3233 = ? × ?
(must try many divisors)

RSA encryption relies on this asymmetry. The public key contains a large number that is the product of two secret primes. Breaking the encryption requires factoring that number, which is computationally infeasible for large enough primes.

Prime Checker

Check if a number is prime:

Enter a number and click "Check"...

Prime Factorization

See how any number can be broken down into prime factors:

Enter a number to see its factorization...

How Many Primes Are There?

There are infinitely many primes! Euclid proved this around 300 BCE. The proof is elegant:

Euclid's Proof

  1. Assume there are only finitely many primes: p₁, p₂, ..., pₙ
  2. Consider N = (p₁ × p₂ × ... × pₙ) + 1
  3. N is not divisible by any of our primes (it leaves remainder 1)
  4. So N is either prime itself, or divisible by a prime not in our list
  5. Contradiction! There must be infinitely many primes.

The Prime Number Theorem

While primes become rarer as numbers get larger, we know approximately how many primes there are below any given number:

π(n) ≈ n / ln(n)

Where π(n) counts primes less than or equal to n. This means roughly 1 in every ln(n) numbers near n is prime.

For Cryptography: To generate a 1024-bit prime (about 308 digits), we expect to test roughly 700 random odd numbers before finding a prime. Modern computers can do this quickly!