Stewdent.eu
▾

Text Files

A text file stores data as plain characters using a character encoding like ASCII or UTF-8.

Last updated: 24 December 2025

★☆☆☆☆ Level 1computingDatafile-typestextfiles4 min read

Report an error

What is a Text File?

A text file is one of the simplest types of computer file. It contains nothing but characters — letters, numbers, punctuation, and spaces — stored using a character encoding like ASCII or UTF-8. There is no formatting information like bold, colour, or font size.

Common text file extensions include .txt, .csv, .html, .py, and .json.

Note

When programmers write code, they are creating text files. Python scripts, HTML pages, and CSS stylesheets are all plain text files that just happen to follow special rules about what the text means.

Plain Text vs Rich Text

It is important to understand the difference between plain text and formatted documents:

FeaturePlain Text (.txt)Rich Text / Word (.docx)
Bold, italic, colourNoYes
Images embeddedNoYes
File sizeVery smallLarger
Opens on any systemYesNeeds compatible software
Human-readableYesPartly (lots of hidden data)

A .txt file with the words "Hello World" contains exactly 11 bytes (one per character). The same text in a Word .docx file might be 10,000+ bytes due to all the formatting and metadata.

CSV Files

A popular text file format is CSV (Comma-Separated Values). It stores data in a table where each row is on a new line and each value is separated by a comma.

Name,Age,Score
Alice,14,87
Bob,13,92
Charlie,15,78

CSV files are used to share data between programs like spreadsheets and databases. They are easy to create, read, and import.

Tip

You can open a CSV file in a text editor to see the raw data, or in a spreadsheet app like Excel or Google Sheets to see it as a table. This flexibility makes CSV one of the most widely used data exchange formats.

How Text Files Are Stored

Each character in a text file is stored as its ASCII or UTF-8 binary code. A newline (pressing Enter) is stored as a special control character — or two on Windows (CR + LF).

Because text files have no extra formatting, they are:

  • Very small in size
  • Portable — they look the same on any operating system
  • Easy to process — programs can read them line by line

When to Use Text Files

Text files are the right choice when you need to store simple, structured data that humans and machines both need to read easily — configuration files, log files, source code, and exported data all fit this description perfectly.

Practice Problems

A CSV file stores a class register with 30 students, each with a name (average 8 characters) and a mark (2 characters), separated by a comma. Estimate the file size in bytes, assuming ASCII encoding and a newline after each row.

Show answer
Each row: 8 + 1 (comma) + 2 + 1 (newline) = 12 bytes. 30 rows × 12 bytes = 360 bytes. (Plus a header row of about 12 bytes = ~372 bytes total.)

Give two advantages of using a plain text file instead of a formatted document like a Word file for storing a list of student names.

Show answer
Any two from: smaller file size; can be opened on any device without special software; human-readable in any text editor; easier to process with programs; no risk of formatting corruption.