File types · Explainer

The TXT file (.txt)

A TXT file is a plain-text file: characters and line breaks, with no formatting at all. This guide explains what's inside one, how encodings and line endings work, the quirks worth knowing, and has free sample TXT files to download for testing.

At a glance

Full name
Plain text file
Extensions
.txt
MIME type
text/plain, best sent with ; charset=utf-8
Kind
Plain text: characters only, no formatting
Encoding
Usually UTF-8 today; older files are often Windows-1252 or UTF-16
Standard
None for the file itself; text/plain is defined in RFC 2046, the characters by Unicode
Origins
As old as computing; ASCII, the base of most encodings, dates from 1963
Opens with
Any text editor (Notepad, TextEdit), any web browser
Line endings
LF (0A) on Linux and macOS, CRLF (0D 0A) traditionally on Windows
Magic number
None. A byte order mark may come first: EF BB BF (UTF-8), FF FE (UTF-16 LE)

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.

notes.txt (text, then 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. 153 68 6f 70 70 69 6e 67

    Plain 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. 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. 30a

    A 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 0a here.

  4. 420

    A 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. 5c3 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. 609

    A 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. 7e2 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. 8f0 9f 8d 93

    An 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. 90a (last byte)

    The final newline

    The file ends with a line feed. Unix tools expect one: without it, wc -l counts one line fewer and joining files can glue two lines together.

Characters

Text encodings: UTF-8, UTF-16, Windows-1252 and the BOM

EncodingBytes per characterNotes
ASCII1128 characters: English letters, digits, punctuation and control codes. Every encoding below agrees with it for those.
Windows-1252 ("ANSI")1256 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)1Like Windows-1252, except that bytes 80 to 9F are control codes rather than curly quotes, the euro sign and other symbols.
UTF-81 to 4Every Unicode character. ASCII text is unchanged. The standard choice today for files and the web.
UTF-162 or 4Every 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

NameBytesEscapeUsed by
LF (line feed)0A\nLinux, macOS, most code and the web
CRLF (carriage return + line feed)0D 0A\r\nWindows, and internet protocols such as HTTP and email headers
CR (carriage return)0D\rClassic 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 \r becomes part of the command. Convert them with dos2unix or your editor's line-ending setting.
  • Git can convert line endings on checkout and commit (core.autocrlf, or a .gitattributes file). 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

FormatPlain text inside?FormattingTypical use
.txtYesNoneNotes, logs, README files, data
.md MarkdownYesWritten as symbols (**bold**) that a renderer turns into formattingDocumentation, README files, notes
.csvYesNone; commas separate the columns of a tableSpreadsheet and database exports
.logYesNone; one event per line by conventionProgram and server logs
.rtf Rich Text FormatText, but full of control words like \bFonts, bold, colours, tablesFormatted text that most word processors open
.docx WordNo: a ZIP of XML filesEverything Word can doDocuments

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 typing notes.txt as 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 .txt files, 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.txt guesses 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: dos2unix and unix2dos, 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.exe shows as invoice.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.exe in a name like invoice[U+202E]txt.exe makes it display as invoiceexe.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.

sample-text.txt · 2.9 KBDownloadOpen
Loading…

What's inside sample-text.txt

The file explains itself: open it in a text editor and each numbered part tests one thing.

  1. Part 1: no formatting

    The "underline" under each heading is a row of hyphens, and *this* stays as typed: plain text has no styling.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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 BF and 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 FE and 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.txt and sample-windows-1252.txt to 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 ^M by some tools).
  • Byte vs character counts: sample-text.txt is 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

Last reviewed 27 October 2026.