Skip to content

What does Cyclomatic Complexity mean?

Cyclomatic Complexity measures how complicated a program is. Developed by Thomas McCabe (1976), it's the number of linearly independent paths through a function — traditionally read off the control-flow graph.

How Understand reports it

Understand computes Cyclomatic Complexity for program units (functions and methods) and reports aggregated average and sum values for their containing classes and files. You can:

  • see it in Metrics → Browse Metrics (the Metrics Browser),
  • export it to CSV (GUI or the und CLI), or
  • visualize it in Metrics → Metrics Treemap, where box size is lines of code and color is complexity, so hot, complex functions stand out at a glance — see Where is my risky / complex code?.

The metric ID is Cyclomatic (friendly name “Cyclomatic Complexity”); aggregates like AvgCyclomatic, MaxCyclomatic, and SumCyclomatic roll it up to files/classes.

How it's calculated

For a function with one entry and one exit, Cyclomatic Complexity = number of decision points + 1. Understand counts decision keywords (for, while, if, …); for a switch, each case counts 1 and the switch itself adds 1.

Understand also supports variants (metric IDs in code):

Variant ID What changes
Modified Cyclomatic CyclomaticModified A whole multi-way structure (e.g. switch) counts as 1, not per-case.
Strict Cyclomatic CyclomaticStrict Logical && / \|\| in conditions each add 1. if (a && b \|\| c) → Strict = 3.
Strict Modified CyclomaticStrictModified Both of the above combined.
Essential Complexity Essential Iteratively removes well-structured control (if/else, while), exposing unstructured flow.

You can pick which variant the Cyclomatic metric reports in Project Configuration → Metrics → Complexity (All/Normal/Strict/Modified/StrictModified), or via und settings -MetricCyclomatic <value>.

Interpreting the value

Thresholds come from external standards, not from SciTools

Understand reports the number; it does not prescribe a pass/fail threshold. A widely-cited reference is the Software Engineering Institute (SEI) risk bands:

Cyclomatic Risk
1–10 Simple, low risk
11–20 More complex, moderate risk
21–50 Complex, high risk
51+ Untestable, very high risk

When you need an enforced per-function limit rather than guidance, the HIS metric set defines one.

Treat these as guidance. High complexity is one input to refactoring decisions — interconnectivity and blast radius matter too. A complex function that has run reliably for years is often riskier to rewrite than to leave alone.

Understand also computes Cognitive Complexity (Sonar's alternative complexity measure, via plugin), Path Count, Depth of Inheritance Tree (DIT), Nesting, and Knots, among others. See the metrics catalog for the full list and per-language availability.