TXT Files Explained: Encoding, Spaces, and Line Endings
Understand how plain text stores characters, from ASCII and GBK to UTF-8, then detect encoding and normalize line endings locally.
TXT (Text File) is the simplest and most universal plain-text format. It contains readable text and control characters, without fonts, colors, complex layout, or embedded images. That simplicity makes it small, fast, and highly compatible.
What exactly is a TXT file?
The .txt extension only says that a file is plain text; it does not prescribe a character encoding. Two TXT files may use UTF-8 and GBK respectively. Text displays correctly only when software decodes the bytes with the right rules.
So TXT format has two layers: plain text as the content model, and an encoding that maps characters to bytes. Garbled text often means an encoding mismatch rather than damaged content.
Common TXT encodings
Every TXT file depends on an encoding. These are the most common options, with different character coverage and byte structures.
ASCII
The basic 7-bit encoding with 128 letters, digits, punctuation marks, and control characters. Plain ASCII cannot represent Chinese, Japanese, or emoji.
GB2312 / GBK
GB2312 contains 6,763 Chinese characters; GBK is a compatible extension covering 21,886. Many older Chinese TXT novels use GBK, though it cannot represent all modern Unicode characters.
Unicode
Unicode assigns stable code points to characters across languages and platforms. It is a character standard; UTF-8 and UTF-16 are concrete ways to encode those points as bytes.
UTF-8
UTF-8 is the most popular Unicode encoding and the dominant encoding on the web. It is ASCII-compatible and uses one to four bytes per Unicode code point.
UTF-16
UTF-16 uses two or four bytes per character and is common inside Windows and some programming environments. A BOM often identifies big- or little-endian byte order.
Why can encoding only be inferred?
TXT usually carries no metadata naming its encoding. Detectors look for a BOM, validate UTF-8, UTF-16, or GBK byte structure, then score character distributions. Except for an explicit BOM, the result is an inference rather than proof.
For example, an ASCII-only file has identical bytes whether called ASCII or saved as UTF-8 without a BOM, so the file itself cannot distinguish the two.
TXT encoding detector
Drop a TXT file below to detect its encoding.
Files are processed only in your browser and are never uploaded. Detection is heuristic, so keep a backup of important files.
Why is UTF-8 preferred today?
ASCII covers too few characters, while GBK mainly targets Simplified Chinese. Neither covers all modern scripts, symbols, and emoji. UTF-8 stays ASCII-compatible while representing all Unicode characters.
There is more than one kind of space. Unicode includes regular, non-breaking, and full-width spaces for different typography. Invisible variants can enter TXT when copying web content, and the tool above can normalize common ones.
CRLF, LF, and CR: what changes?
ASCII, GBK, and UTF-8 use the same byte values for basic spaces, carriage returns, and line feeds, but operating systems traditionally combine them differently.
CRLF— Windows(0x0D + 0x0A)LF— Linux / macOS(0x0A)CR— Classic Mac(0x0D)
Modern editors generally support CRLF and LF, but scripts, version control, or older tools may still fail on an extra 0x0D. Normalizing line endings makes cross-platform processing more predictable.
TXT line-ending tool
Drop a TXT file below to check its line endings and convert them.
Normalize and download
The output has no BOM, and the original file is not modified.
