
What Punycode is
Hostnames in DNS allow Latin letters, digits and hyphens and nothing else. Your browser turns münchen.de into xn--mnchen-3ya.de with the Punycode algorithm from RFC 3492 and shows the original spelling in the address bar.
The browser encodes each label on its own and adds the xn-- prefix. Latin labels stay as they are: bücher.example.com becomes xn--bcher-kva.example.com. To encode, this converter hands the name to your browser's URL parser and falls back to its own RFC 3492 encoder if the parser rejects it.
Cyrillic а, е, о, р, с and х look identical to Latin a, e, o, p, c and x. Scammers register a domain with one swapped letter and pass it off as a well-known site. The Check column warns when a label mixes scripts, and also when a Cyrillic label consists of look-alike letters alone.
When it helps
- Your hosting panel, DNS or nginx config only accepts xn--, and your domain has accents or non-Latin letters.
- An xn-- address turned up in logs or an email, and you want to know what site it is.
- You check a link from an email for swapped letters.
- You prepare a domain list for an SSL certificate or a scraper.
What xn-- means: the ACE prefix and label encoding
xn-- is the ACE prefix, short for ASCII Compatible Encoding. IDNA reserves it for encoded labels, so a browser or mail server that meets it treats the rest of the label as Punycode. The encoder copies the plain ASCII characters of a label first and adds a hyphen after them. It then writes the other characters and their positions as base-36 digits, using a to z and 0 to 9. In xn--mnchen-3ya, mnchen holds the ASCII letters of münchen, and 3ya tells the decoder to insert ü after the m. A label with no ASCII characters gets no hyphen: пример becomes xn--e1afmkfd. Chrome and other browsers that follow the WHATWG URL standard keep ß, as IDNA2008 does, so straße.de becomes xn--strae-oqa.de. The older IDNA2003 rules turn the same name into strasse.de.
Homograph attacks: xn-- look-alikes and what the Check column flags
In 2017 security researcher Xudong Zheng registered аррӏе.com, spelled in Cyrillic letters alone. Its Punycode form is xn--80ak6aa92e.com, yet Chrome and Firefox of that year showed it in the address bar as apple.com. Paste it here and the Check column marks it caution: the label is Cyrillic, but every letter looks Latin. A single swapped letter gets a different warning. Type аpple.com with a Cyrillic а and the converter reports that the label mixes Cyrillic and Latin. The look-alike list covers а, е, о, р, с, у, х, і, ј, ѕ, һ, ӏ and three rarer Cyrillic letters. The converter skips the look-alike test under a non-Latin zone such as .рф, where Cyrillic names are normal, and has no look-alike list for Greek. A fine status describes the scripts in the name, so judge the site itself by other signs before you log in.
IDN conversion in Python, Node.js and PHP code
In Python, 'münchen.de'.encode('idna') returns b'xn--mnchen-3ya.de', and .decode('idna') reverses it. That built-in codec follows IDNA2003 and turns ß into ss. The idna package from PyPI follows IDNA2008 through idna.encode() and idna.decode(). In Node.js, url.domainToASCII('münchen.de') returns xn--mnchen-3ya.de, and url.domainToUnicode() decodes. In PHP with the intl extension, call idn_to_ascii('münchen.de', IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) and idn_to_utf8() for the way back. Paste a few of your names into this page to compare its output with your code.