File Formats
What Is a TXT File? Plain Text, Encodings and UTF-8
TXT is the simplest document format there is: just characters and line breaks. Yet encodings, the BOM and line endings make it one of the most troublesome. We explain each of them.
Author: Hemen Dönüştür Editör EkibiPublished: 8 min read

TXT is the plainest document format a computer has: no bold, no fonts, no page layout, just characters and line breaks. That simplicity makes it extremely portable. You can open a text file written fifty years ago today, and what you write today will very likely still open decades from now. But "plain text" is not as simple as it looks. Accented letters turning into "é" or "?", lines collapsing into one, an invisible character at the start of a file: all of these come from one hidden detail inside a TXT file, its character encoding. This article explains how TXT files work and how to fix these problems.
What is a TXT file?
A file with the .txt extension contains nothing but text characters. There is no header, no metadata and no formatting; every byte belongs to the text itself. The crucial question is: which byte stands for which character? That mapping is called the character encoding, and a TXT file usually does not say which one it uses. The program that opens it has to guess.
A short history: from ASCII to UTF-8
ASCII was first published in 1963 as ASA X3.4-1963. It uses 7 bits and defines 128 characters: the English alphabet, digits, punctuation and control characters such as the line feed. Letters such as é, ñ, ö or the Turkish ı and ş are not part of ASCII.
To fill the gap, code pages appeared, assigning the remaining 128 values of an 8-bit byte to different languages: Windows-1252 and ISO-8859-1 for Western European languages, Windows-1254 and ISO-8859-9 for Turkish, and many more. The problem is that the same byte means different letters in different code pages. The byte FD, for example, is "ý" in Windows-1252 but "ı" in Windows-1254. A program that guesses the wrong code page displays the text incorrectly.
The lasting fix was Unicode, which gives every character in every writing system a single number. UTF-8 is the most widely used way to turn those numbers into bytes. As Rob Pike tells it, Ken Thompson designed UTF-8 on a placemat in a New Jersey diner one night around September 1992. Its current definition is RFC 3629 from November 2003: UTF-8 encodes every character from U+0000 to U+10FFFF in 1 to 4 bytes, and writes ASCII characters as the same single bytes as ASCII.
The web shows how dominant UTF-8 has become: according to W3Techs data from October 15, 2026, 99.1% of websites whose character encoding is known use UTF-8, followed by ISO-8859-1 at 0.8% and Windows-1252 at 0.2%.
What is inside a TXT file?
Characters and bytes
Save the word "café" as UTF-8 and as Windows-1252 and you get different bytes:
Text: c a f é
UTF-8: 63 61 66 C3 A9 (5 bytes)
Windows-1252: 63 61 66 E9 (4 bytes)
A program that reads the UTF-8 file as Windows-1252 shows C3 and A9 as two separate characters, "é". Going the other way, a program that reads the Windows-1252 file as UTF-8 treats E9 as invalid and shows "�" instead. Nearly every garbled-character problem is one of these two scenarios.
The BOM (byte order mark)
Some programs put the bytes EF BB BF at the start of a UTF-8 file. This is the UTF-8 form of the character U+FEFF, used as a signature meaning "this file is UTF-8". RFC 3629 notes that this signature always appears as those three bytes. According to the Unicode FAQ, a BOM is not required in UTF-8 and only serves as a signature, and it should be avoided in protocols that expect ASCII characters at the start of a file. In practice, a BOM helps some older Windows programs and Excel recognize UTF-8, but it can break Unix shell scripts and configuration files read by certain software.
In UTF-16 the BOM matters even more, because it tells the reader the byte order: FF FE means little-endian and FE FF means big-endian UTF-16.
Line endings
The character that marks the end of a line also depends on the operating system:
| System | Line ending | Bytes |
|---|---|---|
| Windows | CRLF | 0D 0A |
| Linux, macOS | LF | 0A |
| Classic Mac OS (before OS X) | CR | 0D |
For many years Windows Notepad only understood CRLF, so a file written on Linux showed up as one long line. Microsoft announced LF and CR support for Notepad on May 8, 2018, and the change reached users with Windows 10 version 1809.
Where is TXT used?
- Notes and drafts: quick notes that need no formatting.
- Software: README files, license texts, source code, configuration files and logs.
- Data exchange: plain lists and exports passed between systems.
- Long-term storage: text that must be archived without depending on any application.
- Accessibility and processing: the cleanest input for screen readers, search engines and text analysis tools.
Strengths and weaknesses
Strengths: every device and operating system opens it. Files are tiny. There is no dependency on program versions and very little risk of corruption. Version control systems such as Git can show changes line by line. It cannot carry macros or embedded objects, which makes it safe.
Weaknesses: it cannot hold formatting, images, tables or links. Because the encoding is not recorded in the file, it can be guessed wrong. Line ending differences cause small but annoying issues across systems. If you need structure such as headings and lists, Markdown is a better choice.
Which programs open TXT?
Notepad on Windows, TextEdit on macOS, and gedit and similar editors on Linux all open TXT, and browsers can display text files directly. Advanced editors such as Visual Studio Code, Notepad++ and Sublime Text show the encoding and line ending type in the status bar and let you change both with a click, which makes them the most practical tools for diagnosing encoding problems.
Common problems and how to fix them
Accented characters look like "é" or "ü"
The file was saved as UTF-8, but the program reading it assumes Windows-1252. Reopen it as UTF-8 in an editor that lets you choose the encoding. If a CSV or text file looks like this in Excel, saving it as UTF-8 with BOM usually fixes it.
Characters are replaced with "?" or "�"
The file was saved in a legacy code page but is being read as UTF-8. Open it in your editor with the correct code page selected, then save it as UTF-8. If the text was saved with literal "?" characters, the originals are gone and you need to go back to the source.
All the text appears on one line
An old editor does not understand LF line endings. Use an up-to-date Notepad or an advanced editor, or convert the line endings to CRLF.
There is an invisible character at the start of the file
That is usually the BOM. If a script or configuration file fails on its first line, save it as "UTF-8 without BOM".
Tips for converting TXT files
On our converter, TXT files are uploaded to our server and deleted within 30 minutes. The encoding is detected automatically: first the BOM is checked (UTF-8, UTF-16 little- and big-endian); without a BOM, the file is checked for valid UTF-8; if it is not valid UTF-8, it is read as Windows-1254, the legacy Turkish Windows code page. Files containing many NUL bytes are treated as binary rather than text, and you get a "this is not a text file" message.
- With TXT to Word and TXT to PDF, every line becomes a paragraph and blank lines are kept. Leading indentation (code, poetry or numbered clauses) is turned into non-breaking spaces so it is not lost, and leading tabs become four spaces.
- TXT to Markdown is a good starting point when you want to enrich plain text with headings and lists later.
- In the other direction, PDF to TXT and Word to TXT drop formatting and separate headings and paragraphs with blank lines. The TXT files we produce are saved as UTF-8 with BOM so that accented characters display correctly in programs such as Notepad and Excel.
Frequently Asked Questions
Which encoding should I save a TXT file in?
UTF-8 for new files. It supports every language and has become nearly universal on the web. Skip the BOM if the file will be read by software that expects UTF-8 without one; add it if the file will be opened in programs such as Excel.
What is the difference between UTF-8 and UTF-8 with BOM?
The content is identical; the BOM version simply starts with the bytes EF BB BF. That signature helps some programs detect the encoding but can show up as an invisible first character in others.
What is the difference between TXT and RTF?
TXT contains only characters. RTF carries formatting such as bold, italic, fonts and tables through control commands embedded in the text. If you do not need formatting, TXT is simpler and more portable.
How do I find out a TXT file's encoding?
Editors such as Visual Studio Code and Notepad++ show the encoding in the status bar. Current versions of Notepad also show the encoding and line ending type in the status bar.
Can a TXT file contain a virus?
A plain text file does not contain executable code by itself. Watch out for double extensions such as "document.txt.exe"; making file extensions visible in Windows helps you spot that trick.
Sources
- IETF RFC 3629: UTF-8, a transformation format of ISO 10646 (November 2003)
- Unicode Consortium: UTF-8, UTF-16, UTF-32 and BOM FAQ
- Rob Pike: UTF-8 history
- W3Techs: Usage statistics of character encodings for websites
- Microsoft: Introducing extended line endings support in Notepad (May 8, 2018)
- Wikipedia: ASCII (secondary source)


