Bell number calculator
B(5) is 52: there are 52 ways to split five distinct items into non-empty groups when the order of the groups does not matter. Enter any n from 0 to 20 and get the exact Bell number, for combinatorics homework or set partitions. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Index n
- 0
- Bell number
- 1
free
What a Bell number counts
A Bell number answers a simple counting question: in how many ways can you split a set of n distinct items into groups, where no group is empty and neither the order of the groups nor the order inside a group matters? For three items there are 5 ways: all together, each on its own, or one of three possible pairs with the remaining item alone. The sequence starts 1, 1, 2, 5, 15, 52, 203 and 877 for n from 0 to 7, and it grows quickly. Because group order is ignored, B(n) is also the sum of the Stirling numbers of the second kind over every possible number of groups.
How it is calculated, and where it is used
Each Bell number is built from the ones before it. To get the next value, the calculator adds up the earlier Bell numbers, each multiplied by a binomial coefficient, the same rule behind the Bell triangle, so no huge factorial is ever formed and every result stays an exact whole number. The range runs from 0 to 20, the span used in combinatorics courses on set partitions and Stirling numbers, where small cases can be checked by hand. A common mistake is to count orderings: splitting items into groups A and B is the same partition as B and A, and treating them as different inflates the count.
The recurrence used
Internally the value is built with a bottom-up recurrence rather than a static lookup table. Starting from B(0)=1, each new B(i+1) is accumulated as the sum over k of C(i,k)·B(k), where the binomial coefficient C(i,k) is generated incrementally with the multiplicative update c = c·(i−k+1)/k, which avoids ever forming a factorial that could overflow. The running sum is passed through Math.round before being stored, repairing the tiny floating-point error the division can introduce, so every stored B(i) stays an exact integer.
This is the same identity that underlies the Bell triangle, evaluated in O(n²) additions.
What you can do with it
Combinatorics coursework
Check partition counts B(0)–B(20) while teaching set partitions and Stirling numbers, with exact integers students can verify by hand for small n.
FAQ
What does this compute?
The Bell number B(n): the number of ways to partition a set of n elements into non-empty, unordered blocks. It echoes n and returns value.
Why is n capped at 20?
B(20) = 51,724,158,235,372 is the largest Bell number that fits exactly in a double, so above 20 the result could no longer be exact. n must be an integer 0–20.
Is the answer exact?
Yes. Each term is rounded back to an integer inside the recurrence, so value is an exact integer, not a floating-point approximation.
How many ways can three items be split into groups?
Five, which is B(3). All three can stay together, each can stand alone, or one of three possible pairs can form while the remaining item sits by itself.
How are Bell numbers related to Stirling numbers?
A Bell number is the sum of the Stirling numbers of the second kind for the same n, taken over every possible number of groups. Each Stirling number counts the splits into exactly that many groups.
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/bell-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/bell-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/bell-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/bell-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/bell-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.bell_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.
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
Enter a non-negative integer n (0 to 20) and get B(n), the number of ways to partition a set of n elements into non-empty, unordered blocks, returned as an exact integer in JSON. Free in the browser or via API from $0.002.
What B(n) counts
Because a partition ignores block order and element order within a block, B(n) also equals the sum of the Stirling numbers of the second kind over all possible block counts. The result is an exact integer, never a float or an approximation, so downstream code can compare it directly. Given a non-negative integer n, this endpoint returns B(n), the Bell number, which counts the ways a set of n distinct elements can be partitioned into non-empty, unordered blocks. B(0) and B(1) both equal 1, then the sequence grows 2, 5, 15, 52, 203, 877 for n = 2 through 7. The request body carries a single required field, n, and the response echoes it alongside value, the computed Bell number, as plain JSON such as {"n":5,"value":52}.
The recurrence used
Every intermediate B(k) up to n is computed once and reused, so a call for n=20 performs only a few hundred operations and returns immediately, with no recursion depth to blow and no memoization cache to warm between requests.
Range, validation and access
Validation is strict and happens before any computation. Negative n, fractional n, strings, arrays, and a missing n are all rejected the same way. The input must be a JSON object, n must be an integer, and it must fall in the closed range 0 to 20; anything else throws a typed invalid_input error whose message names the offending field instead of a bare exception. The upper bound of 20 is deliberate: B(20) equals 51,724,158,235,372, the largest Bell number that still fits exactly in a JavaScript double-precision number, so the endpoint never silently returns a rounded-off big integer.
Integration use cases
Test fixtures
Generate known-good Bell numbers as golden values for unit tests of your own partitioning, clustering, or enumeration code.
Sequence tooling
Populate OEIS A000110 lookups or spreadsheets in bulk over the API without shipping a big-integer library to the client.
Technical questions
What does bad input return?
A typed invalid_input error naming the field — for example a non-integer, negative, or out-of-range n, or a missing n.
Is it free?
Yes in the browser as a tier A widget. The API costs $0.002 per successful call; failed tasks are not charged.