{
    "mode": "man",
    "parameter": "utf-8",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/utf-8/7/json",
    "generated": "2026-11-11T03:51:53Z",
    "sections": {
        "NAME": {
            "content": "UTF-8 - an ASCII compatible multibyte Unicode encoding\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The  Unicode 3.0 character set occupies a 16-bit code space.  The most obvious Unicode encod‐\ning (known as UCS-2) consists of a sequence of 16-bit words.   Such  strings  can  contain—as\npart  of  many  16-bit  characters—bytes such as '\\0' or '/', which have a special meaning in\nfilenames and other C library function arguments.  In addition, the majority  of  UNIX  tools\nexpect  ASCII  files  and  can't read 16-bit words as characters without major modifications.\nFor these reasons, UCS-2 is not a suitable external encoding of Unicode  in  filenames,  text\nfiles,  environment variables, and so on.  The ISO/IEC 10646 Universal Character Set (UCS), a\nsuperset of Unicode, occupies an even larger code space—31 bits—and the obvious UCS-4  encod‐\ning for it (a sequence of 32-bit words) has the same problems.\n\nThe  UTF-8  encoding of Unicode and UCS does not have these problems and is the common way in\nwhich Unicode is used on UNIX-style operating systems.\n",
            "subsections": [
                {
                    "name": "Properties",
                    "content": "The UTF-8 encoding has the following nice properties:\n\n•  UCS characters 0x00000000 to 0x0000007f (the classic US-ASCII characters) are encoded sim‐\nply as bytes 0x00 to 0x7f (ASCII compatibility).  This means that files and strings  which\ncontain only 7-bit ASCII characters have the same encoding under both ASCII and UTF-8.\n\n•  All  UCS  characters greater than 0x7f are encoded as a multibyte sequence consisting only\nof bytes in the range 0x80 to 0xfd, so no ASCII byte can appear as part of another charac‐\nter and there are no problems with, for example,  '\\0' or '/'.\n\n•  The lexicographic sorting order of UCS-4 strings is preserved.\n\n•  All possible 2^31 UCS codes can be encoded using UTF-8.\n\n•  The bytes 0xc0, 0xc1, 0xfe, and 0xff are never used in the UTF-8 encoding.\n\n•  The first byte of a multibyte sequence which represents a single non-ASCII  UCS  character\nis  always  in  the  range 0xc2 to 0xfd and indicates how long this multibyte sequence is.\nAll further bytes in a multibyte sequence are in the range 0x80 to 0xbf.  This allows easy\nresynchronization and makes the encoding stateless and robust against missing bytes.\n\n•  UTF-8 encoded UCS characters may be up to six bytes long,  however  the  Unicode  standard\nspecifies no characters above 0x10ffff, so Unicode characters can be only up to four bytes\nlong in UTF-8.\n"
                },
                {
                    "name": "Encoding",
                    "content": "The  following byte sequences are used to represent a character.  The sequence to be used de‐\npends on the UCS code number of the character:\n\n0x00000000 - 0x0000007F:\n0xxxxxxx\n\n0x00000080 - 0x000007FF:\n110xxxxx 10xxxxxx\n\n0x00000800 - 0x0000FFFF:\n1110xxxx 10xxxxxx 10xxxxxx\n\n0x00010000 - 0x001FFFFF:\n11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n\n0x00200000 - 0x03FFFFFF:\n111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx\n\n0x04000000 - 0x7FFFFFFF:\n1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx\n\nThe xxx bit positions are filled with the bits of the character code number in binary  repre‐\nsentation, most significant bit first (big-endian).  Only the shortest possible multibyte se‐\nquence which can represent the code number of the character can be used.\n\nThe  UCS code values 0xd800–0xdfff (UTF-16 surrogates) as well as 0xfffe and 0xffff (UCS non‐\ncharacters) should not appear in conforming UTF-8 streams.  According to RFC  3629  no  point\nabove U+10FFFF should be used, which limits characters to four bytes.\n"
                },
                {
                    "name": "Example",
                    "content": "The Unicode character 0xa9 = 1010 1001 (the copyright sign) is encoded in UTF-8 as\n\n11000010 10101001 = 0xc2 0xa9\n\nand character 0x2260 = 0010 0010 0110 0000 (the \"not equal\" symbol) is encoded as:\n\n11100010 10001001 10100000 = 0xe2 0x89 0xa0\n"
                },
                {
                    "name": "Application notes",
                    "content": "Users have to select a UTF-8 locale, for example with\n\nexport LANG=enGB.UTF-8\n\nin order to activate the UTF-8 support in applications.\n\nApplication  software  that  has to be aware of the used character encoding should always set\nthe locale with for example\n\nsetlocale(LCCTYPE, \"\")\n\nand programmers can then test the expression\n\nstrcmp(nllanginfo(CODESET), \"UTF-8\") == 0\n\nto determine whether a UTF-8 locale has been selected and  whether  therefore  all  plaintext\nstandard input and output, terminal communication, plaintext file content, filenames, and en‐\nvironment variables are encoded in UTF-8.\n\nProgrammers  accustomed  to single-byte encodings such as US-ASCII or ISO/IEC 8859 have to be\naware that two assumptions made so far are no longer valid in UTF-8 locales.  Firstly, a sin‐\ngle byte does not necessarily correspond any more to a  single  character.   Secondly,  since\nmodern  terminal  emulators  in UTF-8 mode also support Chinese, Japanese, and Korean double-\nwidth characters as well as nonspacing combining characters, outputting  a  single  character\ndoes  not  necessarily  advance the cursor by one position as it did in ASCII.  Library func‐\ntions such as mbsrtowcs(3) and wcswidth(3) should be used today to count characters and  cur‐\nsor positions.\n\nThe  official  ESC  sequence  to switch from an ISO/IEC 2022 encoding scheme (as used for in‐\nstance by VT100 terminals) to UTF-8 is ESC % G (\"\\x1b%G\").  The corresponding return sequence\nfrom UTF-8 to ISO/IEC 2022 is ESC % @ (\"\\x1b%@\").  Other ISO/IEC 2022 sequences (such as  for\nswitching the G0 and G1 sets) are not applicable in UTF-8 mode.\n"
                },
                {
                    "name": "Security",
                    "content": "The  Unicode  and  UCS  standards require that producers of UTF-8 shall use the shortest form\npossible, for example, producing a two-byte sequence with first byte 0xc0  is  nonconforming.\nUnicode  3.1  has added the requirement that conforming programs must not accept non-shortest\nforms in their input.  This is for security reasons: if user input is  checked  for  possible\nsecurity violations, a program might check only for the ASCII version of \"/../\" or \";\" or NUL\nand  overlook  that there are many non-ASCII ways to represent these things in a non-shortest\nUTF-8 encoding.\n"
                },
                {
                    "name": "Standards",
                    "content": "ISO/IEC 10646-1:2000, Unicode 3.1, RFC 3629, Plan 9.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "locale(1), nllanginfo(3), setlocale(3), charsets(7), unicode(7)\n\nLinux man-pages 6.7                          2024-03-14                                     UTF-8(7)",
            "subsections": []
        }
    },
    "summary": "UTF-8 - an ASCII compatible multibyte Unicode encoding",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "locale",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/locale/1/json"
        },
        {
            "name": "nllanginfo",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/nllanginfo/3/json"
        },
        {
            "name": "setlocale",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/setlocale/3/json"
        },
        {
            "name": "charsets",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/charsets/7/json"
        },
        {
            "name": "unicode",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/unicode/7/json"
        },
        {
            "name": "UTF-8",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/UTF-8/7/json"
        }
    ]
}