2357111317192329
MATH.ANIMATED · NUMBER THEORY

Prime Numbers Explained with Animations

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

🔍What is a Prime?
Sieve of Eratosthenes
🌳Factorization Trees
Prime Checker Tool
🧪Trial Division Method
📋Properties & Facts
Beginner·15 min·Mathematics / Number Theory
Reviewed by CodeTikki Academic Team

// DEFINITION

What is a
prime number?

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.

PRIME — 7
1
2
3
4
5
6
7
7 ÷ 1 = 7
7 ÷ 7 = 1
7 ÷ 2 = 3.5 ✗
7 ÷ 3 = 2.33 ✗
✓ Only 2 factors → PRIME
COMPOSITE — 8
1
2
3
4
5
6
7
8
8 ÷ 1 = 8
8 ÷ 2 = 4
8 ÷ 4 = 2
8 ÷ 8 = 1
✗ 4 factors → COMPOSITE

// METHOD 1 · 2000+ YEARS OLD

Sieve of
Eratosthenes

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!

🧑‍🍳

Imagine a kitchen sieve (strainer)!

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!

// READY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
PRIME ✅
CROSSING OUT
CROSSED OUT
CURRENT PRIME
1 (special)
Primes found between 1–100
...

// FLOWCHART · ALGORITHM VISUALIZATION

// FLOWCHART · Sieve of Eratosthenes
Find all primes up to n = 100
n = 100
YesNoYesNoStartisPrime[1..n]← all trueisPrime[1] ← falsep ≤ √n ?isPrime[p]= true ?Cross outmultiples of p(from p² to n)Return all iwhere isPrime[i]= trueEndp ← p + 1

Press PLAY to trace the algorithm through the flowchart.

0 / 15

// PSEUDOCODE · EXECUTION FLOW

// PSEUDOCODE · Sieve of Eratosthenes
Find all primes up to n = 100
n = 100
1function sieveOfEratosthenes(n):
2isPrime[1..n] ← true
3isPrime[1] ← false // 1 is not prime
4for p from 2 to √n:
5if isPrime[p] is true:
6for multiple from p² to n step p:
7isPrime[multiple] ← false
8return all i where isPrime[i] = true

Press PLAY to step through the algorithm line by line.

0 / 10

// HOW IT WORKS — STEP BY STEP

1️⃣STEP 01

Cross out 1

1 is special — it is NOT prime. So we cross it out first.

2️⃣STEP 02

Start with 2

2 is the first prime! Cross out all multiples of 2: 4, 6, 8, 10, 12...

3️⃣STEP 03

Next uncrossed

Move to 3. It is not crossed out, so it is prime! Cross out 9, 15, 21...

STEP 04

What is left

Keep going until √100 = 10. All uncrossed numbers that remain are PRIME!

💡

Why do we stop at √100 = 10?

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

Is it prime?
Check any number.

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:

// PRIME_CHECKER.exe

// FLOWCHART · ALGORITHM VISUALIZATION

// FLOWCHART · Trial Division — isPrime(n)
Check if n = 29 is prime
n = 29
YesNoYesNoYesNoYesNoYesNoStartn < 2 ?n = 2 ?n iseven ?i ≤ √n ?n mod i= 0 ?i ← i + 2return falsereturn truereturn falsereturn truereturn false

Press PLAY to trace the algorithm through the flowchart.

0 / 12

// PSEUDOCODE · EXECUTION FLOW

// PSEUDOCODE · Trial Division — isPrime(n)
Check if a single number n is prime
n = 29
1function isPrime(n):
2if n < 2: return false
3if n = 2: return true
4if n is even: return false
5for i from 3 to √n step 2:
6if n mod i = 0: return false
7return true

Press PLAY to step through the algorithm line by line.

0 / 9

// METHOD 3 · FACTORIZATION TREES

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:

// FACTOR_TREE
12=2×2×3
// FACTOR_TREE
60=2×2×3×5
// FACTOR_TREE
97=97

// FLOWCHART · ALGORITHM VISUALIZATION

// FLOWCHART · Prime Factorization
Factor n = 60 into primes
n = 60
YesNoYesNoYesNoStartfactors ← []divisor ← 2divisor²≤ n ?n moddivisor = 0 ?factors.append(divisor)n ← n / divisordivisor ←divisor + 1n > 1 ?factors.append(n)Return factorsEnd

Press PLAY to trace the algorithm through the flowchart.

0 / 18

// PSEUDOCODE · EXECUTION FLOW

// PSEUDOCODE · Prime Factorization
Break n into its prime factors
n = 60
1function primeFactorize(n):
2factors ← []
3divisor ← 2
4while divisor × divisor ≤ n:
5while n mod divisor = 0:
6factors.append(divisor)
7n ← n / divisor
8divisor ← divisor + 1
9if n > 1: factors.append(n)
10return factors

Press PLAY to step through the algorithm line by line.

0 / 17

// PROPERTIES

4 things to
know about primes.

Exactly 2 factors

A prime number has exactly two divisors: 1 and itself. No more, no less.

Building blocks

Every integer greater than 1 is either prime or can be built by multiplying primes together.

Infinitely many

There is no largest prime. Euclid proved there are infinitely many primes over 2000 years ago.

No pattern

Primes appear irregularly on the number line — no simple formula generates all primes.

// DID_YOU_KNOW

Fun facts about
prime numbers.

01

2 is the only even prime number

Every other even number is divisible by 2, making them composite.

02

1 is NOT a prime number

By definition, primes must have exactly two distinct factors. 1 has only one.

03

The largest known prime has 24,862,048 digits

It is 2⁸²⁵⁸⁹⁹³³ − 1, discovered in 2018 by the Great Internet Mersenne Prime Search.

04

Twin primes are pairs that differ by 2

Like (3,5), (11,13), (17,19). The Twin Prime Conjecture says there are infinitely many.

05

Primes are used in cryptography

RSA encryption, which secures internet communication, relies on the difficulty of factoring large primes.

06

The sieve of Eratosthenes is 2000+ years old

Ancient Greek mathematician Eratosthenes invented this algorithm to find all primes up to any limit.

// TUTORIAL QUIZZES · LEVELS 1–9

Test your mastery

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

Sources & further reading

  1. [1]
    Euclid, Elements (Book IX, Proposition 20)Euclid — proof that there are infinitely many primes
  2. [2]
    An Introduction to the Theory of NumbersG. H. Hardy & E. M. Wright
  3. [3]
    The Sieve of EratosthenesEratosthenes of Cyrene (~240 BC)
  4. [4]
    RSA Cryptography Standard (PKCS#1)RSA Laboratories — primes in modern encryption
  5. [5]
    Prime Number TheoremHadwiger (1896) / de la Vallée Poussin — distribution of primes

// READY?

Master math & coding
with CodeTikki.

Practice 10,000+ coding problems, follow career roadmaps, and get hired.