# Basic Modular Exponentiation reasoning

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?

-

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.