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
- Edges E
- Nodes N
- 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.