Cyclomatic Complexity Calculator

Quick answer

The cyclomatic complexity calculator computes McCabe's complexity M = E − N + 2P of a program's control-flow graph from its edges, nodes and connected components, and rates the risk.

Cyclomatic complexity M
3
Risk
Simple, low risk (1–10)

Cyclomatic complexity counts the independent paths through code. It tells developers how many test cases are needed to cover every independent path and flags functions that are hard to understand and maintain. Thomas McCabe introduced it in 1976.

How to use the Cyclomatic Complexity Calculator

  1. Edges E
  2. Nodes N
  3. Connected components P

Results update as you type, and everything is calculated in your browser.

How it works

Count the nodes (blocks of code) and edges (possible jumps) of the control-flow graph, and the number of separate components (usually 1 per function).

Inputs explained

Field What to enter
Edges E A number
Nodes N A number
Connected components P A number

Example values

How the main result changes when Edges E changes and everything else stays at the example values above:

Edges E Cyclomatic complexity M
4.5 -2
6.75 8e-1
9 3
11.25 5
13.5 8
18 12

Formula

M = E − N + 2P (E edges, N nodes, P connected components)

Worked example

Inputs — Edges E: 9; Nodes N: 8; Connected components P: 1.
Results — Cyclomatic complexity M = 3; Risk = Simple, low risk (1–10).

Key terms

Control-flow graph
A graph of code blocks and the jumps between them.

Frequently asked questions

What is a good cyclomatic complexity?

10 or less per function is the usual guideline.

How can I count it without a graph?

Number of decision points (if, while, for, case, &&, ||) plus 1.

Why does it matter?

It is the number of tests needed to cover every independent path, and an upper bound for full branch coverage.

What is P?

The number of connected components – separate functions analysed together.

Sources

  1. McCabe, T. J. (1976). A Complexity Measure. IEEE Transactions on Software Engineering

Cite this calculator

Speedy Calculator. (2026). Cyclomatic Complexity Calculator. Speedy Calculator. https://speedycalculator.com/calculators/math/cyclomatic-complexity/