Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to understand the modular exponentiation algorithm. Why is it that:

$x^2 \mod5 = (x\mod5)(x\mod5) \mod 5$

What is the basic reasoning behind this?

share|cite|improve this question
up vote 6 down vote accepted

Write $x = m + 5n$ with $0 \leq m \leq 4$. No matter what you multiply $5n$ by, the result will be a multiple of $5$ and subsequently dropped by the "mod $5$" at the end. So, you might as well have dropped the $5n$ to begin with. That is, you could just take $x$ mod $5$ before carrying out the multiplication.

share|cite|improve this answer

I am not sure about the doubt in ur mind but i hope i am answering ur question! The reason for the last mod5 in the rhs is to ensure that the lhs and the rhs are compatible.As the lhs is a residue it is by defn a value between 0 & 5.However if u drop the final mod5 the rhs may not be a residue(note that it is a product of two residues,so not necessarily a residue by itself!). eg x=4 implies lhs =1 without the final mod5 the rhs value=16 !

share|cite|improve this answer
Hi: welcome to math.SE! I just wanted to drop a few tips for better solution writing here. Correct spacing, linebreaks, and spelling are important for making a solution readable. It's also a good rule of thumb to avoid using idiosyncratic abbreviations where possible. People are more likely to read your post and upvote it if it is easy to read! – rschwieb Dec 27 '12 at 17:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.