Enter two nonnegative integers, x and y, to calculate their Cantor pairing. The formula assigns a unique nonnegative integer to each ordered pair. This calculator uses the convention that adds y after the triangular-number term, so the order of your inputs matters.
Pairs with the same sum s = x + y lie on the same diagonal. The triangular number s(s + 1)/2 counts all pairs on earlier diagonals. Adding y selects the position along the current diagonal.
For x = 2 and y = 3, the sum is 5, the triangular term is 5 × 6 / 2 = 15, and the paired integer is 15 + 3 = 18.
Each diagonal produces consecutive integers, and the next diagonal starts immediately after the previous one ends. Consequently, over all nonnegative integer inputs, every nonnegative integer corresponds to exactly one ordered pair.
| x | y | x + y | Paired integer |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 2 |
| 2 | 0 | 2 | 3 |
| 1 | 1 | 2 | 4 |
| 0 | 2 | 2 | 5 |
| 2 | 3 | 5 | 18 |
| 3 | 2 | 5 | 17 |
Use whole numbers from 0 through 1,000,000 for each input. The two fixed formula constants must remain 1 and 2. Negative numbers and fractions are outside the pairing domain; a displayed result for a fractional input is not a valid Cantor pairing.
The maximum permitted pair, (1,000,000, 1,000,000), produces 2,000,002,000,000. These bounds keep the result and all intermediate integer arithmetic within the exact integer range of standard double-precision arithmetic. The mathematical formula extends beyond these bounds, but this calculator is not an arbitrary-precision implementation.
An unavailable result is not zero. Zero is the valid result for (0, 0).
Does swapping x and y change the result?
Yes, unless x and y are equal. The triangular term stays the same, but the final added value changes. For example, (2, 3) maps to 18 while (3, 2) maps to 17.
Why do some formulas add x instead of y?
Adding x enumerates each diagonal in the opposite direction. Both conventions give a one-to-one pairing, but they generally assign different integers to the same ordered pair. Use the same convention when encoding and decoding.
Is Cantor pairing encryption?
No. It is a reversible mathematical encoding without a secret key. It does not conceal the input pair.

