Technical Guide

SonarQube Technical Debt Ratio: What It Measures and Where It Misleads

How SonarQube calculates technical debt, the technical debt ratio and the maintainability rating, what the A to E grades really mean and where they mislead.

Abstract illustration of a code quality gauge moving from grade A to grade E above stacked blocks of source code

In this article:

What SonarQube means by technical debt

Open any SonarQube project and you will see a debt figure in hours or days, a percentage and a letter. Teams quote the letter in planning meetings, investors ask for it in data rooms, and managers put it on slides. Few people who quote it know how it is produced.

SonarQube technical debt has a narrow, precise definition: the estimated time needed to fix every maintainability issue the analyser has found. Each rule in the active quality profile carries a remediation estimate, either a fixed effort per issue or an effort that grows with the size of the problem. SonarQube adds up those estimates and displays the total, converting minutes into days on the basis of a standard working day.

That is very different from technical debt in the wider sense. Ward Cunningham’s metaphor covers every shortcut that makes future change more expensive: a wrong service boundary, a shared database, a missing test suite, an outdated framework. SonarQube measures only what a static analyser can see inside individual files, mostly the patterns described in our guide to code smells.

Recent releases reorganised issues around software qualities (maintainability, reliability, security), but the principle has not changed. The debt figure comes from maintainability issues. Bugs and vulnerabilities feed separate reliability and security ratings, which are based on issue severity rather than on a ratio.


How the technical debt ratio is calculated

The raw debt figure is hard to interpret on its own. Two hundred days of debt is a lot for a small service and very little for a ten-year-old ERP. The technical debt ratio puts the debt in proportion to the size of the codebase:

Technical debt ratio = remediation cost / development cost

The remediation cost is the debt figure described above. The development cost is an estimate of what it would take to write the code again: the number of lines of code multiplied by a cost per line. By default SonarQube assumes 30 minutes to develop one line, a value an administrator can change for the whole instance.

Here is how to calculate the technical debt ratio on a hypothetical system:

InputHypothetical value
Lines of code200,000
Development cost per line (SonarQube default)30 minutes
Development cost6,000,000 minutes = 100,000 hours
Remediation effort reported by SonarQube4,000 hours
Technical debt ratio4,000 / 100,000 = 4%

Now take the same 4,000 hours of remediation effort and place them in a 50,000-line service. The development cost falls to 25,000 hours and the ratio rises to 16%. Same amount of work to clean up, a very different grade. Keep that mechanism in mind, because most of the limits discussed below come from it.


The maintainability rating from A to E

The SonarQube maintainability rating is simply the technical debt ratio mapped to a letter. The default grid looks like this, and an administrator can change the thresholds:

RatingDefault debt ratioPractical reading
A5% or lessDebt is present but within normal maintenance
Babove 5% up to 10%Worth watching, especially if the trend is rising
Cabove 10% up to 20%Debt is visibly slowing change in some areas
Dabove 20% up to 50%Structural clean-up needs to be planned and funded
Eabove 50%The estimated fix effort rivals a large share of a rewrite

SonarQube computes the rating twice: on the overall code and on new code, meaning the code changed since a reference point such as the previous version or a set number of days. The built-in quality gate focuses on new code and expects it to hold an A. This is the “clean as you code” idea: you do not have to fix the past before you can stop making it worse.

That distinction matters more than the overall letter. A legacy system rated C overall whose new code consistently scores A is improving. A system rated A overall whose new code keeps failing the gate is accumulating debt, it just has not shown up in the aggregate yet.


Where the numbers mislead

The sonarqube technical debt ratio is useful, but it is a model built on assumptions. These are the ones we see causing wrong decisions most often.

Remediation estimates are generic

Each rule’s effort was set by its authors for an average case. Renaming a badly named variable and untangling a method with very high cognitive complexity in an untested payment module can carry similar estimates. The real cost depends on test coverage, coupling and how well the team knows the code, none of which the estimate knows.

The denominator rewards size

Because development cost grows with lines of code, anything that adds lines lowers the ratio. Verbose code, copy-pasted modules, generated code or vendored libraries that slipped past exclusions all make the grade look better. Conversely, a careful refactoring that deletes thousands of duplicated lines can push the ratio up even though the system is healthier.

Averages hide hotspots

A project-level A can coexist with a god class that every feature touches. Debt concentrated in a few critical files hurts far more than debt spread thin across code nobody changes. The rating has no notion of change frequency, so it cannot tell the two situations apart. Our guide on how to prioritize technical debt explains how to combine complexity with churn to find those files.

Architecture is invisible

Cyclic dependencies between modules, a distributed monolith, a shared database, missing integration tests, an end-of-life framework, knowledge held by one engineer: none of these appear in the debt figure. In our experience these are usually the most expensive forms of debt, and they are exactly the ones that file-level rules cannot see.

The number depends on configuration

Switch the quality profile, disable a few noisy rules, mark issues as accepted or as false positives, add an exclusion: the debt figure changes overnight without a single line of production code changing. That makes comparisons between projects with different profiles meaningless, and it makes the rating easy to game when it becomes a target.

Principal is not interest

SonarQube estimates the principal, the effort to fix the issues. It says nothing about the interest, the time the team loses every week working around them. That interest is what hurts the business: in Stripe’s Developer Coefficient survey, developers reported spending on average 13.5 hours a week dealing with technical debt. No static analyser can measure that for your team; you have to observe it in delivery data.


How to use SonarQube metrics without being fooled

None of this means you should ignore the tool. It means you should treat the letter as a starting point for questions, not as a verdict. This checklist is what we apply when we read a SonarQube dashboard during an assessment:

  • Freeze the quality profile. Agree on the rules, document every change and annotate the history when the profile moves.
  • Review exclusions. Generated code, vendored libraries and test fixtures should be excluded deliberately, and nothing important should be hidden.
  • Watch new code first. Track whether new code holds an A over successive releases. That trend tells you more than the overall rating.
  • Break the ratio down by module. Look at debt per component, then cross it with change frequency to find hotspots.
  • Read the top issues in critical paths. Payment, authentication and data ingestion deserve a manual look regardless of the aggregate grade.
  • Audit accepted issues and false positives. Sample them periodically to check they were closed for good reasons.
  • Pair the rating with delivery data. Deployment frequency, change failure rate and lead time show whether debt is actually slowing the team, as described in our guide to measuring technical debt.
  • Add the architecture view. Dependency structure, test strategy and framework lifecycle need a human review.

For investors and acquirers the same rule applies. A maintainability rating in a data room is a useful first signal, but it is cheap to improve cosmetically and blind to the risks that usually drive post-deal costs. A software due diligence should verify how the number was produced before relying on it.


Conclusion

The SonarQube technical debt ratio is a clear, reproducible way to express how much file-level clean-up a codebase needs relative to its size, and the maintainability rating turns that into a letter anyone can follow. Used as a trend on new code, with a stable profile, it is one of the most practical guardrails a team can have.

Used as a verdict, it misleads. It ignores architecture, rewards size, hides hotspots and moves with configuration. The decisions that matter, where to refactor, what to fund, what risk you are buying, need the number to be read alongside churn, delivery metrics and an expert look at the structure of the system.

That is the work of our code audit: we start from tools like SonarQube, check how their numbers are produced, and turn them into a prioritised, measurable remediation plan tied to business risk.