Math Guides • • By Prime Number Calculator Team • ⏱ 12 min read

How to Check If a Number Is Prime: Easy Steps & Quick Tricks

Learn how to tell if any number is prime using the square-root shortcut, fast mental math tricks, the skip-by-6 rule, and step-by-step examples.

How to Check If a Number Is Prime: Easy Steps & Quick Tricks
Illustration: How to Check If a Number Is Prime: Easy Steps & Quick Tricks

Checking if a number is prime is one of the first big skills you learn in math—and it shows up everywhere from school worksheets to job coding interviews and internet security.

In this plain-English guide, you will learn:

  1. What a prime number really is (and how 1, primes, and composite numbers differ)
  2. Why you can stop checking factors at the square root
  3. Fast mental math shortcuts for checking small numbers in your head
  4. The 6k ± 1 shortcut that lets computers skip two-thirds of all work
  5. Clear walkthroughs of tricky numbers like 91 and 119
  6. Ready-to-run Python and JavaScript code

1. What Makes a Number Prime?

A prime number is a whole number greater than 1 that has exactly two whole-number factors: 1 and itself.

Here are the first 25 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

Three Groups of Whole Numbers

Every positive whole number belongs to one of three buckets:

  • The number 1: Has only one factor (1 itself). Because it does not have two different factors, 1 is neither prime nor composite.
  • Prime numbers (2, 3, 5, 7, …): Have exactly two factors (1 and the number itself). Think of them as the basic building blocks of all bigger numbers.
  • Composite numbers (4, 6, 8, 9, …): Have three or more factors. You can always split them into primes multiplied together (for example, 6 = 2 × 3, 12 = 2 × 2 × 3).

Remember 2: The number 2 is the smallest prime number and the only even prime. Every other even number (4, 6, 8, 10, ...) divides evenly by 2, so none of them can be prime.


2. The Square-Root Shortcut: Where to Stop Checking

When people first try to check a number like 97 or 1,001, they often think they have to test dividing by every number all the way up to 96 or 1,000. That takes way too long!

Here is the secret: you never have to test numbers larger than the square root (√n).

The Rule: If a number n has a factor other than 1 and itself, at least one of its prime factors must be less than or equal to √n.

Rectangle diagram showing why factor checking stops at the square root of n
Figure 1: Picture factors as sides of a rectangle with area n = a × b. If one side grows past √n, the matching side must shrink below √n.

Why This Works (Using a Simple Rectangle)

Imagine drawing a rectangle whose total area equals your number n, made from two whole-number side lengths a × b:

  1. Suppose a number can be split into two factors: n = a × b, where both a and b are bigger than 1.
  2. What if both sides were bigger than √n?
  3. Then multiplying them together would give: a × b > √n × √n = n.
  4. That is impossible! You cannot multiply two numbers bigger than √n and get n.
  5. So at least one factor must be ≤ √n.

And since any factor itself breaks down into prime factors, checking just the prime numbers up to √n tells you the whole truth. If none of them divide evenly into n, your number is 100% prime.


3. Fast Mental Math Tricks (Divisibility Shortcuts)

For everyday two- and three-digit numbers, you can rule out small factors in seconds without touching a calculator:

Dividing by Easy Mental Math Trick Quick Example
2 Look at the last digit. If it ends in 0, 2, 4, 6, or 8, it divides by 2. 348 ends in 8 → divides by 2.
3 Add all the digits together. If that sum divides by 3, so does the number. 351: 3 + 5 + 1 = 9. 9 divides by 3 → so 351 does too.
5 Look at the last digit. If it is 0 or 5, it divides by 5. 415 ends in 5 → divides by 5.
7 Double the last digit and subtract it from the rest of the digits. Repeat if needed. 343: 34 − (2 × 3) = 28. Since 28 = 7 × 4, 343 divides by 7.
11 Add and subtract the digits back and forth (+ − + −). If you land on 0 or a multiple of 11, it divides by 11. 891: 8 − 9 + 1 = 0 → divides by 11.

4. The “Next Door to 6” Shortcut (6k ± 1)

Even if you skip even numbers and only test odds (3, 5, 7, 9, 11, 13, 15, ...), you still waste effort checking multiples of 3 like 9, 15, 21, and 27.

Look what happens when you group every whole number by sets of 6:

Six-slice wheel showing why primes above 3 only land on 6k - 1 or 6k + 1
Figure 2: The 6-step wheel. Every prime greater than 3 sits just 1 step before or 1 step after a multiple of 6, letting you skip 4 out of 6 numbers.

