# Control Flow Graph (CFG)

> A map of each path a function can take. It splits at each if and loop.

**Field:** Software Development  
**Category:** Code Intelligence  
**Also known as:** CFG, Flow Graph

## Think of it like

It is like a maze map. It shows each path you could walk, and where the paths split.

## Definition

A control flow graph shows every path a program can take through one function. Each box is a run of steps with no choice in it. An arrow leads to the next box. An if or a loop makes the arrows split or circle back. Tools read it to find code no path can reach, or a path that skips a check.

## Example

A tool reads the control flow graph of a login function. It finds one path where the password check is skipped.

## Why it matters

Bugs hide on paths nobody tested. The graph shows every one of them.

## Common mistake

Thinking each path is tested because each line is. Two ifs make four paths, and tests often cover only two.

## Three principles

- **Boxes of steps.** No choices inside a box.
- **Splits at choices.** Each if or loop branches.
- **Every path.** Even the ones you never run.

## Related terms

- [Code Graph](https://learn.benibix.com/term/development/code-graph)
- [Control Flow](https://learn.benibix.com/term/development/control-flow)
- [Data Flow Analysis](https://learn.benibix.com/term/development/data-flow-analysis)
- [Static Analysis](https://learn.benibix.com/term/development/static-analysis)
- [Compiler](https://learn.benibix.com/term/development/compiler)

## Told apart from

- [Call Graph vs Control Flow Graph](https://learn.benibix.com/compare/call-graph-vs-control-flow-graph): People think a call graph and a control flow graph are two names for the same map of a program, and they are not. A call graph is drawn between functions: each arrow means this one calls that one. A control flow graph is drawn inside one function: each arrow is a step, and it splits at each if and loop. Use the first to see how far a change spreads, and the second to find untested paths.

![Two panels. On the left, a dependency graph: the app module imports an auth module and a billing module, and both import a shared utils module, lit up. On the right, a control flow graph for one function: a start box, a diamond asking if the user is logged in, a yes path to show the page and a no path to send to login, both meeting at an end box. A dotted line follows one variable from where it is set to where it is used.](https://learn.benibix.com/diagrams/dev4-flow-graphs.svg)

---

Source: https://learn.benibix.com/term/development/control-flow-graph
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.
