English [en]

GNU IDN Library - Libidn


GNU Libidn is a fully documented implementation of the Stringprep, Punycode and IDNA specifications. Libidn's purpose is to encode and decode internationalized domain names. The native C, C# and Java libraries are dual-licensed, at your choice, under the GNU Lesser General Public License version 3.0 (or later) or the GNU General Public License version 2.0 (or later).

The library contains a generic Stringprep implementation. Profiles for Nameprep, iSCSI, SASL, XMPP and Kerberos V5 are included. Punycode and ASCII Compatible Encoding (ACE) via IDNA are supported. A mechanism to define Top-Level Domain (TLD) specific validation tables, and to compare strings against those tables, is included. Default tables for some TLDs are also included.

The Stringprep API consists of two main functions, one for converting data from the system's native representation into UTF-8, and one function to perform the Stringprep processing. Adding a new Stringprep profile for your application within the API is straightforward. The Punycode API consists of one encoding function and one decoding function. The IDNA API consists of the ToASCII and ToUnicode functions, as well as an high-level interface for converting entire domain names to and from the ACE encoded form. The TLD API consists of one set of functions to extract the TLD name from a domain string, one set of functions to locate the proper TLD table to use based on the TLD name, and core functions to validate a string against a TLD table, and some utility wrappers to perform all the steps in one call.

The library is used by, e.g., GNU SASL and Shishi to process user names and passwords. Libidn can be built into GNU Libc to enable a new system-wide getaddrinfo flag for IDN processing.

Libidn is developed for the GNU/Linux system, but runs on over 20 Unix platforms (including Solaris, IRIX, AIX, and Tru64) and Windows. The library is written in C and (parts of) the API is also accessible from C++, Emacs Lisp, Python and Java. A native Java and C# port is included.

Also included is a command line tool, several self tests, code examples, and more, all licensed under the GNU General Public License version 3.0 or later.

Table of Contents


Note that new releases are only mentioned here if they introduce a major feature or is significant in some other way. Read the help-libidn mailing list if you seek more frequent announcements.

Information on what is new in the library itself is found in the NEWS file (live version).

Try it

A web interface to libidn is available online. Try libidn before you buy it.

A simple IDN web server is also available.


Refer to the Libidn Manual web page for links to the manual in all formats; however, quick links to the most popular formats:

You may also be interested in a preliminary document with Nameprep and IDNA test vectors.

See also the various standard texts:


Libidn can be found on http://ftp.gnu.org/gnu/libidn/ [via HTTP] and ftp://ftp.gnu.org/gnu/libidn/ [via FTP]. It can also be found on one of our FTP mirrors; please use a mirror if possible.

All official releases since version 1.29 are signed with an OpenPGP key with fingerprint 9AA9 BDB1 1BB1 B99A 2128 5A33 0664 A769 5426 5E8C. Earlier releases are signed with an OpenPGP key with fingerprint 0424 D4EE 81A0 E3D1 19C6 F835 EDA2 1E94 B565 716F.


A mailing list where users of Libidn may help each other exists, and you can reach it by sending e-mail to help-libidn@gnu.org. Archives of the mailing list discussions, and an interface to manage subscriptions, is available through the World Wide Web at https://lists.gnu.org/mailman/listinfo/help-libidn.

If you are interested in paid support for Libidn, or sponsor the development, please contact me. If you provide paid services for Libidn, and would like to be mentioned here, also contact me.

If you find Libidn useful, please consider making a donation. No amount is too small!


There is a Savannah Libidn project page. You can check out the sources by using git as follows:

$ git clone git://git.savannah.gnu.org/libidn.git

The online git interface is available.

Notifications of each commit is sent to libidn-commit@gnu.org.

If you have trouble using git, you may download a daily snapshot. The snapshots are prepared similar to regular releases, i.e., you simply build them using ./configure && make.

Build logs from building the package, where you can also contribute a build system for your own platform, are available from the Libidn autobuild page.

