To compute , you could multiply eight times. But notice: . You only need three squaring operations instead of seven multiplications.
When is even, use . When is odd, use . Each step reduces the exponent, moving toward the base case (which returns ).
How many steps does this take? You halve each time (roughly), so you need steps. This is exponentiation by squaring.