Intermediate

Cyclomatic Complexity Calculator

Calculate McCabe's cyclomatic complexity from a control flow graph — enter edges, nodes and connected components to find M, see how many independent test paths exist, and assess where the code falls on the risk scale.
Number of directed edges in the control flow graph
Number of nodes (basic blocks) in the control flow graph
Usually 1 for a single function or method
Cyclomatic Complexity (M)
3

Simple, well-structured code — low risk.

Decision points
2
Risk level
Low
Min. test cases for 100% branch coverage
3
17.814.521.32834.841.548.355M = 3102050Risk scale: ≤10 low · 11–20 moderate · 21–50 high · >50 very high
Step by step
  1. 1

    E − N (edges minus nodes)

    8 − 7 = 1
  2. 2

    2P (connected components term)

    2 × 1 = 2
  3. 3

    Cyclomatic complexity M = E − N + 2P

    1 + 2 = 3
    M equals the minimum number of test cases for full branch coverage.
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

Cyclomatic complexity M = E − N + 2P counts independent execution paths through code. Quick formula: M = decision points + 1. M ≤ 10 is low-risk; above 20 signals a refactoring need; above 50 is nearly untestable. M also equals the minimum test cases needed for full branch coverage.

Formula
M = E − N + 2P (simplified: M = decision points + 1 for a single function)
How this is calculated

Cyclomatic complexity was introduced by Thomas McCabe in 1976 as a graph-theoretic measure of structural code complexity. The program's control flow graph (CFG) represents each basic block as a node and each branch as a directed edge. The formula M = E − N + 2P counts the linearly independent paths through the graph, where E is edges, N is nodes, and P is connected components — typically 1 for a single routine.

For a single connected function the formula simplifies to M = decision points + 1. Decision points include if/else-if, while, for, do-while, switch-case, catch blocks, and short-circuit logical operators (&&, ||). A straight-line function with no branches has M = 1; every branch adds one.

M equals the minimum number of unit test cases needed for 100% branch (decision) coverage. Industry conventions rate M ≤ 10 as low-risk and easy to test; 11–20 as moderate; 21–50 as high-risk where refactoring is advisable; above 50 as effectively untestable. Static analysis tools such as SonarQube and ESLint enforce a configurable threshold — commonly 10 or 15 per function.

Frequently asked questions

Yes. For a single connected function, M = number of decision points + 1. Decision points include if, else if, while, for, do-while, switch case, catch, && and || (in short-circuit languages). This avoids drawing the full CFG and gives the same result.

Most coding standards cap it at 10. Some allow 15 for complex business logic. Above 20 is a refactoring priority; above 50 the function is considered untestable. Many CI pipelines fail the build if any routine exceeds the configured threshold.

M is the exact number of linearly independent paths through the code — the minimum test cases for 100% branch coverage. Lower M means fewer tests, fewer hiding places for bugs, and lower maintenance cost over time.

Also known as

mccabe complexity metric
code complexity score
control flow graph complexity
branch coverage paths calculator
software complexity measurement
decision points complexity
code maintainability metric

APA

TG we-Calculate Editorial Team. (2026). Cyclomatic Complexity Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/cyclomatic-complexity-calculator

Chicago

TG we-Calculate Editorial Team. "Cyclomatic Complexity Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/cyclomatic-complexity-calculator.

IEEE

TG we-Calculate Editorial Team, "Cyclomatic Complexity Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/cyclomatic-complexity-calculator

BibTeX

@misc{wecalculate_cyclomatic_complexity_calculator, title = {Cyclomatic Complexity Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/cyclomatic-complexity-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?