Code refactoring involves restructuring existing computer code without changing its external behavior, in order to improve non-functional aspects like readability and complexity. It uses techniques like abstraction, encapsulation, and generalization to achieve benefits like increased maintainability and extensibility. Refactoring can also be applied to hardware description languages to improve code structure.