Every positive whole number lands in one of six repeating spots:

  • 6k (like 6, 12, 18): divides by 6 → not prime
  • 6k + 1 (like 7, 13, 19): could be prime!
  • 6k + 2 (like 8, 14, 20): even → divides by 2
  • 6k + 3 (like 9, 15, 21): divides by 3
  • 6k + 4 (like 10, 16, 22): even → divides by 2
  • 6k + 5, same as 6k − 1 (like 5, 11, 17): could be prime!

Why This Saves Time

Every prime number larger than 3 must sit at 6k − 1 or 6k + 1.

So after checking 2 and 3, a computer program can jump forward in steps of 6 (5, 11, 17, 23, 29, ...) and check only d and d + 2. That immediately skips two-thirds (66.7%) of all possible numbers!

(Careful: sitting next to a multiple of 6 is a clue, not a guarantee! Numbers like 25 = 5 × 5 and 91 = 7 × 13 also land next to multiples of 6, so you still have to divide to be sure.)


5. Step-by-Step Worked Examples

Example 1: Is 97 Prime?

  1. Find the stopping point: √97 is about 9.8, so we only check primes up to 9.
  2. List primes ≤ 9: 2, 3, 5, 7.
  3. Check each one:
    • By 2: 97 is odd → no.
    • By 3: 9 + 7 = 16, not divisible by 3 → no.
    • By 5: Ends in 7, not 0 or 5 → no.
    • By 7: 97 ÷ 7 = 13 with remainder 6 → no.
  4. Answer: Nothing up to 9 divides evenly into 97. 97 is prime!

Example 2: Watch Out for 91 (“Fake Prime”!)

Many students guess 91 is prime because it is odd, doesn’t end in 5, and 9 + 1 = 10 does not divide by 3.

  1. Stopping point: √91 is about 9.5, so check primes up to 9: 2, 3, 5, 7.
  2. Check 2, 3, 5: None work.
  3. Check 7: 91 ÷ 7 = 13 exactly (7 × 13 = 91)!
  4. Answer: 91 is composite, not prime.

Example 3: What About 119?

Another classic quiz trap:

  1. √119 is about 10.9, so check primes up to 10: 2, 3, 5, 7.
  2. Skip 2, 3, 5, then check 7: 119 ÷ 7 = 17 with zero left over!
  3. Answer: 119 is composite (7 × 17).

6. Which Checking Method Should You Pick?

Whether you are solving homework by hand or writing fast code, use this quick chart to choose the best approach for your number size:

Decision guide showing which prime checking method works best by number size
Figure 3: Picking the fastest way to check if a number is prime—from quick mental math up to 19-digit numbers.

7. Ready-to-Use Code (Python & JavaScript)

Python (6k ± 1 Fast Check)

import math

def is_prime(n: int) -> bool:
    """Checks if n is prime using the 6k ± 1 square-root shortcut."""
    if n <= 1:
        return False
    if n <= 3:
        return True
    # Rule out multiples of 2 and 3 right away
    if n % 2 == 0 or n % 3 == 0:
        return False

    limit = math.isqrt(n)
    # Check 5, 7, 11, 13, 17, 19... up to sqrt(n)
    for d in range(5, limit + 1, 6):
        if n % d == 0 or n % (d + 2) == 0:
            return False

    return True

print(is_prime(97))    # True
print(is_prime(91))    # False (7 * 13)
print(is_prime(1009))  # True

JavaScript (6k ± 1 with BigInt for Big Whole Numbers)

export function isPrime(n) {
  const num = BigInt(n);
  if (num <= 1n) return false;
  if (num <= 3n) return true;
  if (num % 2n === 0n || num % 3n === 0n) return false;

  // Step forward by 6 and test d and d + 2
  for (let d = 5n; d * d <= num; d += 6n) {
    if (num % d === 0n || num % (d + 2n) === 0n) {
      return false;
    }
  }
  return true;
}

8. Quick Questions & Answers

What is the smallest prime number?

The smallest prime number is 2. It is also the only even prime number.

Is 1 a prime number?

No. A prime number must have two different positive factors (1 and itself). Since 1 only has one factor (1), it is neither prime nor composite.

How do computers check huge 15- or 19-digit numbers so quickly?

Once a number passes roughly 10 million, dividing one number at a time becomes slow. Instead, our calculator switches to a 7-number fast prime test (called Miller-Rabin) that checks numbers up to 18 quintillion (2⁶⁴) in less than a millisecond—with 100% accuracy and zero guesswork.


Helpful Calculators

Try It Yourself

Want to check a prime number right now?

Our free online calculator checks numbers up to 18 quintillion with 100% accuracy, giving you instant factor trees and clear step-by-step reasons.

Open Calculator →
π
Prime Number Calculator Team
Math Education & Software Team

Written in plain, friendly English and checked against trusted math research and automated tests.

More Articles You Might Like