Math

Instant, private, and free

Cyclomatic Complexity Calculator.

Compute McCabe cyclomatic complexity from graph edges, nodes, and connected components.

On-device calculationNo signup
01

Set your values

Results update as you type.

Result: complexity: 4.000000 · edges: 10.000000 · nodes: 8.000000 · components: 1.000000

Result

complexity: 4.000000 · edges: 10.000000 · nodes: 8.000000 · components: 1.000000

Use Cases

Assess code testability

Cyclomatic complexity indicates the minimum number of test cases needed to achieve branch coverage. Use this calculator to estimate testing effort for a function or module.

Example: A function with complexity 5 requires at least 5 test cases for full branch coverage.

Identify refactoring candidates

High complexity values often signal code that is difficult to understand and maintain. Use the calculator to compare complexity across functions and prioritize refactoring.

Example: Refactor a function with complexity 25 into smaller, simpler functions.

Frequently Asked Questions

What is cyclomatic complexity?
Cyclomatic complexity, introduced by Thomas McCabe, measures the number of linearly independent paths through a program's source code. It is calculated using the formula M = E - N + 2P, where E is the number of edges, N is the number of nodes, and P is the number of connected components in the control flow graph.
How do I use this calculator?
Enter the number of edges (E), nodes (N), and connected components (P) from your control flow graph. The calculator applies the formula M = E - N + 2P to give you the cyclomatic complexity value. Higher values indicate more complex code that may be harder to test and maintain.
What is a good cyclomatic complexity score?
Generally, a complexity of 10 or less is considered simple and low-risk. Values between 11 and 20 indicate moderate complexity, while above 20 suggests high complexity that may benefit from refactoring. However, acceptable thresholds can vary by project standards.

Tips & Common Mistakes

Tips

  • Ensure your control flow graph includes all decision points (if, else, loops, case) as nodes and edges correctly.
  • For a single function or module, P is typically 1. Use P > 1 only when analyzing multiple connected components.
  • Use the result as a relative measure: compare complexity across similar functions to spot outliers.
  • Combine cyclomatic complexity with code review to improve maintainability, not just as a standalone metric.

Common Mistakes to Avoid

  • Counting edges incorrectly: each edge represents a possible transfer of control, including fall-through paths.
  • Using P = 0 when the graph is connected; P should be at least 1 for a single program.
  • Confusing nodes with statements: nodes represent basic blocks, not every line of code.

Last updated: August 13, 2026