Skip to main content
Strategy & Process
DEFINITION

What is Cyclomatic Complexity?

Cyclomatic complexity is a software metric that measures the number of linearly independent paths through a piece of code, derived from its control-flow graph, giving a quantitative indicator of how complex the code is and roughly how many test cases are needed to cover its branches.

Free to start · 7-day trial on paid plans

IN DEPTH

In depth.

Introduced by Thomas McCabe, cyclomatic complexity counts the decision points in code (if, while, for, case, and logical operators) to estimate how many distinct paths run through it. A simple formula is complexity = number of decision points + 1. A function with no branches has complexity 1; each added decision increases it. Higher numbers mean more paths, more ways to go wrong, and more tests needed to exercise them.

For testers, the metric is doubly useful. First, it signals risk: highly complex functions are harder to understand, more defect-prone, and harder to maintain, so they are good candidates for extra testing, review, or refactoring. Second, it informs coverage: the cyclomatic complexity number is the minimum number of test cases needed to achieve full branch (basis path) coverage of that code, so it directly relates to how much testing a function requires.

It is part of static analysis and maintainability assessment, not something you run the software to measure. Teams often set thresholds (for example, flag functions above 10) to catch complexity creep early. The metric does not capture everything (it ignores data complexity and readability), so it is a useful signal among several, not a sole measure of quality.

WHY IT MATTERS

Why interviewers ask about this.

Cyclomatic complexity connects code structure to test effort and risk, a sign of deeper, SDET-level understanding. Knowing that it estimates independent paths (and thus minimum tests for branch coverage) and flags refactoring candidates shows you can use metrics to target testing where it matters.

EXAMPLE

Example scenario.

Static analysis flags a payment-routing function with cyclomatic complexity 18, far above the team's threshold of 10. It has many nested conditions, so it is both hard to fully test and defect-prone. The team prioritizes refactoring it into smaller functions and ensures each branch is covered, reducing both complexity and risk.

TIP

Interview tip.

Define cyclomatic complexity as a count of independent paths through code (roughly decision points + 1) from its control-flow graph. Tie it to testing: it estimates the minimum test cases for full branch coverage and flags complex, defect-prone functions for extra testing or refactoring. Note it is a static-analysis signal, not the whole picture.

FAQ

Frequently asked questions.

How does cyclomatic complexity relate to test coverage?

The cyclomatic complexity number equals the minimum number of test cases needed to cover every independent path (basis path / full branch coverage) through that code. So a function with complexity 8 needs at least 8 well-chosen test cases to exercise all its branches, directly linking the metric to required test effort.

What is a "good" cyclomatic complexity value?

There is no universal threshold, but many teams treat values up to about 10 as manageable and flag anything significantly higher as complex and defect-prone, warranting extra testing, review, or refactoring. It is a guideline and a signal among several metrics, not a hard rule or a complete measure of quality.

Related Resources

Dive deeper with these related interview prep pages.

FREE TOOLS  /  no signup

Free QA career tools, no account needed

Instant and private, everything runs in your browser. Try them before you sign up.

EXEC.NOW

Ready to Ace Your QA Interview?

Practice explaining cyclomatic complexity and other key concepts with our AI interviewer.

Join 1,200+ QA engineers already practicing with AssertHired.

Start your free QA interview
FREE.TO.START  ·  7.DAY.TRIAL ON PAID PLANS
Written by Aston Cook, Senior QA EngineerLast updated May 2026