ForHosting KIT · Math

Handshake problem calculator

Find how many handshakes happen when everyone in a group greets everyone else once: 5 people make 10 handshakes and 4 make 6, and a total such as 10 turns back into 5 people. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Number of people
5
You get
Calculation mode
forward
Handshakes
10
Max n
1,000,000

This handshake problem calculator answers the classic combinatorics question: if n people meet and every pair shakes hands exactly once, how many handshakes take place? The closed form is n choose two, written C(n, 2) = n(n − 1)/2, the same triangular numbers that appear in graph theory as the edge count of a complete graph K_n. The tool also runs the inverse: given a handshake total that is an exact C(n, 2) value, it recovers the unique non-negative integer people count n. Small checks you already know include five people yielding ten handshakes, four people yielding six, and zero or one person yielding zero. The engine uses deterministic BigInt arithmetic only—no network calls, no sampling, and no date-dependent shortcuts.

What the handshake count means and what you get

The handshake problem is the everyday story behind the binomial coefficient C(n, 2). Each handshake is an unordered pair of people, so the total is the number of ways to choose two people from n with no repetition and no regard to order. That is exactly n times n minus one, divided by two, because you can line people up and pair each person with everyone later in line without double-counting.

The same integer is the number of edges in the complete graph on n vertices, the (n − 1)-st triangular number when indexed from zero carefully, and a standard warm-up in discrete mathematics courses. This calculator returns a mode flag of forward or inverse, the people count n, the exact handshake total as a decimal string, a short formula string such as C(5, 2) = 5*(5-1)/2, and the published maximum n so clients can validate before they send a batch.

If you need ordinary combinations with a free k, permutations, or multiset combinations with repetition, use those dedicated tools; this page answers only the handshake count and its exact inverse.

Where handshake counts fit in study, code, and modeling

Students meet the handshake problem when a textbook introduces combinations, when a teacher asks how many games a round-robin tournament needs, or when graph theory first defines the complete graph K_n. Teachers can pre-generate answer keys for modest n without trusting opaque calculator apps that round large integers or silently switch to scientific notation. Developers call the same contract from scripts to seed deterministic test vectors, to size pairwise comparison workloads, or to satisfy programming-challenge statements that demand the exact C(n, 2) value rather than a floating approximation.

Contest practice often needs a fast, offline source of triangular handshake ranks so solutions can be checked without downloading OEIS tables under time pressure. Product and operations analysts use the count when estimating how many one-to-one meetings or unique undirected edges arise among n participants if every pair interacts once. The inverse path is equally useful: given a reported meeting total that claims full pairwise coverage, recover n and verify the figure is combinatorially possible before it enters a dashboard.

Homework and combinatorics checks

Look up exact C(n, 2) handshake totals and invert triangular handshake counts for textbook exercises and quizzes.

Round-robin and pairwise sizing

Count undirected pairs among n participants for tournaments, meeting plans, or complete-graph edge estimates.

What does the handshake problem calculator cost?

It is free in your browser on this page.

How is the handshake count defined?

If every pair among n people shakes hands once, the total is C(n, 2) = n(n − 1)/2.

Why is the result a string instead of a number?

Handshake totals grow quadratically and can exceed JavaScript safe integers for large n.

Can I find out how many people were there from the number of handshakes?

Yes. Enter the handshake total instead of the people count and you get the group size back: 10 handshakes means 5 people. The total must match a real group exactly, or it is rejected.

How large a group can the calculator handle?

Up to one million people. Every result stays exact at that size, even though the number of handshakes grows roughly with the square of the group.

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.

POSThttps://api.kit.forhosting.com/combo/handshake

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.

curl -X POST https://api.kit.forhosting.com/combo/handshake \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":5}'
{
  "n": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "combo.handshake",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_n1000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Negative people counts are rejected with invalid_input so bad spreadsheet cells never become silent wrong answers.

What the handshake problem counts and what the response contains

There is no approximate floating-point path presented as truth and no random sampling of pairs: the engine either builds the exact product with BigInt inside the supported range or rejects the input with invalid_input. Rejected cases include missing both n and handshakes, non-integers, fractions, scientific notation, values above the documented ceiling, any negative n, negative handshake totals, and handshake totals that are not exactly some C(n, 2).

How n and handshakes are read and how the inverse triangular root works

Optional leading plus signs are allowed on non-negative values; embedded spaces, hex prefixes, and exponential notation are rejected with a clear message so a bad cell does not become a wrong count. Zero and one for n are valid and return zero handshakes, matching the empty complete graph and the single-vertex graph. If both fields are supplied, the engine checks consistency so a mismatched pair fails loudly instead of picking one side silently. The preferred fields are n for the number of people and handshakes for the total to invert, but aliases people and persons for n and h and count for handshakes are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. The engine enforces a hard maximum of one million on n, which keeps memory and latency inside a predictable budget on the free browser path and on the edge Worker even though triangular numbers grow quadratically. Forward mode multiplies n by n minus one with BigInt and divides by two so intermediate products never lose digits the way IEEE doubles would past the fifty-third bit. Inverse mode solves the quadratic n squared minus n minus two h equals zero by testing whether the discriminant one plus eight h is a perfect square via integer square root; when it is and the resulting n is an integer in range, that n is returned, otherwise invalid_input explains that the handshake total is not exact. Every intermediate is a BigInt and the final handshake count is serialized with toString so JSON never truncates large values. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing triangular roots yourself.

Where handshake counts fit in study, code, and modeling

On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result. Pair it with binomial or multiset-combination tools when you need related coefficients, with lattice-path counters when order of steps matters, and with other math endpoints when you are building a small lab of free, deterministic combinatorics helpers.

Deterministic test fixtures

Generate reproducible handshake decimal strings for unit tests, property checks, and CI assertions without hand-maintaining tables.

What happens if n is negative?

Negative people counts are rejected with invalid_input. The handshake problem requires n ≥ 0.

Can I recover n from a handshake total?

Yes. Supply handshakes (or h / count). The total must equal some exact C(n, 2); otherwise the request fails with invalid_input.

Read the full KIT documentation →