Sum of first n odd numbers
Add the first n odd numbers in one step, because they always total n squared: the first 10 odd numbers add up to 100 and the first 100 add up to 10000. Exact for any n up to ten million. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 5
- Sum
- 25
- Last odd
- 9
- Identity
- 1+3+...+(2n-1)=n^2
The first n positive odd numbers form a simple sequence that hides a powerful identity: one plus three plus five and so on up to the n-th odd term always adds up to n squared. For n equals one the sum is one; for n equals two it is four; for n equals three it is nine; for n equals five it is twenty-five. This calculator accepts a positive integer n, validates that it is at least one, and returns the sum together with the last odd term and the classic formula so students, teachers, and developers can check homework, build demos, or wire automated tests without re-deriving the proof under pressure. Values of n below one are rejected with a clear validation error instead of a silent zero or nonsense total.
Why the first n odd numbers sum to n squared
Write the first n positive odd numbers as one, three, five, and so on through two n minus one. There are exactly n terms in that list, and each term is two times its zero-based index plus one. Adding them by hand for small n already suggests a pattern: one equals one squared, one plus three equals four which is two squared, one plus three plus five equals nine which is three squared, and one plus three plus five plus seven equals sixteen which is four squared.
A short inductive argument seals the identity for every positive integer n: if the sum of the first k odds is k squared, then the sum of the first k plus one odds is k squared plus the next odd number two k plus one, which expands to k squared plus two k plus one, exactly the expansion of open parenthesis k plus one close parenthesis squared.
Geometric pictures also help: an n by n square can be built by nesting L-shaped borders of odd length, each border contributing one more odd number of unit squares. Classroom checks include n equals one giving sum one, n equals ten giving sum one hundred, and n equals one hundred giving sum ten thousand.
What you can do with it
Homework and exam checks
Verify that 1+3+…+(2n−1) equals n² for classroom problems and reject n below 1 with a clear error instead of a wrong total.
Teaching induction with live numbers
Show students how each new odd term grows the running total to the next perfect square, using the same function in browser demos and grading scripts.
FAQ
What formula does this calculator use?
The sum of the first n positive odd numbers is n²: 1 + 3 + … + (2n − 1) = n² for every integer n ≥ 1.
What happens if n is 0 or negative?
The first n odd positives are only defined for n at least 1.
What does it cost?
The browser tool is free and runs locally.
Why do the first n odd numbers add up to a perfect square?
Picture a square built from L-shaped borders. Each new border adds the next odd number of unit squares and makes the square one size bigger, so 1, then 1 plus 3, then 1 plus 3 plus 5 give 1, 4 and 9.
What is the last odd number in the sum?
It is twice n minus 1, and the calculator shows it next to the total. With n equal to 5 the odd numbers run from 1 up to 9, and their sum is 25.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/sum-of-odd \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/sum-of-odd", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/sum-of-odd",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/sum-of-odd", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/sum-of-odd", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.sum_of_odd",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The free browser tool and the paid API share one pure function, so classroom demos and production pipelines never silently diverge on the same n.
Why the first n odd numbers sum to n squared
This service does not re-prove the theorem on every call; it applies the closed form sum equals n times n after validating n, so the result is exact within the supported integer range and free of floating-point drift.
What you send and what you get back
Wire the free browser tool for quick sanity checks, then call the identical contract from scripts when you need bulk evaluation of odd-number sums without reimplementing the gate in every language. Provide one required integer field n (aliases count, terms, how_many) equal to how many leading positive odd numbers you want to add. The value must be an integer between one and ten million inclusive; missing fields, empty strings, decimals, non-numeric text, zero, and negative numbers are rejected with invalid_input and are not charged. On success the JSON response echoes the normalized n, returns sum as n squared, includes last_odd as two n minus one so clients can show the final term without recomputing it, sets formula to the string n caret two, and sets identity to the readable string one plus three plus ellipsis plus open parenthesis two n minus one close parenthesis equals n squared for documentation in logs and teaching UIs. Example checks: n equals five yields sum twenty-five and last_odd nine; n equals one yields sum one and last_odd one; n equals seven yields sum forty-nine and last_odd thirteen; n equals zero or n equals negative three both fail invalid_input with a message that n must be at least one.
Where this identity shows up in real work
Secondary-school algebra and middle-school number sense units constantly ask students to sum the first n odd numbers or to explain why that total is a perfect square; a trusted calculator with a strict n greater than or equal to one check speeds homework grading and removes spreadsheet mistakes where someone multiplies the wrong closed form. If you later need the sum of the first n even numbers, an arbitrary arithmetic series, or odd numbers starting at an offset other than one, treat those as separate search intents rather than overloading this landing page. Programming contest warm-ups and coding interview drills use the same identity as a first exercise in loops, induction, or closed-form thinking, so an API oracle that returns sum, last_odd, and the formula string lets auto-graders compare student output without flaky tolerance. Visualization and teaching demos that grow an n by n grid one L-shaped odd border at a time can pull last_odd and sum on each step to keep narration and numbers aligned. Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Integration use cases
Coding drills and auto-graders
Compare student loop implementations against the closed-form sum and last_odd without re-deriving the identity in every test harness.
Technical questions
What is last_odd in the response?
It is the n-th positive odd number, equal to 2n − 1, so you can display the final term without recomputing it.
Does this sum even numbers or an arbitrary odd range?
No. This endpoint only sums the first n positive odds starting at 1. Other series are separate tools.