Home · Everyday · Tech, Text & Media · Cyclomatic Complexity Calculator

Cyclomatic Complexity Calculator

Computes McCabe cyclomatic complexity M = E − N + 2P from a program's control-flow graph to gauge testing and maintenance effort.

Your figures

P = 1 for a single function or program.

Example result — edit the figures to make it yours

4

Cyclomatic complexity M

Computed from the inputs on this page with the formula below — change any figure and every result updates.

Predicate (decision) count, M − 13

What this calculator does

Computes McCabe cyclomatic complexity M = E − N + 2P from a program's control-flow graph to gauge testing and maintenance effort. Where a measure is involved, US and metric units are both accepted — flip the unit toggle and the figures convert with the same definitions the formula uses. Every result on this page is computed from the formula stated below, with no hidden rounding steps.

The formula and method

M = E − N + 2P

McCabe's metric counts the independent paths through a control-flow graph: M = E − N + 2P, where E is the number of edges, N the number of nodes and P the number of connected components (usually 1 per function). For a single structured function this equals the number of decision points (if, while, case, &&, ||) plus one.

M is also the minimum number of test cases needed for full branch-path basis coverage. Common risk bands: 1–10 simple, 11–20 moderate, 21–50 high, above 50 effectively untestable. Count each boolean sub-condition separately if your tooling does, and note that different analysers treat exception handlers and switch fall-through differently.

Worked example

With the example inputs this page opens with (edges e (control-flow arrows) 10, nodes n (basic blocks) 8, connected components p 1), the result is 4 — cyclomatic complexity m. Computed from the inputs on this page with the formula below — change any figure and every result updates.

Quick reference

Quick reference — varying Edges E (control-flow arrows)
Edges E (control-flow arrows)Cyclomatic complexity MPredicate (decision) count, M − 1
5-1-2
1043
1598
201413
251918
302423

Computed with the same formulas as the calculator above — enter any values there for figures beyond this table.

Common questions

Does cyclomatic complexity equal the number of if statements plus one?

For one structured function with P = 1, yes: M = predicates + 1. Loops, case labels and each side of && or || each count as one predicate.

How does the Cyclomatic Complexity Calculator work?

Computes McCabe cyclomatic complexity M = E − N + 2P from a program's control-flow graph to gauge testing and maintenance effort. Edges E · Nodes N · Components P → Complexity M. The result updates as you type, and the formula and method on this page state the exact definitions used, so you can reproduce the calculation by hand.

What inputs does the Cyclomatic Complexity Calculator need?

Edges E · Nodes N · Components P → Complexity M. Invalid entries — such as a zero denominator, an out-of-range value or a malformed list — produce a plain-language message instead of a misleading number.

Is the Cyclomatic Complexity Calculator free to use?

Yes. It runs entirely in your browser with no sign-up, and the same calculator is available as an embeddable widget via the Embed button, so it can be placed on another site with its calculation intact.