# I Need A Formula (Or A Calculator Function) For Adding A Series Of Consecutive Integers

**URL:** <https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434>\
**Category:** Factual Questions\
**Created:** [August 29, 2016, 9:45pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434 "2016-08-29T21:45:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![HeyHomie](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/heyhomie/32/207_2.png) [@HeyHomie](https://boards.straightdope.com/u/HeyHomie)\
**Post date:** [August 29, 2016, 9:45pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/1 "2016-08-29T21:45:02Z")

</div>

I want to calculate the sum of the numbers 1+2+3+4 and so on. Is there a formula I can use? Does it work with any beginning and ending number (say, 23+24+25 and so on, up to, say 48)?

Is there a quick & easy way to do it on the calculator that came with my iPhone 4S?

---

<div class="post-metadata">

**Author:** ![Schnitte](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/schnitte/32/9033_2.png) [@Schnitte](https://boards.straightdope.com/u/Schnitte)\
**Post date:** [August 29, 2016, 9:56pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/2 "2016-08-29T21:56:47Z")

</div>

You can use the trick used by Gauss in a famous anecdote: You take the largest number in your series, add 1, and multiply that by half the number of integers in your series.

For instance (in Gauss’ example), 1 + 2 + 3 + … + 100 = (1 + 100) \* (100/2) = 101 \* 50 = 5050. It works because the lowest and the highest number can be paired to 1 + 100; the second lowest and second highest number to 2 + 99, also 101, and so on; you get 50 pairs, all adding up to 101.

---

<div class="post-metadata">

**Author:** ![Schnitte](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/schnitte/32/9033_2.png) [@Schnitte](https://boards.straightdope.com/u/Schnitte)\
**Post date:** [August 29, 2016, 9:59pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/3 "2016-08-29T21:59:45Z")

</div>

Oh, and for your example with 23 + 24 + … + 48: You can apply the trick twice:

First step: Use that method to calculate the sum of all integers up to 48, which is 49 \* 24 = 1,176.

Second step: Use the method to calculate the sum of all integers up to 22, which is 12 \* 11 = 242.

Third step: Subtract the sum of the integers up to (and including) 22 from the sum of all integers up to and including 48; the difference, 934, is the number you’re looking for.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [August 29, 2016, 10:03pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/4 "2016-08-29T22:03:11Z")

</div>

So in summary (pun intended) the formula for the sum of the integers from m to n is

[n\*(n+1)-m\*(m-1)]/2

---

<div class="post-metadata">

**Author:** ![The\_Great\_Unwashed](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/the_great_unwashed/32/4791_2.png) [@The\_Great\_Unwashed](https://boards.straightdope.com/u/The_Great_Unwashed)\
**Post date:** [August 29, 2016, 10:05pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/5 "2016-08-29T22:05:49Z")

</div>

For consecutive integers, m… …n, the formula is

(m+n)(m-n+1)/2

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [August 29, 2016, 10:10pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/6 "2016-08-29T22:10:02Z")

</div>

Another way of thinking of it: Take the average of the numbers (which, for consecutive integers, will just be the smallest plus the largest divided by two), and multiply it by the number of them.

Which of course will give you the same result as the other method.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [August 29, 2016, 10:10pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/7 "2016-08-29T22:10:09Z")

</div>

The most general term for the kind of thing you’re looking for is “closed-form expression” or similar; these problems have no magical solution, but instead require some insight and pattern-matching to solve.

[Here’s a page on the subject which walks you through an example and provides some general advice.](https://people.richland.edu/james/lecture/m116/sequences/induction.html)

---

<div class="post-metadata">

**Author:** ![HeyHomie](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/heyhomie/32/207_2.png) [@HeyHomie](https://boards.straightdope.com/u/HeyHomie)\
**Post date:** [August 29, 2016, 10:12pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/8 "2016-08-29T22:12:06Z")

</div>

Thanks! Having mathematicians around is helpful!

---

<div class="post-metadata">

**Author:** ![Indistinguishable](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@Indistinguishable](https://boards.straightdope.com/u/Indistinguishable)\
**Post date:** [August 29, 2016, 10:29pm UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/9 "2016-08-29T22:29:49Z")

</div>

> [@Derleth](#):
>
> The most general term for the kind of thing you’re looking for is “closed-form expression” or similar; these problems have no magical solution, but instead require some insight and pattern-matching to solve.
> 
> [Here’s a page on the subject which walks you through an example and provides some general advice.](https://people.richland.edu/james/lecture/m116/sequences/induction.html)

In the greatest generality, any particular problem becomes the entirety of human knowledge and ignorance, every solved and unsolved potential problem agglomerated together into “How do I figure out _everything_?”. But at least the OP’s specific question does indeed have a “magical solution”.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [August 30, 2016, 12:32am UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/10 "2016-08-30T00:32:07Z")

</div>

> [@The\_Great\_Unwashed](#):
>
> For consecutive integers, m… …n, the formula is
> 
> (m+n)(m-n+1)/2

Be careful with this one. The formula assumes m \> n, but the description would imply m \< n.

---

<div class="post-metadata">

**Author:** ![The\_Great\_Unwashed](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/the_great_unwashed/32/4791_2.png) [@The\_Great\_Unwashed](https://boards.straightdope.com/u/The_Great_Unwashed)\
**Post date:** [August 30, 2016, 7:17am UTC](https://boards.straightdope.com/t/i-need-a-formula-or-a-calculator-function-for-adding-a-series-of-consecutive-integers/764434/11 "2016-08-30T07:17:55Z")

</div>

> [@OldGuy](#):
>
> Be careful with this one. The formula assumes m \> n, but the description would imply m \< n.

Good call.

S = (m+n)(n-m+1)/2
