Code refactoring involves restructuring existing code without changing its external behavior to improve qualities like readability, maintainability and extensibility. It involves techniques like extracting methods, consolidating conditional logic, simplifying method calls, generalizing classes and hierarchies, and separating concerns. Refactoring helps reduce defects, improve design, and make code easier to understand and modify over time. It should be done iteratively and tests ensured to pass after each small refactoring step.