The building blocks of all numbers — explained through stunning animations. Watch the Sieve of Eratosthenes in action, check any number, and discover why primes matter.
// WHAT YOU'LL LEARN
// DEFINITION
A prime number is a whole number greater than 1 that has exactly two factors: 1 and itself.
It cannot be divided evenly by any other number. If you try, you'll always get a remainder.
// METHODS · 3 WAYS TO FIND PRIMES
There are three main methods. We will explore each one with animations below!
Best for finding ALL primes up to a limit. Cross out multiples one by one. Fast and fun!
ANIMATED BELOW ↓🔍METHOD 2Best for checking ONE number. Divide by 2, 3, 4, 5... up to √n. If none divide evenly, it is prime!
INTERACTIVE BELOW ↓🌳METHOD 3Break a number into its prime factors. If the only factors are 1 and itself, it is prime!
ANIMATED BELOW ↓// METHOD 1 · 2000+ YEARS OLD
Imagine pouring numbers through a kitchen sieve! We cross out numbers that are NOT prime, one by one. Whatever is left at the end are the prime numbers. Watch the animation below — it will guide you step by step, just like a teacher!
When you pour pasta through a sieve, only the right pieces pass through. Here, we pour all numbers 1–100 through our sieve. We cross out the "non-prime" numbers one by one. Whatever is left at the end — those are our prime numbers!
Press PLAY to start the sieve!
// FLOWCHART · ALGORITHM VISUALIZATION
Press PLAY to trace the algorithm through the flowchart.
// PSEUDOCODE · EXECUTION FLOW
Press PLAY to step through the algorithm line by line.
// HOW IT WORKS — STEP BY STEP
1 is special — it is NOT prime. So we cross it out first.
2 is the first prime! Cross out all multiples of 2: 4, 6, 8, 10, 12...
Move to 3. It is not crossed out, so it is prime! Cross out 9, 15, 21...
Keep going until √100 = 10. All uncrossed numbers that remain are PRIME!
Because if a number has a factor bigger than its square root, it must also have a factor smaller than the square root. So if we have crossed out all multiples of primes up to 10, every composite number up to 100 has already been crossed out!
// METHOD 2 · TRIAL DIVISION
Trial Division is the simplest way to check if a single number is prime. Just divide the number by 2, 3, 4, 5... all the way up to its square root. If none of them divide evenly, the number is PRIME! Try it below:
// FLOWCHART · ALGORITHM VISUALIZATION
Press PLAY to trace the algorithm through the flowchart.
// PSEUDOCODE · EXECUTION FLOW
Press PLAY to step through the algorithm line by line.
// METHOD 3 · FACTORIZATION TREES
Break a number into its prime factors. If the only factors are 1 and itself, it is prime! Watch the factors appear one by one:
// FLOWCHART · ALGORITHM VISUALIZATION
Press PLAY to trace the algorithm through the flowchart.
// PSEUDOCODE · EXECUTION FLOW
Press PLAY to step through the algorithm line by line.
// PROPERTIES
A prime number has exactly two divisors: 1 and itself. No more, no less.
Every integer greater than 1 is either prime or can be built by multiplying primes together.
There is no largest prime. Euclid proved there are infinitely many primes over 2000 years ago.
Primes appear irregularly on the number line — no simple formula generates all primes.
// DID_YOU_KNOW
Every other even number is divisible by 2, making them composite.
By definition, primes must have exactly two distinct factors. 1 has only one.
It is 2⁸²⁵⁸⁹⁹³³ − 1, discovered in 2018 by the Great Internet Mersenne Prime Search.
Like (3,5), (11,13), (17,19). The Twin Prime Conjecture says there are infinitely many.
RSA encryption, which secures internet communication, relies on the difficulty of factoring large primes.
Ancient Greek mathematician Eratosthenes invented this algorithm to find all primes up to any limit.
// PRACTICE & ASSESS
Now that you've learned the concept, put it into practice. Solve coding problems and take quizzes to reinforce what you've learned.
// TUTORIAL QUIZZES · LEVELS 1–9
Nine progressive quizzes from Level 1 to Level 9. Each has 10 questions with a 10-minute timer. XP scales with level — L1 gives 10 XP, L9 gives 90 XP. Click a quiz to expand and begin.
// REFERENCES
// READY?
Practice 10,000+ coding problems, follow career roadmaps, and get hired.