What is a .txt file? Opening, creating and fixing plain text files
The .txt file is the simplest document format in computing, and one of the most durable. Here is what is inside one, how to work with it on any device, and how to fix the common problems.
A .txt file is a plain text file: a sequence of characters with no formatting at all. No fonts, no bold, no images, no page layout — just letters, numbers, punctuation, spaces and line breaks. That simplicity is exactly why .txt files have survived for decades and why every computer, phone and programming language can read them.
What is actually inside a .txt file
Computers store everything as numbers. A text file stores one number (or a short sequence of numbers) per character, according to a rule called a character encoding. When you open the file, the editor reads the numbers and turns them back into characters using the same rule.
That is the entire format. There is no header, no metadata about fonts and no hidden structure. If you open a .txt file in any text editor, you see exactly what is stored. This is very different from a Word document, which is a compressed package of XML files, styles and media.
Character encodings: ASCII, UTF-8 and friends
The encoding is the one detail of text files that regularly causes trouble, so it is worth understanding.
- ASCII, standardized in the 1960s, defines 128 characters: English letters, digits, punctuation and some control codes. It has no accented letters, so it cannot represent "café" or "São Paulo".
- Legacy encodings such as Windows-1252 and ISO-8859-1 extended ASCII to 256 characters for Western European languages. Other regions had their own incompatible versions.
- Unicode is a universal catalog of characters covering virtually every writing system, plus symbols and emoji.
- UTF-8 is the most common way to store Unicode in a file. It is compatible with ASCII for English text and uses two to four bytes for other characters. It is the default for the web and for most modern software.
Rule of thumb: save text files as UTF-8. It handles every language, and almost every program reads it correctly.
Fixing garbled characters
If a text file shows strange sequences like "é" instead of "é", or question marks and boxes in place of letters, the file was saved in one encoding and opened in another. The text is usually not damaged; it is just being interpreted with the wrong rule.
- "é", "ã" and similar pairs usually mean a UTF-8 file is being read as Windows-1252. Reopen it explicitly as UTF-8.
- Single odd symbols where accents should be often mean the opposite: an older Windows-1252 file is being read as UTF-8.
- Most advanced editors have an "Encoding" or "Reopen with encoding" option. Choose the right one, then save the file again as UTF-8 so the problem does not return.
Line endings: the other invisible difference
Operating systems historically marked the end of a line differently. Windows uses two characters (carriage return + line feed, often written CRLF), while Linux and modern macOS use one (line feed, LF). Very old Mac systems used carriage return alone.
Today most editors handle both automatically, but you may still see a file with all its text on one long line in an old program, or with extra blank lines in another. Changing the line-ending setting in your editor and saving fixes it. Programmers care about this more than anyone, because some tools and scripts break with the "wrong" line endings.
How to open a .txt file
- Windows: double-click the file to open it in Notepad. Notepad on current Windows versions saves as UTF-8 by default.
- macOS: double-click to open it in TextEdit. To edit as pure plain text, use Format → Make Plain Text.
- Linux: any text editor works — gedit, Kate, nano or vim, depending on your desktop.
- iPhone and iPad: open the file from the Files app; it previews directly, and many apps can edit it.
- Android: open it from your file manager; most phones include a basic text viewer.
- In a browser: drag the file into a browser window to view it, or import it into an online notepad to edit it.
How to create a .txt file
- Open any plain text editor (Notepad, TextEdit in plain-text mode, or an online notepad).
- Type or paste your text.
- Save or download the file with a .txt extension, choosing UTF-8 if asked.
Be careful with word processors. Saving from Word or Google Docs creates a .docx file by default; you must choose "Plain Text (.txt)" explicitly, and all formatting will be removed.
What .txt files are good for
- Long-term archives. Text written today will be readable for decades, regardless of which apps survive.
- Notes and lists you want to open quickly on any device.
- Configuration and data files used by software, such as robots.txt on websites.
- Logs produced by applications and servers.
- Sharing text that must arrive exactly as written, without formatting surprises.
- Backups of notes from apps that might change or disappear.
Related plain text formats
Many file types are plain text with a different extension and a convention for what goes inside:
| Extension | What it is |
|---|---|
| .md | Markdown — text with simple formatting marks such as # for headings |
| .csv | Comma-separated values — tables, one row per line |
| .json | Structured data used by web apps and APIs |
| .html | Web pages |
| .log | Application logs |
| .ini, .conf, .yaml | Configuration files |
All of these open in any text editor. If you are ever unsure what a strange file contains, opening it in a plain text editor is a safe way to look — though you should not run or open unknown files in other programs.
Is .txt safe?
A .txt file cannot contain macros or executable code in itself, which makes it one of the safest formats to receive. Be cautious of names that hide a second extension, such as "document.txt.exe": on Windows, turning on "File name extensions" in File Explorer shows the real type.
Summary
A .txt file is just characters, stored with an encoding — ideally UTF-8. It opens everywhere, lasts forever and never surprises you with formatting. Garbled characters mean the wrong encoding, odd line breaks mean different line endings, and both are easy to fix. For notes you want to keep, there is still no better archive format.