Hexagonal number calculator
The 5th hexagonal number is 45. Enter a position to get its exact hexagonal number, every digit kept even for huge results, or enter any whole number to learn whether it is hexagonal and where it sits. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 5
- Value
- 45
Hexagonal numbers form the figurate sequence that counts dots arranged in a regular hexagon: one at the center for n equals one, then successive hexagonal rings. The closed formula is H of n equals n times two n minus one, so the sequence begins zero (when n is zero), then one, six, fifteen, twenty-eight, forty-five, sixty-six, and so on. Every hexagonal number is also a triangular number, specifically the triangular number at index two n minus one, which is why these values appear in lattice packing, recreational mathematics, and programming contest problems about figurate sequences. This calculator accepts a non-negative index n and returns the exact hexagonal value as a decimal string, or accepts an arbitrary non-negative integer and reports whether it is hexagonal together with the matching index when it is. Negative indices are rejected with a clear validation error rather than a silent wrong answer.
How the n-th hexagonal number is defined and checked
The hexagonal sequence uses the compact product H of n equals n times two n minus one. Expanding gives the quadratic two n squared minus n, which is the discrete area of a hexagon built from unit dots. With n starting at zero you get H of zero equals zero; with n equals one you get one; n equals two yields six; n equals three yields fifteen; n equals four yields twenty-eight; n equals five yields forty-five.
To decide whether a candidate x is hexagonal without scanning the whole sequence, solve the quadratic two n squared minus n minus x equals zero and require that the positive root n equals one plus the square root of one plus eight x, all divided by four, is a non-negative integer. Equivalently, one plus eight x must be a perfect square s squared and one plus s must be divisible by four.
This implementation never uses floating-point square roots or rounding: it computes H of n with BigInt multiplication and tests membership with an exact integer square root and modular check, so every digit of large results stays correct. The path is fully deterministic—no random seeds, no clocks, no network, and no model drift—so the same n always yields the same string and the same value always gets the same yes-or-no membership answer.
Where hexagonal numbers show up in real work
Discrete math and combinatorics educators need the classic sequence on slides and answer keys: centered hexagonal lattices, honeycombs, and polygonal-number hierarchies all share H of n, and a single calculator landing keeps demos honest across those interpretations. Project Euler style problems and recreational math puzzles often combine triangular, pentagonal, and hexagonal filters; an exact membership test avoids off-by-one mistakes when students implement the inverse square-root criterion themselves. Data-structure and graphics demos that lay out dots in hexagonal rings can validate ring sizes against H of n before rendering.
Product demos and interview prep often show a short polygonal table; computing H of n or testing a candidate in one call keeps interactive demos aligned with textbooks. If you later need pentagonal numbers, centered hexagonal numbers, hexagonal-pyramidal volumes, or modular figurate values for cryptographic-sized indices, treat those as separate search intents rather than overloading this hexagonal calculator landing.
What you can do with it
Teaching figurate numbers
Show students the hexagonal sequence as exact strings so large terms stay correct and H(1)=1 through H(5)=45 matches textbook tables and lattice diagrams.
Polygonal filters in pipelines
Test candidate integers for hexagonality when combining triangular, pentagonal, and hexagonal constraints in batch scripts or Project Euler-style solvers.
FAQ
What formula does this hexagonal calculator use?
H(n) = n × (2n − 1), computed with exact BigInt multiplication. Membership uses the inverse: n = (1 + √(1 + 8x)) / 4 must be a non-negative integer (integer square root, no floats).
Why is value a string instead of a number?
Hexagonal numbers grow as O(n²) and eventually leave JavaScript safe integers. Decimal strings keep every digit exact for large n and large checks.
What happens if n is negative?
Hexagonal indices are defined for n >= 0; negative indices are not accepted.
Is H(0) allowed?
Yes. H(0) equals 0 under the product formula. Only negative n is rejected. The membership test also treats 0 as hexagonal with index 0.
What does it cost?
The browser tool is free and runs locally.
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/hexagonal-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/hexagonal-number", {
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/hexagonal-number",
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/hexagonal-number", 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/hexagonal-number", 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.hexagonal_number",
"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.
Limits
min_n | 0 |
max_n | 10000000 |
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 automated pipelines never silently diverge on the same n or the same membership check.
How the n-th hexagonal number is defined and checked
The same numbers appear as every other triangular number: H of n equals T of two n minus one, so hexagonal membership is a stricter filter on the triangular sequence. Returning values as decimal strings keeps JSON consumers honest when terms leave the safe-integer range of ordinary JavaScript numbers. Bounds keep n between zero and ten million so worst-case latency stays suitable for a free in-browser tool and a lightweight Worker path.
What you send and what you get back
At least one of n or value is required; you may send both in a single call. The error for negative n states that hexagonal numbers are defined for n greater than or equal to zero so form clients and scripts can correct the input without guessing. On a successful compute path the response includes the normalized n, value as the exact H of n written in decimal, and formula as the string n times open parenthesis two times n minus one close parenthesis. Provide a non-negative integer under the field n, or the alias index, to compute the n-th hexagonal number. Provide a non-negative integer under the field value, or the aliases check or number, to test whether that integer is hexagonal. Missing fields, non-integers, decimals, and any negative n are rejected with invalid_input and are not charged. On a successful check path the response includes check_value, is_hexagonal as a boolean, value as the decimal form of the input, and when the answer is true also n and hexagonal_index for the matching index. Example checks: n equals five yields value forty-five; n equals one yields value one; n equals two yields value six; value forty-five yields is_hexagonal true with index five; value ten yields is_hexagonal false; n equals negative one yields invalid_input mentioning negative. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where hexagonal numbers show up in real work
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
Contest and homework fixtures
Generate exact H(n) decimal strings and membership answers for olympiad problems, programming exercises, and automated answer keys that reject floating-point drift.