Fermat Primality Test Calculator

Enter a number and a base to run the Fermat primality test.

How to use

  1. Enter your values in the fields above.
  2. Press Calculate to see your result instantly.
  3. Use the Share button to copy a link to your result.

About this calculator

Fermat's little theorem states that if n is a prime number, then for any integer base a not divisible by n, a^(n-1) ≡ 1 (mod n). This calculator runs that check in reverse: given a number n and a chosen base a, it computes a^(n-1) mod n — if the result isn't 1, n is definitely composite; if it is 1, n is only probably prime, since rare composite numbers (Fermat pseudoprimes, and the especially stubborn Carmichael numbers) can pass the test for many or even all bases.

Because it's fast to compute even for large numbers, the Fermat test is used as a cheap first-pass filter in cryptography and computer science education — quickly discarding obvious composites before running slower, more rigorous primality tests like Miller-Rabin, which underpins real-world RSA key generation. It's also a standard exercise in number theory courses for illustrating modular exponentiation and the difference between a necessary and a sufficient condition for primality.

Was this helpful?

Comments (0)

  • Be the first to comment.

Popular calculators

All Calculators