The basics
What is a TXT file?
A TXT file holds text and nothing else: letters, digits, punctuation, spaces, tabs and line breaks. There is no bold, no font, no page size, no images. Any program on any computer can open it, which makes plain text the most portable and longest-lasting document format there is.
Notes, README files, licences, logs, lists, exported chat histories and data dumps are often .txt files. Many other formats are plain text with a different extension and rules on top: CSV, JSON, Markdown, HTML, source code and configuration files all open in a text editor.
Two things are not in the file, and cause nearly every problem with it:
- The encoding. The file is bytes; which bytes mean which characters depends on the encoding, and nothing in a plain text file records it (except, sometimes, a byte order mark).
- The line-ending convention. Windows, Linux and old Macs marked the end of a line with different bytes, and a file carries whichever one the program that wrote it used.
Anatomy
What's inside a TXT file
A text file is nothing but a list of character codes. There's no header and no formatting; even the line breaks are characters. Here is a four-line file as you'd see it in an editor, then the same 52 bytes in hex.
Shopping list
- Café crème
- Bread €2.40
- 🍓
00000000: 53 68 6f 70 70 69 6e 67 20 6c 69 73 74 0a 2d 20 Shopping list.-
00000010: 43 61 66 c3 a9 20 63 72 c3 a8 6d 65 0a 2d 20 42 Caf.. cr..me.- B
00000020: 72 65 61 64 09 e2 82 ac 32 2e 34 30 0a 2d 20 f0 read....2.40.- .
00000030: 9f 8d 93 0a ....- 1
53 68 6f 70 70 69 6e 67Plain letters
S h o p p i n g: each ASCII character is one byte, the same in ASCII, Windows-1252 and UTF-8. That shared base is why English text survives most encoding mix-ups. - 2
(no header)No header, no metadata
The file starts straight away with its text. Nothing records the encoding, the author or the language, so every program that opens it has to guess the encoding.
- 3
0aA line feed
The invisible end of each line. This file uses LF alone, as Linux and macOS do. A Windows-style file would have
0d 0ahere. - 4
20A space
Spaces are characters too. So are trailing spaces at the end of a line, which you can't see but which make two files that look identical differ.
- 5
c3 a9é in UTF-8
Characters outside ASCII take two to four bytes in UTF-8. Read these two bytes as Windows-1252 and you get
é, the classic sign of an encoding mix-up. - 6
09A tab
One byte, but its width is up to the editor: often 4 or 8 columns. Columns lined up with tabs in one editor can be ragged in another.
- 7
e2 82 ac€ in UTF-8
Three bytes. In the old Windows-1252 encoding the euro sign is the single byte
80, which is invalid on its own in UTF-8. - 8
f0 9f 8d 93An emoji
🍓 takes four bytes in UTF-8 (and four in UTF-16, as a surrogate pair). The file is 52 bytes but only 45 characters long, so byte counts and character counts differ.
- 9
0a (last byte)The final newline
The file ends with a line feed. Unix tools expect one: without it,
wc -lcounts one line fewer and joining files can glue two lines together.
Characters
Text encodings: UTF-8, UTF-16, Windows-1252 and the BOM
| Encoding | Bytes per character | Notes |
|---|---|---|
| ASCII | 1 | 128 characters: English letters, digits, punctuation and control codes. Every encoding below agrees with it for those. |
| Windows-1252 ("ANSI") | 1 | 256 characters for Western European languages. The usual default on older Western-language Windows. Can't store Greek, Cyrillic, Chinese or emoji. |
| ISO-8859-1 (Latin-1) | 1 | Like Windows-1252, except that bytes 80 to 9F are control codes rather than curly quotes, the euro sign and other symbols. |
| UTF-8 | 1 to 4 | Every Unicode character. ASCII text is unchanged. The standard choice today for files and the web. |
| UTF-16 | 2 or 4 | Every Unicode character, in 16-bit units. Comes in little-endian (LE) and big-endian (BE) byte orders. Windows uses it internally, and older Notepad versions called it "Unicode". |
A byte order mark (BOM) is the character U+FEFF written at the very start of a file. In UTF-16 it says which byte order follows (FF FE for little-endian, FE FF for big-endian). In UTF-8 it's the bytes EF BB BF and only works as a signature that says "this is UTF-8". The Unicode Consortium neither requires nor recommends it for UTF-8, and some tools trip over it: a script that starts with a BOM before #! won't run, and a CSV can get a garbled first column name.
When a program opens a text file it looks for a BOM, then for an encoding someone declared (a web server's charset, an editor setting), and otherwise guesses from the bytes. Guess wrong and you get mojibake: UTF-8 é read as Windows-1252 shows as é, and ’ as ’. Windows-1252 read as UTF-8 shows � replacement characters instead.
On the web
A server should send text files as Content-Type: text/plain; charset=utf-8. Without a charset, the MIME rules for text/plain say to assume US-ASCII, and browsers fall back to guessing, so accented letters can come out garbled.
Line breaks
Line endings: LF, CRLF and CR
| Name | Bytes | Escape | Used by |
|---|---|---|---|
| LF (line feed) | 0A | \n | Linux, macOS, most code and the web |
| CRLF (carriage return + line feed) | 0D 0A | \r\n | Windows, and internet protocols such as HTTP and email headers |
| CR (carriage return) | 0D | \r | Classic Mac OS, up to version 9 |
The names come from typewriters and teleprinters: return the carriage to the left, then feed the paper up a line. Most editors today read all three, and Windows Notepad has handled LF and CR files since the Windows 10 October 2018 Update. Before that, a Linux file opened in Notepad appeared as one long line.
- Shell scripts with CRLF fail on Linux and macOS with errors like
/bin/bash^M: bad interpreter, because the invisible\rbecomes part of the command. Convert them withdos2unixor your editor's line-ending setting. - Git can convert line endings on checkout and commit (
core.autocrlf, or a.gitattributesfile). That's why a file can show as changed on every line when nothing visible changed. - Diff tools and checksums see the difference. Two files that look identical but use different line endings have different sizes and hashes.
Related formats
TXT vs RTF, DOCX, Markdown and CSV
| Format | Plain text inside? | Formatting | Typical use |
|---|---|---|---|
.txt | Yes | None | Notes, logs, README files, data |
.md Markdown | Yes | Written as symbols (**bold**) that a renderer turns into formatting | Documentation, README files, notes |
.csv | Yes | None; commas separate the columns of a table | Spreadsheet and database exports |
.log | Yes | None; one event per line by convention | Program and server logs |
.rtf Rich Text Format | Text, but full of control words like \b | Fonts, bold, colours, tables | Formatted text that most word processors open |
.docx Word | No: a ZIP of XML files | Everything Word can do | Documents |
If you need headings, lists or links but want to stay in plain text, Markdown is the usual answer: it reads naturally as a .txt file and converts to HTML or DOCX when you need it to.
Troubleshooting
Why does my text file look wrong?
- Accented letters show as
é,’or�. The file was read with a different encoding from the one it was saved in. Reopen it with the right one (in VS Code, click the encoding in the status bar and choose "Reopen with Encoding"; in Notepad++, use the Encoding menu), then save it as UTF-8. - Spaces or dots between every letter, or the text looks Chinese. A UTF-16 file read as an 8-bit encoding, or the other way round. UTF-16 stores English letters as the letter plus a zero byte. A missing BOM is the usual cause.
- Everything is on one line. An old editor that doesn't understand LF line endings. Use a current editor, or convert the file to CRLF.
- An empty line between every line. The line endings were converted twice, giving
\r\r\n, which some programs show as two breaks. - The first character is
or the first column name is wrong. A UTF-8 BOM was read as Windows-1252 text. Save the file as UTF-8 without BOM. - The file is called
notes.txt.txt. Windows hides known extensions, so typingnotes.txtas a name added a second one. Turn on file name extensions in File Explorer's View menu.
How to
How to open, edit and convert a text file
- Windows: Notepad opens it on double-click. The status bar shows the encoding and line endings, and Save As lets you choose the encoding. Recent versions save new files as UTF-8 by default.
- Mac: TextEdit opens
.txtfiles, but new TextEdit documents are rich text until you choose Format, Make Plain Text (or set plain text as the default in TextEdit's settings). - Linux: any editor: Text Editor, Kate,
nano,vim.file notes.txtguesses the encoding and line endings. - Phones: iPhone and iPad open text files from the Files app; on Android, a files app or any text editor app.
- Browser: drag the file into a browser window to read it.
- Convert the encoding: in an editor's Save As dialog, or with
iconv -f WINDOWS-1252 -t UTF-8 old.txt > new.txt. - Convert line endings:
dos2unixandunix2dos, or the CRLF/LF switch in the status bar of VS Code and Notepad++. - Turn it into a PDF: open it in any editor or browser, choose Print, and pick "Save as PDF".
Security
Is it safe to open a TXT file?
A real text file can't run anything: opening it in a text editor only displays characters. The risks are in what the file pretends to be, and what it says:
- A disguised program. With extensions hidden,
invoice.txt.exeshows asinvoice.txt. Check the file type in its properties before you open an attachment. - Reversed file names. The invisible Unicode character U+202E (right-to-left override) placed before
txt.exein a name likeinvoice[U+202E]txt.exemakes it display asinvoiceexe.txt. - Instructions to paste something. A text file that asks you to copy a command into a terminal, PowerShell or the Run box is a common trick. Don't.
Served as text/plain, a text file is shown as text by current browsers and never run, even if it contains HTML or script code.
Free downloads
Sample TXT files to download
Free sample text files for testing editors, uploads, encodings, line endings and size limits. Each one decodes cleanly in the encoding it declares.
Loading…What's inside sample-text.txt
The file explains itself: open it in a text editor and each numbered part tests one thing.
Part 1: no formatting
The "underline" under each heading is a row of hyphens, and
*this*stays as typed: plain text has no styling.Part 2: line endings
Every line ends with a single LF byte. If the file shows as one long line, your editor doesn't support LF.
Parts 3 and 4: paragraphs and wrapping
Blank lines separate paragraphs. One paragraph is a single 432-character line, so you can see whether your editor soft-wraps it.
Part 5: tabs and spaces
The same table twice, aligned with tab characters and with spaces. Change your editor's tab width and only the first one moves.
Part 6: characters beyond ASCII
Accented letters, Greek, Cyrillic, Chinese, Japanese, Korean, Arabic, Hebrew and emoji, grouped by how many bytes each takes in UTF-8.
Part 7: an invisible character
A no-break space (U+00A0) that looks like a normal space but isn't, which trips up search and comparison.
Part 8: the final newline
The file ends with a line feed after its last line, as Unix tools expect.
All sample TXT files
Self-explaining sample text file
sample-text.txt · 2.9 KB (2,984 bytes)
UTF-8 without BOM, LF line endings. Numbered parts test formatting, line endings, wrapping, tabs, multilingual characters, an invisible no-break space and the final newline.
- Checking how an editor or viewer handles plain text
- Teaching what's inside a text file
UTF-8 with BOM and CRLF
sample-utf8-bom-crlf.txt · 684 bytes
Windows-style: starts with the UTF-8 byte order mark
EF BB BFand ends every line with CRLF.- Testing BOM handling in parsers and importers
- Line-ending conversion
UTF-16 LE with BOM
sample-utf16le.txt · 1.2 KB (1,244 bytes)
UTF-16 little-endian with the BOM
FF FEand CRLF line endings, with text in several scripts and two characters that need surrogate pairs.- Encoding detection
- Testing tools that assume one byte per character
Windows-1252 legacy encoding
sample-windows-1252.txt · 722 bytes
An old-style 8-bit file: accents, the euro sign (byte
80) and curly quotes in Windows-1252, with CRLF. Read as UTF-8 it shows replacement characters.- Testing encoding detection and conversion
- Reproducing mojibake bugs
100 KB text file
sample-100kb.txt · 100 KB (102,400 bytes)
Numbered ASCII lines with LF endings, exactly 102,400 bytes.
- Upload and size-limit tests
- Compression tests
1 MB text file
sample-1mb.txt · 1 MB (1,048,576 bytes)
The same structure at exactly 1,048,576 bytes (1 MiB), 15,200 lines.
- Upload limits and timeouts
- Editor and viewer performance
Ways to test with them
- Upload limits: the 100 KB and 1 MB files have exact sizes and are pure ASCII, so bytes equal characters.
- Encoding detection: feed
sample-utf8-bom-crlf.txt,sample-utf16le.txtandsample-windows-1252.txtto your importer. All three should come out as the same kind of readable text, with noÃ,or�. - Line endings: after your tool processes the CRLF files, no line should end in a stray
\r(shown as^Mby some tools). - Byte vs character counts:
sample-text.txtis 2,984 bytes but fewer characters, which catches code that confuses the two.
Free to use for testing, teaching and demos, commercially or not, with no attribution needed. A link back to this page is always appreciated.
Put it online
Have a TXT file? Give it a link.
Drop a text file on 99helpers and it gets its own web address. Anyone who opens the link reads it as plain text in their browser, with nothing to download or install.
Questions
TXT files, frequently asked
What is a TXT file?
A plain-text file: just characters and line breaks, with no formatting, fonts or images. Any text editor or browser can open it.
How do I open a TXT file?
Double-click it. Windows opens it in Notepad and a Mac in TextEdit. You can also drag it into a browser window, or open it in any code editor.
How do I create a text file?
On Windows, open Notepad, type, and save. On a Mac, open TextEdit, choose Format, Make Plain Text, then save. On Linux or macOS in a terminal, nano notes.txt creates and edits one.
Why does my text file show strange characters like é or ’?
The file was saved in one encoding (usually UTF-8) and opened as another (usually Windows-1252). Reopen it with the UTF-8 encoding selected, then save it as UTF-8.
Which encoding should I use?
UTF-8. It can store every language and emoji, plain English stays one byte per character, and it's what the web and most tools expect. Add a BOM only if a specific program needs one.
What's the difference between TXT and RTF or DOCX?
A TXT file holds only text. RTF adds formatting using control words inside the text, and DOCX is a ZIP package of XML files with full Word formatting. Only TXT opens identically everywhere.
Why is my text file all on one line?
It uses Linux-style LF line endings and the program that opened it only understands Windows CRLF. Use a newer editor, or convert the line endings.
Can a TXT file contain a virus?
A real text file can't run code. The danger is a program disguised with a name like notes.txt.exe, or text that talks you into pasting a command somewhere. Check the real file type before opening attachments.
Related formats
Other file types explained
Keep going
Related
Sources
- RFC 2046: MIME Media Types (text/plain)
- RFC 6657: charset parameter handling in textual media types
- Unicode FAQ: UTF-8, UTF-16, UTF-32 and BOM
- RFC 3629: UTF-8
- Microsoft: extended line endings support in Notepad
Last reviewed 27 October 2026.