Combinations calculator
Find how many ways you can choose items when order does not matter: any 3 of 10 books for a weekend bag give 120 different bags, C(10,3), and the result stays exact for huge counts. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Non-negative total items
- 10
- Resistance (Ω)
- 3
- Quantity
- 120
The binomial coefficient answers a simple counting question: given n distinct items, how many ways can you choose a subset of size r when order does not matter? That quantity is written C(n,r), n choose r, or nCr, and equals n factorial divided by r factorial times (n minus r) factorial. This capability evaluates that formula with BigInt arithmetic so large coefficients stay exact instead of overflowing floating-point or safe-integer limits.
What n choose r means and why BigInt matters
Combinations count unordered selections. If you have ten books and want any three for a weekend bag, the number of distinct bags is C(10,3), which expands to ten factorial over three factorial times seven factorial and equals one hundred twenty. Order does not matter: picking book A then B then C is the same combination as C then B then A, which is why combinations are smaller than permutations of the same n and r.
The classical factorial form is easy to write but disastrous to evaluate naively for large n, because n! grows faster than any fixed-width integer type can hold long before the final ratio is moderate. This tool therefore multiplies and divides in a reduced loop—equivalent to building the product (n−r+1)…n over 1…r—using JavaScript BigInt so every intermediate stays exact and the final count is returned as a decimal string.
Symmetry C(n,r)=C(n,n−r) cuts the loop to min(r,n−r) steps.
What you can do with it
Programming contest and interview prep validators
Assert candidate solutions for combination-counting problems without reimplementing multiprecision binomial arithmetic in every language harness.
Probability demos and binomial model setup
Pull exact C(n,k) values when building binomial probability tables or teaching combinatorics so denominators stay exact before any floating probability step.
FAQ
What is n choose r (the binomial coefficient)?
C(n,r) counts how many ways to choose r items from n distinct items when order does not matter. It equals n! / (r! × (n−r)!).
Why is the count returned as a string?
Large coefficients exceed JavaScript safe integers. A decimal string keeps the exact value for every supported n without precision loss.
What happens if r is greater than n or negative?
Combinations are only defined here for 0 ≤ r ≤ n with non-negative integers.
Is the combinations calculator free?
The browser tool is free and runs locally.
How many ways can I pick 3 books out of 10?
120 ways. Enter 10 as the total and 3 as the number to choose; picking A, B and C is the same bag as C, B and A, so the order adds no new options.
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/combo/combinations \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":10,"r":3}'const res = await fetch("https://api.kit.forhosting.com/combo/combinations", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 10,
"r": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/combo/combinations",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 10,
"r": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/combo/combinations", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":10,"r":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":10,"r":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/combo/combinations", 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": 10,
"r": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "combo.combinations",
"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
max_n | 10000 |
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
Students, teachers, data scientists, and contest programmers get a deterministic JSON count—no computer-algebra install, no random sampling, and the same pure function in the free browser tool and the prepaid API path—so homework checks, pipeline validation, and interview sandboxes all share one reproducible answer.
What n choose r means and why BigInt matters
Boundary cases are well defined: C(n,0) and C(n,n) are always one, C(n,1) equals n, and any r greater than n or any negative index is rejected as invalid_input rather than inventing an extension. That contract matches standard combinatorics textbooks and programming-contest judges, so you can trust the number against hand calculations for small n and against known tables for larger ones without floating-point drift or silent wraparound.
How to call the API and read the response
Field n is the total number of distinct items—the upper index of the binomial coefficient—and must be an integer from zero through ten thousand. Field r is how many items you choose—the lower index—and must be an integer from zero through n. /(r!( n-r)!) so clients can display or log the identity without hard-coding it. Use it from homework graders, programming-contest validators, interview-prep sandboxes, spreadsheet enrichment jobs, probability demos that need C(n,k) for binomial probabilities, or any workflow that needs a reproducible combinations count without installing multiprecision packages on every machine that runs the pipeline. Send a JSON body with two required non-negative integers. Aliases total and N are accepted for the same meaning. Aliases k, choose, and R map to r. A successful response returns n and r as numbers, count as a decimal string of the exact binomial value, and formula as the string C(n,r)=n! Failed validation—missing n or r, a non-integer, a fraction, a value above the published maximum, a negative number, or r greater than n—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item and zero marginal unit price.
Practical tips, limits, and related intents
When teaching, prefer paired examples: n equals ten and r equals three yields one hundred twenty; n equals five and r equals zero yields one; n equals five and r equals six demonstrates the hard rejection path for r greater than n; and a negative r demonstrates the negative rejection path. Sibling landings may target permutations, factorials, or figurate numbers; this page is specifically for people searching for a combinations calculator, nCr calculator, or binomial coefficient tool. Do not confuse combinations with permutations: if order matters, you need P(n,r) equals n! /(n−r)!, which is a different intent and a different landing. Keep n at most ten thousand so worst-case C(10000,5000) finishes quickly on the Worker and in the browser while still covering contest and teaching sizes far beyond safe Number range. If you need multiprecision coefficients with n in the hundreds of thousands, use a dedicated big-integer stack offline—this lightweight parse capability is built for interactive checks, API glue, and classroom demos. Because the multiplicative formula is deterministic, students can recompute small cases by hand or with a spreadsheet and match the API line by line. Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when users type bad values while learning the contract. Prefer exact string counts over forcing a JavaScript Number so large coefficients never lose low-order digits in JSON transport.
Integration use cases
Homework and exam grading for binomial coefficients
Give students n and r and check their hand-computed nCr against a deterministic API or free browser result without floating-point ambiguity.
Technical questions
Is C(n,0) or C(n,n) supported?
Yes. Both equal 1 for any valid non-negative n, including n = 0 where C(0,0) = 1.