Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. It is a disciplined way to clean up code that minimizes the chances of introducing bugs. In essence, when you refactor, you are improving the design of the code after it has been written.
Martin Fowler provided this definition in one of the quintessential books on the subject: Refactoring: Improving the Design of Existing Code. If you haven’t read this book and you’re interested in learning more about refactoring, I highly recommend it.
Over the years, I’ve completed refactoring projects of varying sizes. I’ve always enjoyed the sense of satisfaction I get from rewriting code to be cleaner (or at least cleaner by my standards).