For every release, we publish cyclomatic code complexity charts for the package. There is also self-test code coverage charts available. Finally, clang-analyzer output is also available.


Report all problems to bug-libidn@gnu.org, but please read the manual on how to report bugs first.

Related implementations

The following is a list of links to other free IDN, or otherwise related, implementations. The list is not conclusive, suggestions appreciated.

Projects using GNU Libidn include:

Projects using libidn2 include:

Let us know about more projects that use GNU Libidn!

How to use it?

Read data from user, convert it to UTF-8 and then pass it to stringprep(). Example code below (it is included in the distribution as example.c). To simplify compiling, use libtool and pkg-config. More information and more examples are included in the manual.

See also the other example*.c files in the source distribution on how to use other features of the library (punycode, IDNA).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

 * Compiling using libtool and pkg-config is recommended:
 * $ libtool cc -o example example.c `pkg-config --cflags --libs libidn`
 * $ ./example
 * Input string encoded as `ISO-8859-1': ª
 * Before locale2utf8 (length 2): aa 0a
 * Before stringprep (length 3): c2 aa 0a
 * After stringprep (length 2): 61 0a
 * $

int main(int argc, char *argv[])
  char buf[BUFSIZ];
  char *p;
  int rc, i;

  printf("Input string encoded as `%s': ",
	 stringprep_locale_charset ());
  fgets(buf, BUFSIZ, stdin);

  printf("Before locale2utf8 (length %d): ", strlen(buf));
  for (i=0; i < strlen(buf); i++)
    printf("%02x ", buf[i] & 0xFF);

  p = stringprep_locale_to_utf8 (buf);
  if (p)
      strcpy(buf, p);
    printf("Could not convert string to UTF-8, continuing anyway...\n");

  printf("Before stringprep (length %d): ", strlen(buf));
  for (i=0; i < strlen(buf); i++)
    printf("%02x ", buf[i] & 0xFF);

  rc = stringprep(buf, BUFSIZ, 0, stringprep_nameprep);
  if (rc != STRINGPREP_OK)
    printf("Stringprep failed with rc %d...\n", rc);
      printf("After stringprep (length %d): ", strlen(buf));
      for (i=0; i < strlen(buf); i++)
        printf("%02x ", buf[i] & 0xFF);

  return 0;


Libidn2 is an implementation of the IDNA2008 specifications (RFC 5890, RFC 5891, RFC 5892, RFC 5893) and TR46.

Libidn2 is a standalone library, without any dependency on Libidn. Libidn2 is believed to be a complete IDNA2008/TR46 implementation, but has yet to be as extensively used as the IDNA2003 Libidn library.

The installed C library libidn2 is dual-licensed, at your choice, between LGPLv3+ and GPLv2+, while the rest of the package is GPLv3+. See the file COPYING for detailed information.

Libidn2 uses GNU libunistring for Unicode processing and GNU libiconv for character set conversion.

Libidn2 can be downloaded from https://alpha.gnu.org/gnu/libidn/ [via HTTP] and ftp://alpha.gnu.org/gnu/libidn/ [via FTP]. It can also be found on one of our FTP mirrors; please use a mirror if possible.

The following documentation of libidn2 exists:

Development of libidn2 is done through the GitLab libidn2 page, where you can view and download the source code (and more). There is a libidn2 issue tracker if you want to report a problem in libidn2.

For Quality Assurance, we publish code coverage report and clang static analyzer output.

Initial development of Libidn2 has been sponsored by DENIC.


 [FSF logo] “Our mission is to preserve, protect and promote the freedom to use, study, copy, modify, and redistribute computer software, and to defend the rights of Free Software users.”

The Free Software Foundation is the principal organizational sponsor of the GNU Operating System. Support GNU and the FSF by buying manuals and gear, joining the FSF as an associate member, or making a donation, either directly to the FSF or via Flattr.