# Counting Integers in a Range

Finding how many numbers there are between two numbers might seem like a simple task, but there can be some complications: do you include the endpoints? What if you only have to include one endpoint? Some care is required to find the number of integers in an arbitrary range.

#### Contents

## Counting Integers in a Range

How many integers are there from 1 to 10? That's easy, it's 10.

How do you get the answer 10?

First of all, "1 to 10" represents the closed interval \([1, 10]\); to get 10 we simply subtract the left endpoint from the right endpoint and then add 1, i.e. \(10-1+1=10\).

Generally,

In a closed interval \([a, b]\), the number of integers is \(b-a+1\).

How about the number of integers from 1 to 10, excluding 1 and 10?

This is an open interval \((1, 10)\). Since we already know that there are 10 integers in the range \([1, 10]\), we simply exclude the two endpoints 1 and 10 by subtracting 2. Hence there are \(10-1+1-2=8\) integers in \((1, 10)\).

Generally,

In an open interval \((a, b)\), the number of integers is \(b-a-1\).

As for the last cookie, how many integers are there in a half-open interval \([a, b)\) or \((a, b]\)?

Since only 1 of the endpoints is excluded, the number of integers is \(b-a+1-1=b-a\).

In a half-open interval \([a, b)\) or \((a, b]\), the number of integers is \(b-a\).

## Examples

How many integers are there in the open interval \((-10, 5)?\)

The number of integers is \(5-(-10)-1=14.\) \(_\square\)

How many integers are there in the closed interval \([-1, 99]?\)

The number of integers is \(99-(-1)+1=101.\) \(_\square\)

What is the total number integers in the intervals \((-15, -4]\) and \([0, 22)?\)

The total number of integers is \(\big(-4-(-15)\big)+(22-0)=11+22=33.\) \(_\square\)

What is the total number integers in the intervals

\[(-4, -3), \ (-2, -1), \ (0, 1)?\]

The total number of integers is

\[\begin{align} \big(-3-(-4)-1\big)+\big(-1-(-2)-1\big)+\big(1-(0)-1\big) &=0+0+0\\ &=0.\ _\square \end{align}\]

Which of the following intervals has the most number of integers:

\[\begin{array} & (-23, -7), & (-12, 3], & [0, 15), & [99, 114]? \end{array}\]

The number of integers in the interval \((-23, -7)\) is \(-7-(-23)-1=15.\)

The number of integers in the interval \((-12, 3]\) is \(3-(-12)=15.\)

The number of integers in the interval \([0, 15)\) is \(15-0=15.\)

The number of integers in the interval \([99, 114]\) is \(114-99+1=16.\)Hence, the interval \([99, 104]\) has the most number of integers. \(_\square\)

Both \(A\) and \(B\) are integers such that \(A<B\) and the number of integers in the interval \((A, B)\) is \(99.\) What is \(A-B?\)

The number of integers in the interval \((A, B)\) is \(B-A-1.\) Since this is equal to \(99,\) we have

\[B-A-1=99 \implies A-B=-1-99=-100.\ _\square\]

**Cite as:**Counting Integers in a Range.

*Brilliant.org*. Retrieved from https://brilliant.org/wiki/counting-integers-in-a-range/