# 5 to 18: Why Your Count Might Be Off by One

DevFeed: [5 to 18: Why Your Count Might Be Off by One](<https://devfeed.tech/articles/5-to-18-why-your-count-might-be-off-by-one-33310.md>)

Original publisher: [Read original article](<https://ruslanspivak.com/bb07/>)

Author: Ruslan Spivak

Published: 2025-08-19T15:37:00Z

Content type: tutorial

Language: en

Sources: [Ruslan Spivak](<https://devfeed.tech/sources/ruslan-spivak.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [coding](<https://devfeed.tech/topics/coding.md>), [bug](<https://devfeed.tech/topics/bug.md>)

Tags: [blog](<https://devfeed.tech/tags/blog.md>), [bug](<https://devfeed.tech/tags/bug.md>), [code](<https://devfeed.tech/tags/code.md>), [numbers](<https://devfeed.tech/tags/numbers.md>), [range](<https://devfeed.tech/tags/range.md>)

## AI overview

A tutorial explains how to count integers in an inclusive range using b - a + 1. It uses the range from 5 to 18 to show why subtracting the endpoints alone produces an off-by-one error, then connects the mistake to dates, strings, workout plans, floors, and loop boundaries in code.

## Source excerpt

Quick question: How many numbers are there from 5 to 18, including both ends? Your first instinct might be to subtract: 18 - 5 = 13 Feels right. But it's wrong. It's a small thing, and kind of basic, but this mistake got me more times than I'd like ...