ThisCalculator

Technology

Sum of n Numbers: Formula & How to Use It

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Sum of n Numbers: Formula & How to Use It

This calculator works out the sum of the first n natural numbers (1 + 2 + 3 + … + n) using the standard formula S = n(n + 1)/2. You enter the value of n, and you get the total sum instantly, along with the average of those numbers. The formula is one of the most useful in arithmetic, appearing in everything from classroom math to programming loops.

Formula

The sum of the first n natural numbers is given by:

S = n × (n + 1) / 2

Where:

  • S = the total sum (no unit, it’s just a count)
  • n = the number of terms you are adding, starting from 1 (a positive integer)

This formula assumes you are summing consecutive integers starting at 1. If you want to sum a different range, like 5 to 10, you subtract the sum of 1 to 4 from the sum of 1 to 10.

Worked Example

Using the default value of n = 100, the formula gives:

  1. Write down the formula: S = n × (n + 1) / 2
  2. Plug in n = 100: S = 100 × (100 + 1) / 2
  3. Add inside the parentheses: S = 100 × 101 / 2
  4. Multiply: S = 10100 / 2
  5. Divide: S = 5050

So the sum of 1 + 2 + 3 + … + 100 is exactly 5050. The average is (100 + 1) / 2 = 50.5, which makes sense because 50.5 is exactly halfway between 1 and 100.

Why This Formula Works

The classic proof, often attributed to a young Carl Friedrich Gauss, pairs the first and last terms. For n = 100, pair 1 with 100 (sum 101), 2 with 99 (sum 101), and so on. You get 50 pairs, each summing to 101, so the total is 50 × 101 = 5050. In general, you get n/2 pairs, each summing to (n + 1), which gives the formula. This pairing trick works for any even n; for odd n, the middle number is simply (n + 1)/2, and the formula still holds.

When to Use This Formula

Use this formula whenever you need the total of a consecutive integer sequence starting at 1. Common situations include:

  • Adding up page numbers, seats in a theater, or days in a month
  • Calculating the total number of handshakes in a group (n people each shake n−1 hands, but each handshake is counted twice, so the total is n(n−1)/2 – a close cousin)
  • Computing the sum of the first n positive integers in a programming loop
  • Estimating the total of a large arithmetic series quickly without adding each term

For a sequence that does not start at 1, say from a to b, use: sum = (a + b) × (b − a + 1) / 2. This is the same formula applied to the average of the first and last terms times the count.

Common Mistakes and How to Avoid Them

  • Using the wrong n: If you sum from 1 to 50, n = 50, not 49. The formula counts the number of terms, not the last number minus one.
  • Forgetting to divide by 2: The formula is n(n+1)/2, not n(n+1). A quick check: for n = 1, the sum should be 1, and 1×2/2 = 1, correct.
  • Mixing up with the square of n: The sum of the first n odd numbers is n², not this formula. For example, 1+3+5 = 9 = 3².
  • Using the formula for non-integer n: The formula technically works for any real n, but the “sum of the first n numbersâ€� only makes sense for positive integers. If you enter a decimal, the calculator will still compute a number, but it won’t represent a real sum.

Related Formulas and Extensions

This formula is part of a family of power sums. If you need the sum of squares (1² + 2² + … + n²), the formula is n(n+1)(2n+1)/6. For cubes (1³ + 2³ + … + n³), the formula is [n(n+1)/2]² – which is simply the square of this sum. These appear in statistics (variance calculations), physics (moment of inertia), and numerical analysis. The general approach for any polynomial sequence uses Bernoulli numbers, but for most practical purposes, the linear and quadratic formulas cover the majority of needs.

Limits of the Formula

The formula is exact and has no rounding error for integer n. However, be careful with very large n: n(n+1) can overflow in a computer if n is huge (beyond about 10^9 in a 64-bit integer). In that case, you can compute (n/2) × (n+1) or n × ((n+1)/2) to avoid overflow, depending on whether n is even or odd. Also, if you are summing numbers that are not consecutive or not starting at 1, this formula does not apply directly – you need the general arithmetic series formula.

Frequently Asked Questions

What is the sum of the first 100 numbers?

The sum of the first 100 positive integers (1 to 100) is 5050. This is the classic example used to illustrate the formula, and it is exactly what the calculator returns when n = 100.

How do I find the sum of numbers from 1 to n without adding them all?

Use the formula S = n(n+1)/2. For example, for n = 50, S = 50×51/2 = 1275. This works because the average of 1 and n is (n+1)/2, and you multiply that average by the count n.

Does the formula work for negative numbers or zero?

The formula technically computes a value for any n, but the “sum of the first n natural numbers� is only defined for positive integers. If you enter n = 0, the formula gives 0, which is correct (empty sum). For negative n, the result is not meaningful in the usual sense.

What is the sum of the first n even numbers?

The first n even numbers are 2, 4, 6, …, 2n. Their sum is n(n+1) – exactly double the sum of the first n integers. For example, the first 10 even numbers sum to 10×11 = 110.

How is this formula related to the average?

The average of the first n natural numbers is (n+1)/2. Since the sum is n times the average, you get S = n(n+1)/2. This is a handy way to estimate sums: for large n, the average is roughly n/2, so the sum is roughly n²/2.

Can I use this formula for a list of numbers that aren’t consecutive?

No. This formula only works for consecutive integers starting at 1. For an arbitrary list, you need to add them directly or use a different method. If the list is an arithmetic sequence (constant difference), use the general formula: sum = (first + last) × count / 2.

Related

Formula used
in n | n (count of numbers) | - | 100 | 1
out sum | Sum of 1 to n | - | n * (n + 1) / 2 | 0
out avg | Average (mean) | - | (n + 1) / 2 | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.