Refactoring involves restructuring existing code without changing its external behavior in order to improve the internal design, understandability, and maintainability of software. The key benefits of refactoring include making code easier to understand and modify over time, helping to find and fix bugs, and allowing software to be developed more rapidly by preventing design decay. Refactoring should be done when adding new code, fixing bugs, during code reviews, and on an ongoing basis to keep software designs high quality.