Introduction
Before Unicode, each system and each group of languages had its own code page: a
table that gives each byte value a character. The single-byte code pages have 256
characters. Their first half, 00 to 7F, is ASCII, and the
second half holds the letters and symbols of one region: Windows-1252 and ISO 8859-1
for Western Europe, Mac OS Roman on the classic Mac, code page 437 on the IBM PC,
Windows-1251, KOI8-R and code page 866 for Russian. Chinese, Japanese and Korean need
thousands of characters, so their code pages use two bytes for each one beyond ASCII:
GBK, Big5, Shift_JIS, EUC-JP and EUC-KR. Windows calls both kinds “ANSI code pages”,
and Notepad still saves in the computer’s own code page under the name “ANSI”.
Strictly, each code page is a format of its own: the byte E9 is é in
Windows-1252, È in Mac OS Roman, Θ in code page 437 and й in Windows-1251. But nothing
in a text file says which one was used. There is no byte order mark and no header, and
a single-byte code page accepts every byte, so the file reads without error in all of
them. This page therefore describes them together, as one format, and the explorer
guesses which code page a file uses.
The code page shown is a guess. The explorer says so each time, gives its reasons, and shows what the commonest bytes would be in each candidate, so that a reader can judge. No program can be sure, and with only a few accented letters in a file a guess is often wrong.
A file dropped on any page of this site opens in the explorer, which shows its structure (each line, and the bytes of each character), the guessed code page with its reasons, a preview of the text in that code page, and the start of the file in every code page the explorer knows, each with a button that opens the whole text read that way.
Structure
The file has up to three parts, in this order. Only the lines are always there.
0Lines characters of one byte, or in East Asian code pages one or two, each line followed by its line endingvaries…End-of-file mark Ctrl-Z (1A) bytes, from MS-DOS programssometimes…Zero padding NUL bytes after the textrare
Byte order mark
Code pages have no byte order mark, and nothing else in the file names the code page.
Formats built on text can say it, as HTML does with <meta charset>
and email with its Content-Type header, but a plain text file cannot.
A file that starts with a Unicode byte order mark is one of the Unicode formats, not
this one: EF BB BF UTF-8,
FF FE UTF-16LE,
FE FF UTF-16BE,
FF FE 00 00 UTF-32LE and
00 00 FE FF UTF-32BE.
GB18030, China’s national encoding, has its own mark, 84 31 95 33, and
its own format; so do the
7-bit encodings of ISO-2022 and HZ,
UTF-7 and
EBCDIC.
Encoding
Single-byte code pages
Each byte is one character. To read it, look the byte up in the code page’s table
of 256 entries; to write a character, find it in the table and write its byte. A
character that is not in the table cannot be written at all, which is why each
region needed its own code page. Bytes 00 to 7F are ASCII
in every code page the explorer guesses between; 80 to FF
differ (see Code pages).
This 20-byte line was written in Windows-1252. Read in three code pages, the same bytes give three texts, and only one is right:
00000000 43 61 66 E9 20 93 71 75 6F 74 65 64 94 20 96 20 Caf. .quoted. .
00000010 35 B0 0D 0A 5...
| Read as | Text |
|---|---|
| Windows-1252 | Café “quoted” – 5° |
| Mac OS Roman | CafÈ ìquotedî ñ 5∞ |
| DOS code page 437 | CafΘ ôquotedö û 5░ |
| ISO 8859-1 | Café, then three invisible C1 control codes where the quotes and dash should be, and 5° |
The Russian word привет is EF F0 E8 E2 E5 F2 in Windows-1251,
D0 D2 C9 D7 C5 D4 in KOI8-R and AF E0 A8 A2 A5 E2 in DOS
code page 866.
Double-byte code pages
The East Asian code pages keep ASCII as single bytes and write every other
character as a lead byte above 7F followed by a trail byte. The lead
byte says that a second byte follows.
| Code page | Language | Windows code page | Bytes |
|---|---|---|---|
| GBK | Simplified Chinese | 936 | lead 81–FE, trail 40–7E or 80–FE; a lone 80 reads as € |
| Big5 | Traditional Chinese | 950 | lead 81–FE, trail 40–7E or A1–FE |
| Shift_JIS | Japanese | 932 | lead 81–9F or E0–FC, then a trail byte 40–7E or 80–FC; A1–DF alone are half-width katakana; JIS X 0201 puts ¥ at 5C and ‾ at 7E |
| EUC-JP | Japanese, on Unix | – | pairs of bytes A1–FE; 8E then a byte A1–DF for half-width katakana; 8F then two bytes (JIS X 0212), three in all |
| EUC-KR | Korean | 949 extends it | lead and trail A1–FE in EUC-KR proper; the wider code page 949, which browsers read, adds leads from 81 and trails 41–5A, 61–7A and 81–FE |
A trail byte is never 0A or 0D, so lines split in the
same places as in ASCII. A trail byte can be in the ASCII range, though. In
Shift_JIS it can be 5C, the backslash, which is why Japanese file paths
in Shift_JIS trip up programs that look for \ byte by byte.
The double-byte code pages hold 7,000 to 23,000 characters each, so this site does not print their tables; it links to them instead. The explorer reads these code pages through the browser’s own decoders, which follow the WHATWG Encoding Standard, and the standard publishes each table as an index file: one line per pointer, giving the pointer and the Unicode code point. The pointer for a lead byte L and trail byte T is worked out as the standard says:
| Code page | Table | Pointer |
|---|---|---|
| GBK, GB18030 (two-byte forms) | index-gb18030 | (L − 81) × 190 + (T − 40) for T below 7F, (T − 41) above |
| Big5 | index-big5 | (L − 81) × 157 + (T − 40) for T below 7F, (T − 62) above |
| Shift_JIS | index-jis0208 | (L − 81, or − C1 for L from A0) × 188 + (T − 40) for T below 7F, (T − 41) above |
| EUC-JP | index-jis0208, or index-jis0212 after 8F | (L − A1) × 94 + (T − A1) |
| EUC-KR (code page 949) | index-euc-kr | (L − 81) × 190 + (T − 41) |
Three things in the standard go beyond “one line, one character”:
- Big5 is Big5-HKSCS. The standard’s
big5decoder, which also answers to the labelbig5-hkscs, reads the Hong Kong Supplementary Character Set (leads87–A0andFA–FEhold its characters, among them many that are not in Big5 proper), and four pointers decode to two code points: 1133 to U+00CA U+0304, 1135 to U+00CA U+030C, 1164 to U+00EA U+0304 and 1166 to U+00EA U+030C. Node’sbig5decoder is not this one (it differs in 6,251 of the 19,782 two-byte codes), so the tests that name Big5 either use the index itself or do not depend on it. - Shift_JIS user-defined area. Pointers 8836 to 10715, which are
the lead bytes
F0toF9with any trail byte, are not in the index: the standard maps them to the private use code points U+E000 to U+E757 (U+E000 − 8836 + pointer), the end-user-defined characters that Windows calls EUDC. Every other pointer with no line in its index is not a character. - EUC-KR is code page 949. For the 8,836 cells of KS X 1001
(
A1–FEboth bytes), the index agrees with iconv’s EUC-KR except atA2 E6(€) andA2 E7(®), which the 1998 edition added and the index has too, andA2 E8(U+327E), which the index leaves out; Node’seuc-krdecoder has none of the three and puts the user-defined rowsC9andFEin the private use area, where the index has nothing.
The explorer shows a pointer with no character as an invalid sequence. The index
files are the full tables the explorer uses, cell for cell, in browsers; the checks
of the explorer’s own tables against iconv (test-txt-built.mjs --cns --whatwg
and --euckr) run on the index, not on Node’s decoders.
日本語 (“Japanese”) in Shift_JIS is 93 FA 96 7B 8C EA: three
characters of two bytes each, the second with the trail byte 7B, which
alone would be {. 中文 (“Chinese”) in GBK is
D6 D0 CE C4.
ASCII and the control codes
Bytes 20 to 7E are the printable ASCII characters, the same
in every code page here. 00 to 1F and 7F are
the C0 controls and DEL, and 80 to 9F are the C1 controls
of ISO 6429, which the ISO 8859 code pages keep and most others overwrite with
printable characters. ASCII dates from 1963 (ASA X3.4), revised in 1967 and 1986. The
explorer names each control code in its character list.
| _0 | _1 | _2 | _3 | _4 | _5 | _6 | _7 | _8 | _9 | _A | _B | _C | _D | _E | _F | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2_ | SP | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | / |
| 3_ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? |
| 4_ | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
| 5_ | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ |
| 6_ | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o |
| 7_ | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ | DEL |
| Byte | Abbr. | Name | Function |
|---|---|---|---|
00 | NUL | NULL | fills time or space; means nothing in text |
01 | SOH | START OF HEADING | starts the heading of a message |
02 | STX | START OF TEXT | ends the heading and starts the body |
03 | ETX | END OF TEXT | ends the body; Ctrl-C |
04 | EOT | END OF TRANSMISSION | ends a transmission; Ctrl-D |
05 | ENQ | ENQUIRY | asks the other end to respond |
06 | ACK | ACKNOWLEDGE | positive response to an enquiry |
07 | BEL | BELL | makes a sound or a flash |
08 | BS | BACKSPACE | moves back one position |
09 | HT | HORIZONTAL TABULATION | moves to the next tab stop: the tab character |
0A | LF | LINE FEED | moves down one line; ends a line on Unix |
0B | VT | LINE TABULATION | vertical tab: a mandatory line break in UAX #14 |
0C | FF | FORM FEED | starts a new page; a mandatory line break in UAX #14 |
0D | CR | CARRIAGE RETURN | moves to the start of the line; ends a line on the classic Mac OS |
0E | SO | SHIFT OUT | switches to an alternative character set |
0F | SI | SHIFT IN | switches back to the standard character set |
10 | DLE | DATA LINK ESCAPE | changes the meaning of the next few characters |
11 | DC1 | DEVICE CONTROL ONE | device control; XON, resume output |
12 | DC2 | DEVICE CONTROL TWO | device control |
13 | DC3 | DEVICE CONTROL THREE | device control; XOFF, pause output |
14 | DC4 | DEVICE CONTROL FOUR | device control |
15 | NAK | NEGATIVE ACKNOWLEDGE | negative response to an enquiry |
16 | SYN | SYNCHRONOUS IDLE | keeps a synchronous link in step |
17 | ETB | END OF TRANSMISSION BLOCK | ends a block of data |
18 | CAN | CANCEL | says the data before it should be ignored |
19 | EM | END OF MEDIUM | marks the end of a recording medium |
1A | SUB | SUBSTITUTE | stands for an invalid character; Ctrl-Z, end of a DOS text file |
1B | ESC | ESCAPE | starts an escape sequence |
1C | FS | INFORMATION SEPARATOR FOUR | file separator |
1D | GS | INFORMATION SEPARATOR THREE | group separator |
1E | RS | INFORMATION SEPARATOR TWO | record separator |
1F | US | INFORMATION SEPARATOR ONE | unit separator |
7F | DEL | DELETE | marks a position as erased |
80 | PAD | PADDING CHARACTER | a Unicode name alias, not part of ISO 6429 |
81 | HOP | HIGH OCTET PRESET | a Unicode name alias, not part of ISO 6429 |
82 | BPH | BREAK PERMITTED HERE | marks a place where a line may be broken |
83 | NBH | NO BREAK HERE | marks a place where a line must not be broken |
84 | IND | INDEX | moves down one line; withdrawn from ISO 6429 |
85 | NEL | NEXT LINE | moves to the start of the next line; the line end of EBCDIC systems |
86 | SSA | START OF SELECTED AREA | starts a selected area of a page |
87 | ESA | END OF SELECTED AREA | ends a selected area of a page |
88 | HTS | CHARACTER TABULATION SET | sets a horizontal tab stop here |
89 | HTJ | CHARACTER TABULATION WITH JUSTIFICATION | tab with the text before it justified |
8A | VTS | LINE TABULATION SET | sets a vertical tab stop here |
8B | PLD | PARTIAL LINE FORWARD | moves down part of a line, for subscripts |
8C | PLU | PARTIAL LINE BACKWARD | moves up part of a line, for superscripts |
8D | RI | REVERSE LINE FEED | moves up one line |
8E | SS2 | SINGLE-SHIFT TWO | the next character comes from code set G2 |
8F | SS3 | SINGLE-SHIFT THREE | the next character comes from code set G3 |
90 | DCS | DEVICE CONTROL STRING | starts a device control string |
91 | PU1 | PRIVATE USE ONE | reserved for private use |
92 | PU2 | PRIVATE USE TWO | reserved for private use |
93 | STS | SET TRANSMIT STATE | sets the transmit state |
94 | CCH | CANCEL CHARACTER | erases the character before it |
95 | MW | MESSAGE WAITING | says a message is waiting |
96 | SPA | START OF PROTECTED AREA | starts a protected area of a page |
97 | EPA | END OF PROTECTED AREA | ends a protected area of a page |
98 | SOS | START OF STRING | starts a control string |
99 | SGCI | SINGLE GRAPHIC CHARACTER INTRODUCER | a Unicode name alias, not part of ISO 6429 |
9A | SCI | SINGLE CHARACTER INTRODUCER | the next character is a control function |
9B | CSI | CONTROL SEQUENCE INTRODUCER | starts a control sequence |
9C | ST | STRING TERMINATOR | ends a control string |
9D | OSC | OPERATING SYSTEM COMMAND | starts an operating system command |
9E | PM | PRIVACY MESSAGE | starts a privacy message |
9F | APC | APPLICATION PROGRAM COMMAND | starts an application program command |
Lines
Limits of the viewer. The Text tab, and each “read in this code page” row, shows the first 16 MB of the file (16,777,216 bytes), and says when it has stopped. A row of the Lines table shows the first 1,000 characters of its line, then “…”. Neither limit hides anything from the tree, which holds every line and, inside each line, every character, however long, and the counts cover the whole file.
Names. The character list names every control code, the blank and format characters, and every other assigned code point from the Unicode Character Database’s UnicodeData.txt, version 18.0.0, copied unchanged into the site (Unicode, Inc.’s data under the Unicode Terms of Use); a code point the file does not have is not assigned and gets no name. The code page tables on the pages below give each byte’s character, not its name.
A line is the characters up to a line
ending. The explorer counts one line for each line ending, plus one for any text
after the last, so a␊b␊ and a␊b are both two lines. Lines
are numbered from 1, as editors number them.
POSIX defines a line as ending in a newline, so a last line with no line ending is, strictly, incomplete. It is common and harmless, and the explorer gives it as a note, not a problem.
In a single-byte code page a character is a byte, so the counts of characters are
counts of bytes, not counting the line endings; the explorer shows the number of bytes
above 7F rather than of non-ASCII characters. When it guesses a
double-byte code page it reads the file again in that code page, so that the counts
are of characters. The longest line is measured in characters. Tabs (09),
form feeds (0C, page breaks) and vertical tabs (0B) are
counted and not reported.
Line endings
In a code page only CR and LF end lines:
| Name | Bytes | Where it is used |
|---|---|---|
| LF (line feed) | 0A | Unix and Linux |
| CR LF | 0D 0A | Windows, MS-DOS, CP/M, Internet protocols |
| CR (carriage return) | 0D | classic Mac OS (up to 9), Apple II, Commodore |
The byte 85 is NEL (next line) in ISO 8859-1, but an ellipsis, …, in
Windows-1252, and a letter in most other code pages, so it is not taken as a line
ending. A file in Mac OS Roman usually ends its lines in CR alone, and the explorer’s
guess uses that (see The guess).
A file with more than one kind of ending is reported as having mixed line endings, with the first line that differs from the commonest kind.
End of the file
The text stops at the end of the file. Whether the last line has a line ending is covered under Lines. Two other things can follow the text:
- Ctrl-Z. CP/M stored file sizes in 128-byte records, so it marked
the end of the text with the byte
1A(SUB, Ctrl-Z), and MS-DOS programs kept writing it. It is common on old DOS text files, and the files examined for this site included some. The explorer shows trailing1Abytes as an End-of-file mark. A1Ainside the text is a control character. - Zero padding. NUL bytes after the text, left by programs that preallocate a file or write it in fixed-size blocks. The explorer shows them as Zero padding and reports them. A file that is mostly such zeros is not taken as text.
Problems
In a single-byte code page every byte is a character, so there are no invalid
sequences. Some bytes are unwelcome all the same: control codes, and the few bytes a
code page leaves unassigned, such as 81, 8D,
8F, 90 and 9D in Windows-1252. A reader shows
them as boxes, as nothing, or as U+FFFD. In a double-byte code page a lead byte with
no trail byte after it is an invalid sequence.
The worse problem is the wrong code page, which no reader can detect: every byte still reads as something. Text read in the wrong code page shows “mojibake”. é shown as È is Windows-1252 read as Mac OS Roman; é shown as é is UTF-8 read as Windows-1252.
| Problem | Meaning |
|---|---|
| NUL character | a 00 byte in the text |
| control character | a C0 control other than tab, LF, form feed and CR, or DEL (7F) |
| invalid byte sequence | in a double-byte code page, a lead byte with no valid trail byte, a byte that cannot start a character, or a well-formed pair with no character in the page’s table |
| character cut short by the end of the file | in a double-byte code page, a lead byte as the very last byte |
| mixed line endings | more than one kind of line ending |
| zero padding | NUL bytes after the text |
The explorer adds notes when:
- the guess is Windows-1252 and the file holds bytes that Windows-1252 leaves unassigned, so the guess may be wrong;
- most multi-byte sequences in the first 4 MB are valid UTF-8: the file is then probably UTF-8 with a few damaged or mixed-in bytes.
Telling it apart
There is no positive test for a code page. This format is what is left: the explorer tries it last, after UTF-7, ISO-2022 and HZ, UTF-8, UTF-32, UTF-16, GB18030 and EBCDIC, and its parser accepts any file that none of those took and that still looks like text. NUL and control characters together must be under one in fifty of the first 64 KB. (Tab, LF, vertical tab, form feed, CR, escape and Ctrl-Z do not count.) That is tighter than the Unicode formats’ test, because a code page accepts any byte, so binary data would otherwise pass. A file that is mostly zero bytes is turned down.
Most files come here because UTF-8 turned them down: an accented letter written as
one byte, such as E9 for é, is a UTF-8 lead byte with no continuation.
A file of pure ASCII never comes here; it is valid UTF-8. Which code page it is, is
then guessed.
Code pages
Bytes 00 to 7F are ASCII in all of these (see
ASCII and the control codes). The
complete tables of the upper halves are on their own pages:
| Page | Code pages |
|---|---|
| ISO 8859 | parts 1 to 11 and 13 to 16 (part 12 was never published) |
| Windows | Windows-874 and 1250 to 1258, and the Vietnamese pages VISCII and TCVN 5712 |
| DOS | 437, 737, 775, 850, 852, 855, 857, 858, 860, 861, 862, 863, 865, 866, 869 |
| Mac OS | Roman, Cyrillic, Central European, Greek, Turkish, Icelandic |
| KOI8 | KOI8-R and KOI8-U |
Each of the 48 single-byte code pages has a table in the plugin, so the explorer can show any file in any of them. A guessed page never rules out the others: the explorer lists the start of the file in every one, with a button that opens the whole text read that way.
Windows-1252 and ISO 8859-1
ISO 8859-1 (Latin-1, 1987) is the Western European part of the ISO 8859 standard.
Its 80 to 9F are C1 control codes, which text does not
use. Windows-1252, the code page of Windows in Western Europe and the Americas,
agrees with it everywhere else, and puts printable characters in
80 to 9F: € ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ‘ ’ “ ” • – — ˜ ™ š › œ ž
Ÿ, leaving five bytes unassigned (81, 8D, 8F,
90, 9D). The euro sign at 80 was added later,
for the euro. The WHATWG Encoding Standard makes “iso-8859-1”, “latin1” and “ascii”
names for Windows-1252, so browsers read Latin-1 files as Windows-1252. A file with no
bytes in 80 to 9F reads the same in both, and the explorer
then names both.
ISO 8859-15 (Latin-9) changes eight bytes of 8859-1; A4 becomes €. The
explorer does not tell 8859-15 from 8859-1.
Mac OS Roman
The code page of the classic Mac OS from the first Macintosh (1984), in English and
Western European systems. It puts its accented letters in an order of its own,
starting at 80, and has typographic and mathematical symbols such as •,
∞ and ∫. Files from the classic
Mac OS end their lines in CR.
DOS code page 437
The character set of the IBM PC (1981). It has accented letters at
80 to A5, box-drawing and shading characters at
B0 to DF, and Greek letters and mathematical signs at
E0 to FE. DOS readmes drew frames and tables with the box
characters (╔═══╗), and the DOS tree command draws with them too
(├───). The PC also showed pictures for the control codes 01 to
1F (☺ ♥ ♪ …), but only on screen; in a file those bytes are still
control codes.
Cyrillic code pages
Windows-1251 is the Cyrillic code page of Windows, with the alphabet in order at
C0 to FF. KOI8-R (RFC
1489, 1993) was the usual code page of Russian Unix systems and email. It puts
the letters at C0 to FF in an order chosen so that, with
the top bit lost, each letter becomes a Latin look-alike: привет becomes PRIWET. DOS
code page 866 is the Russian DOS code page. It keeps 437’s box-drawing characters at
B0 to DF and puts the letters at 80 to
AF and E0 to EF.
Code pages the explorer does not guess
The guess covers the Latin, Cyrillic, Greek, Hebrew, Arabic, Thai, Central European, Turkish and Baltic pages listed under The guess. The rest of the table (ISO 8859 parts 3, 4, 10, 14, 15 and 16, the DOS pages other than 437 and 866, the Mac pages other than Roman and Cyrillic, Windows-1258) can be too close to another page to pick out by statistics, or too rare to be worth a false match, so the explorer never chooses them itself, but they are all in the table of readings. A guessed code page can only ever be a guess.
Encodings that are not code pages have formats of their own: ISO-2022 and HZ, GB18030, EBCDIC and UTF-7.
The guess
No rule can tell these code pages apart. Every byte is valid in each of them, so the only evidence is which reading looks more like real text. Tools such as chardet, uchardet and ICU’s detector all work this way, from statistics, and all can be wrong. The explorer’s guess is the same kind of thing. Step by step:
- Count the bytes. Every byte value is counted over the whole file, and so is how often each byte follows itself.
- Density. The bytes above
7Fare compared with the ASCII letters. In Western European text they are a few accented letters among many ASCII ones. In Russian text nearly every letter is one, so when they make up more than 0.35 of the two together, the text is taken to be mostly non-Latin, and the guess is among the Cyrillic pages (Windows-1251, KOI8-R, KOI8-U, DOS 866, ISO 8859-5, Mac OS Cyrillic), Greek (Windows-1253, ISO 8859-7), Hebrew (Windows-1255, ISO 8859-8), Arabic (Windows-1256, ISO 8859-6) and Thai (Windows-874, ISO 8859-11), each scored by its own letter frequencies, with DOS 437 kept in for box drawing. Otherwise it is between Windows-1252, Mac OS Roman and DOS 437; and a Central European (Windows-1250, ISO 8859-2), Turkish (Windows-1254, ISO 8859-9) or Baltic page (Windows-1257, ISO 8859-13) takes over when its letters score at least a quarter better than the Western winner. - Score each candidate. Each byte above
7Fis read in the candidate code page and weighted by how common that character is in ordinary text: Western European letters (é, à, ü, ñ, ø …) and English typography (’ “ ” – … •), or Russian letter frequencies for the Cyrillic code pages. A C1 control code or an unassigned byte counts −3, a symbol −0.5. A letter that follows itself is not counted, since letters seldom double. - Box drawing. Box-drawing characters count only when they repeat (═════), as in frames and shading; a lone one counts slightly against.
- Line endings. Lines that end in CR, with no CR LF and hardly any LF, point to the classic Mac OS, and Mac OS Roman’s score is raised.
- The winner. The highest score wins. If it is Windows-1252 and the
file has no bytes from
80to9F, the result is named “Windows-1252 or ISO 8859-1”, since the two agree on every other byte. With fewer than 20 bytes above7Fthe explorer says the guess is weak. - Box art. In a dense file, when bytes
B0toDF, box drawing in both DOS code pages, are most of the bytes above7Fand at least three in ten of them repeat the byte before, the file is DOS 437, or 866 if 866’s Cyrillic letters are common as well. A listing from the DOStreecommand is the typical case. - East Asian code pages. When the bytes above
7Fare more than 0.12 of the letters, the start (up to 64 KB, cut at a line feed) is decoded in GBK, Big5, Shift_JIS, EUC-JP and EUC-KR. A code page counts only if at most a few of its characters fail to decode (no more than one, or one in two hundred), at least half of what is not ASCII comes out as kana, Chinese characters or Hangul, and, in a file below the 0.35 line, at least one character in twenty beyond ASCII is among the commonest. Among those, the one whose text holds the most hiragana (for Japanese), the most of the commonest Chinese characters (的 一 是 不 了 …), or the most of the commonest Korean syllables (이 다 는 의 에 …) wins. The file is then read again in it. - File name. A file called
.nfoor.dizis taken to be DOS text, and its bytes above7Fare read as code page 437 without a guess: their art is block drawing.
The explorer shows the result as the encoding, marked “a guess”, with its reasons,
and a table of the commonest bytes above 7F with what each would be in
every candidate. When the guess looks wrong, that table usually shows the right code
page. Whatever the guess, the Overview tab also lists the start of the file in all 54
code pages the explorer knows, single-byte and double-byte, each with a button that
opens the whole file read that way.
In spot checks on the files examined for this site the guess read correctly DOS
readmes with box drawing and tree listings (437), Mac OS 7 era release
notes (Mac OS Roman, with • and ∫ as bullets), Russian and Bulgarian documentation
(1251), Russian Unix documentation (KOI8-R), Chinese readmes (GBK) and Japanese
readmes (Shift_JIS). Short files with only one or two accented letters remain the
hardest case.
Not described
The gaps are those on the text overview. For legacy text: Shift_JIS-2004 and EUC-JIS-2004 are read as Shift_JIS or EUC-JP, with the wrong characters for the JIS X 0213 cells, and the CNS 11643 plane 3, 4 and 7 cells where ICU and libiconv differ follow ICU. No program can be sure which code page a file uses; the explorer guesses.
Variants
- UTF-8 text – one to four bytes a character, ASCII unchanged
- UTF-16LE text – two or four bytes a character, low byte first
- UTF-16BE text – two or four bytes a character, high byte first
- UTF-32LE text – four bytes a character, low byte first
- UTF-32BE text – four bytes a character, high byte first
- Legacy code page text – a pre-Unicode code page that the file does not name
- UTF-7 text – Unicode as pure ASCII, with Base64 runs
- ISO-2022 and HZ text – 7-bit Japanese, Korean and Chinese with escape sequences
- GB18030 text – China’s national encoding, one, two or four bytes a character
- EBCDIC text – IBM mainframe text, not based on ASCII
- SCSU text – Unicode compressed with windows and tags
- BOCU-1 text – Unicode as differences between code points
- UTF-1 text – the withdrawn ISO 10646 transformation
- UTF-EBCDIC text – UTF-8 for EBCDIC systems
Links
Software
- Notepad – the text editor built into Windows, which opens and saves the computer’s own code page as “ANSI” (Windows)
- Notepad++ – free text and code editor that reads a file in any of many character sets and converts it to UTF-8 (Windows)
- Visual Studio Code – free code editor that can reopen a file in a chosen encoding (Windows, macOS, Linux)
- BBEdit – long-standing Mac text editor that opens Mac OS Roman and other old encodings (macOS)
- Vim – keyboard-driven text editor (Windows, macOS, Linux)
- GNU Emacs – extensible text editor (Windows, macOS, Linux)
- iconv – command that converts a file from a code page to UTF-8 (macOS, Linux)
- file – the Unix
filecommand, which names a text file’s encoding and line endings (macOS, Linux)
Developers
- ICU – conversion between encodings and charset detection (C, C++, Java)
- GNU libiconv – the iconv conversion library, with many code pages (C)
- chardet – guesses a file’s encoding (Python)
- uchardet – encoding detector from Mozilla’s code (C)
- encoding_rs – the WHATWG encodings, as used by Firefox (Rust)
- ftfy – repairs mojibake (Python)
Reference
- WHATWG Encoding Standard – the code pages browsers support, with their tables
- Unicode’s code page mapping files – CP437, CP1252, Mac OS Roman and others, byte by byte
- RFC 1489 – KOI8-R