Catalan number calculator
Get the exact n-th Catalan number: C(5) is 42 and C(10) is 16796, written out digit for digit with no rounding, even for very large n. Handy for combinatorics homework, answer keys and checking recurrences. 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
- 42
Catalan numbers count balanced structures that appear everywhere in combinatorics and computer science: correctly matched parentheses, binary trees with n+1 leaves, non-crossing handshakes, monotonic lattice paths that never rise above the diagonal, and triangulations of a convex polygon. The closed formula is C(n) equals one over n plus one times the central binomial coefficient of 2n choose n, with the base case C(0) equal to one. This calculator accepts a non-negative integer index n and returns the exact Catalan value as a decimal string computed with BigInt arithmetic, so terms far beyond ordinary floating-point or safe-integer limits stay correct digit for digit. Negative indices are rejected with a clear validation error rather than a silent wrong answer.
How the n-th Catalan number is defined and computed
The Catalan sequence begins C(0) equals one, C(1) equals one, C(2) equals two, C(3) equals five, C(4) equals fourteen, C(5) equals forty-two, C(6) equals one hundred thirty-two, and grows roughly like four to the n over n to the three-halves. The classical formula C(n) equals binomial of 2n choose n divided by n plus one is exact for every non-negative integer n; an equivalent product form multiplies successive factors without building the full binomial numerator first.
This implementation never uses floating-point approximation or Binet-style shortcuts: it starts from C(0) equals one and applies the exact recurrence C(i) equals C(i minus one) times four i minus two, all divided by i plus one, for i from one through n, using BigInt so every intermediate and final digit is integer-exact. 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.
Where Catalan numbers show up in real work
Compiler and language tools count Dyck words, balanced parentheses, and abstract syntax tree shapes that Catalan numbers enumerate; an exact C(n) check confirms table sizes and dynamic-programming recurrences without off-by-one mistakes. Discrete math and combinatorics educators need the classic sequence on slides and answer keys: correctly matched parentheses of n pairs, binary trees, polygon triangulations, and non-crossing partitions all share C(n), and a single calculator landing keeps demos honest across those interpretations.
Product demos and interview prep often show a short Catalan table; computing C(n) in one call keeps interactive demos aligned with textbooks. If you later need Motzkin numbers, Schröder numbers, Ballot numbers, or modular Catalan values for cryptographic-sized n, treat those as separate search intents rather than overloading this calculator landing.
What you can do with it
Teaching balanced structures
Show students the Catalan sequence as exact strings so large terms stay correct and C(0)=1 through C(5)=42 matches textbook tables.
Compiler and DP table sizes
Confirm how many balanced trees, Dyck words, or triangulations of size n exist when sizing tables or validating recurrence code.
FAQ
What formula does this Catalan calculator use?
C(n) = (1/(n+1)) × binomial(2n, n), computed via the exact recurrence C(i) = C(i−1)×(4i−2)/(i+1) with BigInt. C(0) = 1.
Why is value a string instead of a number?
Catalan numbers grow past JavaScript safe integers by C(30). Decimal strings keep every digit exact for large n.
What happens if n is negative?
Catalan numbers are defined for n >= 0; negative indices are not accepted.
Is C(0) allowed?
Yes. C(0) equals 1 under the standard definition. Only negative n is rejected.
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/catalan-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/catalan-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/catalan-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/catalan-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/catalan-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.catalan_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 | 5000 |
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 homework demos and automated pipelines never silently diverge on the same n.
How the n-th Catalan number is defined and computed
Returning the value as a decimal string keeps JSON consumers honest: Catalan numbers leave the safe-integer range of ordinary JavaScript numbers by C(30), and a numeric type would silently round. Bounds keep n between zero and five thousand so worst-case latency stays suitable for a free in-browser tool and a lightweight Worker path, while still covering contest, classroom, and pipeline needs.
What you send and what you get back
The error for negative n states that Catalan numbers are defined for n greater than or equal to zero so form clients and scripts can correct the input without guessing. On success the response always includes the normalized n and value as the exact n-th Catalan number written in decimal. Provide a required non-negative integer under the field n, or the aliases number or index. The value must be an integer from zero through five thousand inclusive; missing fields, non-integers, decimals, and any n below zero are rejected with invalid_input and are not charged. Example checks: n equals zero yields value one; n equals one yields value one; n equals two yields value two; n equals three yields value five; n equals five yields value forty-two; n equals ten yields value sixteen thousand seven hundred ninety-six; n equals negative one yields invalid_input. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where Catalan 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 C(n) decimal strings for olympiad problems, programming exercises, and automated answer keys that reject floating-point drift.