# Dead Code Detection

> Finding code that never runs or that nothing uses. Then it can go.

**Field:** Software Development  
**Category:** Code Intelligence  
**Also known as:** Dead Code, Unused Code, Unreachable Code

## Think of it like

It is like finding toys in a box. No one has played with them in years.

## Definition

Dead code detection finds code that never runs or that nothing uses. It might be a function nobody calls, or a line after a return that no path can reach. Tools find it with the call graph and the control flow graph. Dead code still has to be read, tested and kept safe. Removing it makes the codebase smaller and easier to follow.

## Example

A tool finds that oldFormat has no callers in Jack's project. He checks the logs, sees it never ran, and deletes 300 lines.

## Why it matters

Dead code costs time on each read and each upgrade. It can also hide old security holes.

## Common mistake

Deleting code that looks unused but is called from outside. A public API, a plugin or a name in a config file can call it.

## Three principles

- **Never called.** No path leads to it.
- **Never reached.** No branch can run it.
- **Check before delete.** Outside callers may exist.

## Related terms

- [Call Graph](https://learn.benibix.com/term/development/call-graph)
- [Control Flow Graph (CFG)](https://learn.benibix.com/term/development/control-flow-graph)
- [Static Analysis](https://learn.benibix.com/term/development/static-analysis)
- [Tree Shaking](https://learn.benibix.com/term/development/tree-shaking)
- [Refactoring](https://learn.benibix.com/term/development/refactoring)

![A call graph of six functions joined by arrows, each arrow meaning calls. The function parseDate is lit up as changed. The two functions that call it, and the one that calls those, are marked affected. Off to one side, a function called oldFormat has no arrows pointing to it and is marked never called, dead code.](https://learn.benibix.com/diagrams/dev4-call-graph.svg)

---

Source: https://learn.benibix.com/term/development/dead-code-detection
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
