Off-by-one errors are a common enough problem in programming to warrant all sorts of jokes, folk stories, and warnings. Everybody who has ever touched a computer as a programmer has made them and had to fix them more times than they could count, and yet they still keep cropping up.
But where do they actually come from?
Imagine a relatively long trip by train. Such a trip willl typically consist of multiple legs — i.e. segments spent in one particular seat on one particular vehicle, between which you need to change trains within a certain amount of time at a particular station. You also begin and end the trip at two entirely different stations, but at both ends the experience is different from that of changing trains: at the start of the trip you may need to deal with the logistics of getting your ticket, checking in luggage, etc, whereas on arrival you need to start thinking about local transit and are likely under less time pressure.
For those reasons and others, there arise situations in which it makes sense to count the number of legs in the trip, others in which it makes more sense to count changes, and still others where you might want to count stations (including the initial and terminal stations). And it is not always entirely clear which one you need until you've thought about your question for some time — possibly more time than you (feel you) have if you are rushing to catch a train.
Assumimg that your trip follows the broad pattern laid out above, knowing any one of those numbers is enough to derive the other two. And for a long enough trip, all three of the numbers might be close enough to being the same. However, they are not and will never be identical: the number of stations will always be one more than the number of legs, which will always be one more than the number of changes.
Furthermore, one of these things will often be much easier to count than the others — your ticket may list each train individually (legs), or your travel companion may be lamenting that you change in cities X and Y but never leave the station, etc. There are many good reasons for your brain to immediately jump to the most easily computable value, even if it isn't exactly the information you wanted.
And hence, off-by-one errors: not because your code fails to count accurately, but because you made the mistake of counting trains when you actually needed changes or stations. This can take many different forms: for instance, counting iterations through a loop is a classic, where "trips" around the loop are comparable to legs in the train metaphor, but incrementing the counter is an atomic operation better analogized to a station — and hence you have to situate it carefully if what you actually want is the number of "trips".
The math people are now laughing at me, of course. But that's fine. I still think most programmers have something to gain from this metaphor.