# 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.

## Interval Notations

In mathematics, we use **interval notations** to represent a range of (real) numbers. To represent the interval of numbers between \(a\) and \(b\), including \(a\) and \(b\), we write \([a, b]\). The two numbers \(a\) and \(b\) are called the endpoints of the interval.

If you want to exclude either \(a\) or \(b\) from the range, we simply replace the corresponding bracket with parenthesis. For example, the interval \([a, b)\) represents a range of numbers larger than or equal to \(a\) and strictly smaller than \(b\).

An

**open interval**does not include its endpoints, and is indicated with parentheses. For example, \((0,1)\) means greater than 0 and less than 1.A

**closed interval**includes its endpoints, and is denoted with square brackets. For example, \([0,1]\) means greater than or equal to 0 and less than or equal to 1.A

**half-open interval**includes only one of its endpoints, and is denoted by mixing the notations for open and closed intervals. \((0,1]\) means greater than 0 and less than or equal to 1, while \([0,1)\) means greater than or equal to 0 and less than 1.

**Notes:**

In open and half-open intervals, the parentheses can also be replaced with reversed brackets, for example \((0, 1)\) can also be rewritten as \(]0, 1[\).

In some countries where comma (,) is used as decimal points, a semicolon (;) may be used in place of a comma as a separator to avoid ambiguity: for example, \((0; 1)\).

## 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/