Skip to content
Design Corner Knowledge Base ← Back to designcorner.co.ke
Knowledge Base

Software and Development

Off-by-One Error

Also known as: Fencepost Error

1 min read Updated November 10, 2026

Definition A common programming bug where a loop or count is wrong by exactly one.

What it is

It happens when code starts or stops counting one step too early or late, for example processing 9 items instead of 10 because counting started at 0. Programmers often call it a fencepost error, because a fence with ten gaps needs eleven posts.

Why it matters for your business

These small bugs can produce wrong totals, missing records or even security flaws.

Real-world example

A report script skips the last day of every month, so M-Pesa totals look slightly low.

Design Corner tip

Test code at its boundaries, such as the first and last items, before going live.