Code complexity measures how difficult a piece of code is to understand, test, and maintain. It quantifies the structural and logical density of a function, module, or codebase so that engineering teams can spot sections likely to cause bugs, slow code review, or resist change.
The most common measure is cyclomatic complexity, developed by Thomas McCabe in 1976. It counts the number of linearly independent paths through a function's control flow graph. A function with one if-statement has a cyclomatic complexity of 2. Add a nested loop and an exception handler, and you can push that past 10 before the function even does anything interesting.
Industry benchmarks from the DORA State of DevOps research consistently place low-complexity functions between 1 and 10. Functions in the 10-20 range carry moderate risk and warrant review. Anything above 20 is high complexity: harder to test, more likely to contain defects, and slower to change safely.
The standard formula for cyclomatic complexity is:
Cyclomatic Complexity = E - N + 2P
Where E is the number of edges in the control flow graph, N is the number of nodes, and P is the number of connected components (typically 1 for a single function). In practice, most static analysis tools count branches directly: each if, else if, case, catch, while, for, and boolean operator adds one to the score.
Primary data sources: your version control system (Git), static analysis tools (SonarQube, CodeClimate, ESLint with complexity rules), and code review platforms. For teams running AI coding assistants, complexity data should also capture AI-generated code separately since AI-written functions tend to be longer with more branching paths.
How Hivel measures Code Complexity
Hivel surfaces code complexity through its Code Quality dashboard, where you can view per-repository cyclomatic complexity trends alongside PR size, review time, and rework rate.
To find this data in Hivel:
1. Go to Code Quality > Complexity in the left nav.
2. Filter by repository, team, or date range to isolate high-complexity hotspots.
3. Use the Trend view to see whether complexity is rising over sprints, and correlate spikes with your rework and bug rate metrics.
Code complexity and technical debt often move together, but they are different measurements. Complexity tells you how hard a specific function or module is to understand right now. Technical debt is the accumulated cost of shortcuts taken across the codebase over time.
You can have low-complexity code that carries heavy debt (straightforward but outdated patterns, deprecated dependencies). You can also have high-complexity code that is fully intentional and well-documented. Treat them as separate signals. High complexity is a warning. Technical debt is a backlog item with a cost attached.
Code complexity is a leading indicator of review time, bug rate, and incident recovery time. Functions with cyclomatic complexity above 20 have bug densities two to four times higher than simpler functions, according to longitudinal data from NASA software studies. That compounds fast on a team shipping 50 PRs a week.
For engineering leaders, complexity is where velocity and quality connect. A team shipping faster into high-complexity codebases is not getting faster. They are building a system that will slow them down in 90 days. Platforms like Hivel surface
code quality visibility across your repos alongside DORA metrics so engineering leaders can see whether speed gains are real or borrowed against future rework.
See how Hivel tracks code complexity across your engineering org →



We'll show you exactly how AI is impacting your speed and code quality.



See exactly how AI-assisted code is impacting your delivery speed and code quality, before you commit to anything.
Trusted by 1000+ teams