Euclidean Algorithm Visualizer illustration

Euclidean Algorithm Visualizer

Euclid’s algorithm for the greatest common divisor has a beautiful geometric form: to find gcd(a, b), tile an a×b rectangle with the largest squares that fit, then repeat on the leftover strip. The side of the last square that tiles its rectangle perfectly is the gcd. This visualizer draws the rectangle, lays down each round of squares in its own colour and lists the subtraction-and-remainder steps, making the link between the geometry and the usual remainder recursion clear.

Runs 100% in your browser — simulations are computed locally on your device.

Notes

  • gcd(a, b) = gcd(b, a mod b); each step peels off as many squares of the smaller side as fit.
  • The algorithm ends when a square tiles the remaining rectangle exactly — its side is the gcd.
  • Consecutive Fibonacci numbers are the worst case, forcing the most steps for their size.
  • Runs 100% in your browser — simulations are computed locally on your device.