# Bugs and Error Types

> What a bug is, and the three kinds of error: syntax, runtime and logic. Why the off-by-one error is the most common bug of all.

**Course:** [Programming Basics](https://learn.benibix.com/learn/development-concepts)  
**Time:** 12 min

**After this lesson you can:**

- Tell syntax, runtime and logic errors apart
- Explain why a logic error is the hardest to find
- Spot an off-by-one error in a loop

## What kinds of error a program can have

A bug is a mistake in a program that makes it do the wrong thing, or stop. The word goes back a long way. In 1947, engineers working on an early computer at Harvard found a moth stuck in a part and taped it into their logbook. Every programmer writes bugs. The skill is finding them.

An error is the problem a bug causes, and errors come in three kinds. They differ in when they show up and how loudly. Knowing which kind you have tells you where to look, so it is worth learning to tell them apart.

A syntax error breaks the grammar of the language: a missing bracket, a missing colon, a quote mark left open. Python checks the whole file first, so a syntax error stops it before a single line runs. Python names the line and points near the spot. These are the easiest to fix.

A runtime error shows up while the program is running. It happens only when a certain line meets a certain value. Dividing by zero causes one. So does reading names[5] from a list of 3, or asking for a key that is not there. The code was fine as text, but the data broke it.

A logic error is the sneakiest. The program runs to the end with no message, but the answer is wrong. Typing + where you meant -, or testing > where you meant >=, gives a logic error. Python cannot know what you meant, so only a test that checks the answer will catch it.

The most common logic error has its own name: the off-by-one error. A loop runs one time too many or one too few. A list of 5 items has spots 0 to 4. A loop that goes up to 5, rather than stopping before it, reads a spot that does not exist.

People expect errors to be bad news. A loud error is the good kind: it tells you the line and stops. A quiet wrong answer can run for months. That is why it pays to check results, not just that the program finished.

## The three kinds of error

| Kind | When it shows up | Example |
| --- | --- | --- |
| Syntax error | Before any line runs | A missing colon after if |
| Runtime error | While running, on some data | Dividing by zero |
| Logic error | Never, the answer is just wrong | Using + instead of - |

![Five names, Ana to Ed, sit in boxes numbered 0 to 4, with an empty box at 5 marked nothing. A loop with i < 5 is marked right, 0 to 4. A loop with i <= 5 is marked one too far, and reading position 5 goes past the end and crashes.](https://learn.benibix.com/diagrams/dev7-off-by-one.svg)

### Example: Lucy's average is always a bit low

Lucy's script averages 10 test scores, but the answer is always a little low. No error ever appears.

Her loop used range(1, 10), which skips spot 0, so it added 9 scores and divided by 10. It was an off-by-one logic error. She changes it to range(10) and the average is right.

**Words in this lesson:** [Bug](https://learn.benibix.com/term/development/bug), [Error](https://learn.benibix.com/term/development/error), [Syntax Error](https://learn.benibix.com/term/development/syntax-error), [Runtime Error](https://learn.benibix.com/term/development/runtime-error), [Logic Error](https://learn.benibix.com/term/development/logic-error), [Off-by-One Error](https://learn.benibix.com/term/development/off-by-one-error)

**Question:** A program runs with no message but prints the wrong total. What kind of error is it?

**Answer:** A logic error. The code is valid and nothing crashed, but the answer is wrong. That is a logic error, and only checking the result will catch it.

---

Source: https://learn.benibix.com/learn/development-concepts/bugs-and-error-types
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.
