What is refactoring?

Last reviewed November 8, 2026

Refactoring is changing the internal structure of code to make it easier to understand and change, without changing what it does for users. Martin Fowler, who popularized the term, describes it as a series of small changes, each of which keeps the software working. Renaming something unclear, removing duplicated logic or splitting a long function are all refactorings. Done continuously, refactoring keeps a product cheap to change. Neglected, the code slowly becomes harder to work with, and every new feature takes longer.

Refactoring isn't a Scrum term, but it matters to every Scrum Team that builds software. A team that can't change its code safely can't respond to what it learns at the Sprint Review.

What refactoring is and isn't

ActivityChanges what users see?Is it refactoring?
Renaming a confusing variableNoYes
Combining four copies of the same calculation into oneNoYes
Fixing a bugYesNo, even if done at the same time
Adding a featureYesNo
Rewriting a module from scratchUsually not intended, but oftenNo, it is a rewrite

The key is "without changing behavior". Automated tests are what make that safe. They show, after each small step, that the software still does what it did.

When to refactor

  • Before a change: make the code easy to change, then make the change.
  • After a change: clean up what the change left messy, while it is fresh.
  • When reading code: leave it a little clearer than you found it.

Most refactoring belongs inside the Product Backlog items that need it, not in separate items. A Developer working on a feature refactors the code the feature touches. That keeps refactoring tied to value, and avoids the question "why are we spending a Sprint on cleanup?".

Larger restructuring, which can't fit inside one item, may need its own Product Backlog item, explained to the Product Owner in terms of what it will make faster or safer. See Technical debt in Scrum.

A worked example

How it relates to nearby terms

  • Technical debt: the accumulated cost of shortcuts and outdated design. Refactoring is the main way to pay it down. See Technical debt in Scrum.
  • Rewrite: replacing code with new code. Bigger, riskier, and different from refactoring.
  • Continuous integration: merging and testing changes often, which makes small refactorings safe. See Continuous integration.
  • Definition of Done: some teams include "code left as clear as it was found" in theirs.

Common misunderstandings

"Refactoring needs its own Sprint." Most refactoring is small and belongs inside the items that need it.

"Refactoring adds no value." It adds no feature. Its value is in every future feature that becomes cheaper and safer.

"Any code change is refactoring." Only changes that keep behavior the same. Changing behavior is something else, even if it is done at the same time.

"We can refactor without tests." It is possible, but risky. Without tests, nobody knows if behavior changed.

Questions

What is refactoring in software development?

Changing the internal structure of code to make it easier to understand and change, without changing what it does for users.

Should refactoring be a separate Product Backlog item?

Usually not. Most refactoring belongs inside the items that need it. Larger restructuring may need its own item, explained by what it will make faster or safer.

Does refactoring count toward velocity?

If it is part of an item, it is part of that item's size. If it is a separate item and the team sizes such items, it counts when Done.

What is the difference between refactoring and rewriting?

Refactoring changes the structure in small steps, keeping the software working throughout. Rewriting replaces code with new code, usually in larger steps and with more risk.

How do you convince a Product Owner to allow refactoring?

Show the cost of not doing it in terms they care about: slower changes, more defects, longer estimates. Then tie the refactoring to the items it will make faster.