# Debugging

> The work of finding out why code goes wrong, then fixing it.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Debug

## Think of it like

Think of it like being a detective. You gather clues, guess who did it, and test your guess.

## Definition

Debugging is the work of finding and fixing bugs. First you make the bug happen again on purpose. Then you narrow down where it lives, by reading messages, printing values or stepping through the code. Once you find the cause, you fix it and check the fix. Good debugging is calm and step by step, not random changes.

## Example

Lucy's total is off by one cent. She prints the value after each step and finds a float rounding error on line 14.

## Example code

```python
total = 0
for price in [0.1, 0.2]:
    total = total + price
    print("total so far:", total)   # a quick debug line
```

Printing the value at each step shows where it first goes wrong.

## Why it matters

Every developer spends a large share of their time debugging. Doing it with a method saves hours.

## Common mistake

Changing things at random until it works. You may hide the bug, and you learn nothing about the cause.

## Three principles

- **Make it happen again.** A bug you can repeat is half fixed.
- **Narrow it down.** Cut the search area in half each step.
- **Check the fix.** Run the failing case again after.

## Related terms

- [Bug](https://learn.benibix.com/term/development/bug)
- [Stack Trace](https://learn.benibix.com/term/development/stack-trace)
- [Error](https://learn.benibix.com/term/development/error)
- [Software Developer](https://learn.benibix.com/term/development/software-developer)
- [Print Debugging](https://learn.benibix.com/term/development/print-debugging)
- [Rubber Duck Debugging](https://learn.benibix.com/term/development/rubber-duck-debugging)

## Taught in

- [Exceptions and Debugging](https://learn.benibix.com/learn/development-concepts/exceptions-and-debugging): Programming Basics, 16/18

---

Source: https://learn.benibix.com/term/development/debugging
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-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
