# Cyclomatic Complexity Calculator

URL: https://speedycalculator.com/calculators/math/cyclomatic-complexity/
Last updated: 2026-10-30

> 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.

## Inputs

- Edges E
- Nodes N
- Connected components P

## Results

- Cyclomatic complexity M
- Risk

## Formula

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

## Explanation

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

FieldWhat to enterEdges EA numberNodes NA numberConnected components PA number

### Example values

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

Edges ECyclomatic complexity M4.5-26.758e-19311.25513.581812

## 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.

## FAQ

**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

- [McCabe, T. J. (1976). A Complexity Measure. IEEE Transactions on Software Engineering](https://doi.org/10.1109/TSE.1976.233837)
