Text files

What is a text file?

A text file is a file that only contains characters.

Specifically, the characters are represented by an agreed code (for example 65 for A, 66 for B…).

Importantly this means there is no formatting information encoded in the file itself: only characters.

#35
 32
A65
 32
P80
y121
t116
h104
o111
n110
 32
p112
r114
o111
g103
r114
a97
m109
#65
 32
i105
s115
 32
s115
t116
o111
r114
e101
d100
 32
a97
s115
 32
a97
#65
 32
t116
e101
x120
t116
 32
f102
i105
l108
e101
.46
p112
r114
i105
n110
t116
(28
"34
H72
E45
L76
L76
O79
!21
"34
)29
 

Click or hover on the characters to see their underlying codes.

If you open a text file, and see text in different formats, you’re not just seeing the text file’s contents. Instead, you are seeing how a program is choosing to display it. So if some words are red, and others are in big font — those formatting features are not encoded directly in the file but are being added by the program you are using to look at it.

This is a subtle distinction. For example, a Word document does contain extra information that isn’t represented in this way. So a Word document is not a text file, even if it only contains the word “hello”.

It’s also a very important distinction if you are going to be doing any programming or using any command-line tools.