Off-by-one Error
Updated 2026-07-28
Summary
An off-by-one error (OBOE) is an error in counting where the result is one more or one less than it should be due to a mistake in judging boundary conditions. It typically refers to a programming error in which a loop iterates one time too many or one time too few, and is a type of logical error. For example, a programmer might use "less than" instead of "less than or equal to" in a loop comparison, or fail to account for a sequence starting at 0 rather than 1 (as is the case with array indices in many programming languages). This error also occurs in mathematics.
Definition
An off-by-one error (OBOE) is an error in counting where the result is one more or one less than it should be due to a mistake in judging boundary conditions. It typically refers to a programming error in which a loop iterates one time too many or one time too few, and is a type of logical error. For example, a programmer might use "less than" instead of "less than or equal to" in a loop comparison, or fail to account for a sequence starting at 0 rather than 1 (as is the case with array indices in many programming languages). This error also occurs in mathematics.
Introduction
How to use
An off-by-one error (OBOE) is an error in counting where the result is one more or one less than it should be due to a mistake in judging boundary conditions. It typically refers to a programming error in which a loop iterates one time too many or one time too few, and is a type of logical error. For example, a programmer might use "less than" instead of "less than or equal to" in a loop comparison, or fail to account for a sequence starting at 0 rather than 1 (as is the case with array indices in many programming languages). This error also occurs in mathematics.
Mechanism
In counting, indexing, and boundary handling, a deviation in the starting/ending point (e.g., counting from 0 vs. 1) leads to a result that is off by one. The root cause is confusion between "interval endpoints" and "counting" (the number of posts equals the number of intervals plus one).
Practice
In progress 0/4Practice this model in one real situation:
Cases
- A fence with 10 intervals requires 11 posts; a loop boundary misses the last element; pagination with "page 1, items 0-9" has an index offset.
Common pitfalls
- Only guarding against it in code—this error can occur in any range, period, or step problem; relying on visual inspection of boundaries is highly prone to missing it.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E5%B7%AE%E4%B8%80%E9%94%99%E8%AF%AFverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS