Computer Science Basics

Prime Numbers: A Simple & Complete Guide

7 min readBy OctalOne Team
TL;DR

The Building Blocks of All Numbers

A prime number is a whole number greater than 1 that can only be divided evenly by 1 and itself (e.g., 2, 3, 5, 7, 11). They are the fundamental building blocks of math because every other whole number can be made by multiplying primes together. Today, gigantic prime numbers power the encryption systems that secure online banking, shopping, and passwords!

1. What is a Prime Number?

A prime number is a natural number greater than 1 that has exactly two positive divisors: 1 and the number itself.

In simple words: A prime number can only be divided evenly by 1 and itself. If any other number can divide it exactly without leaving a remainder, it is not a prime number.

Examples of Prime vs. Not Prime

Number 2✅ Prime

Divisors: 1, 2 (Exactly 2 divisors)

Number 3✅ Prime

Divisors: 1, 3 (Exactly 2 divisors)

Number 4❌ Not Prime

Divisors: 1, 2, 4 (3 divisors)

Number 5✅ Prime

Divisors: 1, 5 (Exactly 2 divisors)

Number 6❌ Not Prime

Divisors: 1, 2, 3, 6 (4 divisors)

Number 11✅ Prime

Divisors: 1, 11 (Exactly 2 divisors)

2. Why Isn't 1 a Prime Number?

This is one of the most common questions in mathematics. The definition of a prime number requires exactly two distinct positive divisors.

Let's examine the number 1. How many positive divisors does it have? Only one: 1 itself. Since it has only one divisor—not two—it fails the requirement.

Why this rule matters: If mathematicians considered 1 to be prime, many important mathematical theorems—especially the Fundamental Theorem of Arithmetic (that every number has a unique prime factorization)—would break down or become unnecessarily complicated. Therefore, 1 is neither prime nor composite; it belongs to its own special unit category.

3. What is a Composite Number?

A composite number is any whole number greater than 1 that has more than two divisors. In other words, if a number can be made by multiplying two smaller whole numbers (other than 1 and itself), it is composite.

NumberDivisorsClassification
41, 2, 4Composite
61, 2, 3, 6Composite
81, 2, 4, 8Composite
91, 3, 9Composite
101, 2, 5, 10Composite

4. The First 50 Prime Numbers

Need a quick reference? Here are the first 50 prime numbers:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229

Visual Example: Numbers 1 to 30

1
No
2
Prime
3
Prime
4
No
5
Prime
6
No
7
Prime
8
No
9
No
10
No
11
Prime
12
No
13
Prime
14
No
15
No
16
No
17
Prime
18
No
19
Prime
20
No
21
No
22
No
23
Prime
24
No
25
No
26
No
27
No
28
No
29
Prime
30
No

5. How Can We Tell If a Number Is Prime?

Suppose someone asks: "Is 37 prime?" We check whether any number other than 1 and 37 divides it evenly. Since neither 2, 3, 4, 5, nor 6 divides 37 exactly without a remainder, 37 is prime!

⚡ An Easy Trick: The Square Root Rule

To determine whether a large number is prime, you do not need to test every smaller number! You only need to test divisibility by prime numbers up to the square root of the number.

Example: Is 97 prime?
1. The square root of 97 is roughly 9.8.
2. We only need to check prime divisors up to 9: 2, 3, 5, 7.
3. Since none of these divide 97 evenly, we can stop immediately!
✅ 97 is guaranteed to be prime!

6. Why Are Prime Numbers Important?

Prime numbers are often called the building blocks of numbers because every whole number greater than 1 can be written as a unique multiplication of prime numbers. This is known as prime factorization.

12 = 2 × 2 × 3
18 = 2 × 3 × 3
20 = 2 × 2 × 5
60 = 2² × 3 × 5

Real-Life Applications

🔐 Internet Security & Banking

Whenever you log into your bank, shop online, or send secure messages, encryption systems (like RSA) rely on prime numbers. Multiplying two gigantic prime numbers together is trivial for a computer, but reversing the process (finding those original primes) takes supercomputers thousands of years!

💻 Computer Science & Hashing

Primes are widely used in hash tables, random number generators, error detection algorithms, and data structure optimizations to avoid collisions and distribute data evenly across memory.

7. History & The Sieve of Eratosthenes

The study of prime numbers goes back thousands of years. Around 300 BCE, the Greek mathematician Euclid proved an astonishing result in his work Elements: There are infinitely many prime numbers. No matter how high you count, you will never run out of primes!

Around 240 BCE, another Greek mathematician named Eratosthenes invented a clever algorithm known as the Sieve of Eratosthenes for finding all primes up to a chosen limit:

  1. Write down all whole numbers from 2 up to your desired limit.
  2. Start with 2 (the first prime) and cross out all of its multiples (4, 6, 8, 10...).
  3. Move to the next uncrossed number (3) and cross out all of its multiples (6, 9, 12...).
  4. Repeat this process. All numbers remaining uncrossed at the end are prime numbers!

8. 6 Interesting Facts About Primes

1. 2 is the ONLY Even Prime

Every other even number can be divided by 2, automatically disqualifying it from being prime.

2. Primes Spread Out

As numbers get larger, prime numbers become less common, but the gaps between them behave unpredictably.

3. Twin Primes

Some prime pairs differ by only 2 (e.g., 3 & 5, 11 & 13, 17 & 19, 29 & 31). Whether there are infinitely many twin primes is still an unsolved mystery!

4. Mersenne Primes

Primes taking the form 2ⁿ − 1 (like 3, 7, 31, 127) are called Mersenne primes. Most of the largest known primes in the world belong to this family.

5. Millions of Digits

The largest known prime number discovered by computers today contains well over 24 million digits!

6. Cicada Lifecycles

Certain species of cicadas stay underground for exactly 13 or 17 years (both prime numbers) to prevent predators from synchronizing with their lifecycle!

9. Common Mistakes to Avoid

Mistake 1: Assuming 1 is prime

Remember, a prime number must have exactly two distinct divisors. 1 has only one divisor.

Mistake 2: Assuming all odd numbers are prime

Numbers like 9, 15, 21, 25, 27, and 35 are all odd, but they are composite numbers because they can be divided by 3, 5, or 7.

Mistake 3: Checking every single smaller number

When checking if a number is prime, you can stop testing as soon as you reach the square root of that number!

10. Practice Questions

Test yourself! Try deciding whether each number below is Prime or Composite before checking the answers.

13
21
29
35
41
51
73
91
97
121

🔑 Answer Key & Explanations

13Prime
21Composite (3 × 7)
29Prime
35Composite (5 × 7)
41Prime
51Composite (3 × 17)
73Prime
91Composite (7 × 13)
97Prime
121Composite (11 × 11)

Explore Encryption & Data Tools

Prime numbers are the backbone of modern data encoding and security. Explore our online tools to see how data is securely transformed and decoded in web applications!