Summary

  • RFC 3492's Bootstring copied basic ASCII code points literally, then encoded every non-basic point as a delta carrying both code-point distance and an insertion position in the growing output.
  • Self-delimiting integers and an adaptive bias made that representation unique and reversible — but never a translation, a normalization, an IDNA validation, a registration receipt, or a proof of identity.

Type a domain name in Japanese, Arabic, or Russian, and the DNS hands back something that looks like a cat walked across the keyboard: xn-- followed by a stubborn little tail of letters and digits. That tail is not a cipher and not a translation. It is a receipt — proof that RFC 3492's Punycode took a sequence of Unicode code points, copied the easy ones, and packed the rest into arithmetic a decoder can unwind exactly.

Most people meet Punycode from the front, staring at the opaque half of an ASCII label. It is more interesting from the decoder's bench. The decoder does not translate a word. It rebuilds a sequence by starting with the characters that could already survive in ASCII and slotting everything else into exact gaps.

What Punycode Actually Encodes (Hint: Not Meaning)

Bootstring first segregates the basic code points. It copies them to the front in their original relative order. If at least one exists, a delimiter follows — for Punycode the basic set is ASCII and the delimiter is the hyphen-minus. This literal portion is not a miniature translation. It is simply the part of the input that needs no encoding.

The tail carries the missing structure. The decoder keeps two state variables: n, a candidate code-point value, and i, a possible insertion position in the output built so far. Advancing the state walks i through every gap; after the end, i wraps to zero and n increases. A delta says how many of those non-insertion states to cross before inserting the current n at the current i.

One Integer, Two Jobs

That is the compression that makes the whole scheme sing. A single nonnegative integer carries a distance through code-point space and a location in the growing string. The encoder processes non-basic points in numerical order — which tends to keep successive distances small — and derives the deltas that let the decoder rebuild the original order. The tail records position without ever writing an explicit position table.

Why the Integers Need Their Own Grammar

Several deltas must be concatenated, so ordinary positional integers would leave an ambiguity about where one ends and the next begins. Bootstring instead uses generalized variable-length integers. A threshold for each digit decides whether another digit follows. Exactly one final digit falls below its threshold. With little-endian digits, a decoder can peel off the first integer, then the next, while reading forward. For fixed thresholds, each nonnegative integer has exactly one representation.

The Bias That Guesses the Next Jump

The thresholds do not stay fixed across deltas. After every insertion, an adaptation function shifts a bias. A large first jump is damped hard; later jumps are scaled and adjusted for the number of code points already handled. The latest delta becomes a hint about the likely size of the next. This is not linguistic prediction. It is a local arithmetic forecast, spending fewer basic characters on nearby magnitudes.

Base 36, Bias 72, and the Arithmetic That Had to Be Guarded

Punycode fixed the mechanism at base 36, with letters carrying values zero through 25, digits carrying 26 through 35, an initial code point of 128, and an initial bias of 72. The parameter set shaped efficiency. Provided Bootstring's constraints held, the parameters did not change whether encoding and decoding were correct.

Correctness still demanded defensive arithmetic. RFC 3492 names overflow as a failure and shows where additions and multiplications must be checked. It argues that a 26-bit unsigned integer suffices for valid IDNA labels under Unicode and the 63-character DNS label limit. That bounded conclusion did not make unchecked overflow acceptable in a general implementation.

Uniqueness Was a Security Feature

Uniqueness mattered to security. If one Unicode sequence could acquire several ASCII encodings, those labels could live under different DNS authorities. Punycode avoided the split by offering at most one basic string per extended string. Yet the RFC immediately preserved the next boundary: different Unicode sequences may still count as “the same” text under some human, language, or normalization rule. Punycode never decided that question.

Where Punycode's Authority Ends

RFC 3490 placed Punycode inside IDNA's acceptance and display operations. IDNA2008 later kept Punycode A-labels while changing the surrounding preparation and validity rules. That continuity illustrates Lu Heng's minimum-initial-specification principle: a narrow reversible encoding could stay stable while policy about admissible code points, local mapping, and registration evolved elsewhere.

The reality-layer lesson is just as exact. Input code points, prepared code points, literal prefix, delta stream, reconstructed sequence, accepted A-label, registered name, DNS answer, and recognized identity are different receipts. Punycode joined two of them — a sequence and its ASCII representation. Its quiet triumph was refusing to pretend it had joined the rest.

Sources