2 while (n >> shift) != 0: shift += 2 # Unroll the bit-setting loop. result = 0 while shift >= 0: result = result << 1 large_cand = ( result + 1 ) # Same as result ^ 1 (xor), because the last bit is always 0. if large_cand * large_cand <= n >> shift: result = large_cand shift -= 2 return result Traditional pen-and-paper presentations of the digit-by-digit algorithm include various optimisations not present in the code above, in particular the trick of presubtracting the square of the previous digits which makes a general multiplication step unnecessary. See for an example. In programming languages Some programming languages dedicate an explicit operation to the integer square root calculation in addition to the general case or can be extended by libraries to this end. (isqrt x): Common Lisp. math.isqrt(x): Python. See also Methods of computing square roots Notes External links Number theoretic algorithms Number theory Root-finding algorithms