Friday, September 18, 2026

What Is UTF-8?

// character encoding

What Is UTF-8?

UTF-8 is a character encoding used to represent text inside computers. It provides a way of turning Unicode characters such as letters, numbers, mathematical symbols and characters from many languages into bytes that a computer can store and process.

// definition

UTF-8 turns characters into bytes

UTF-8 stands for Unicode Transformation Format - 8-bit.

It is an encoding system that converts Unicode characters into sequences of bytes.

This allows text to be stored in files, transmitted across networks and interpreted consistently by different computer systems.

// why encoding?

Computers do not store letters directly

When we look at a computer screen, we see characters:

A £ π é 日 😀

But computer storage ultimately consists of binary data. The computer therefore needs a defined system for representing each character using numbers and bytes.

Character Unicode code point UTF-8 encoding Bytes
// unicode

First, understand Unicode

Unicode is a standard that assigns characters unique numerical identifiers called code points.

A Unicode code point is normally written using U+ followed by hexadecimal digits.

Character Unicode code point
A U+0041
£ U+00A3
é U+00E9
π U+03C0
U+20AC
😀 U+1F600
// unicode vs utf-8

Unicode and UTF-8 are not the same thing

This distinction is important.

Unicode

Defines characters and assigns them code points.

UTF-8

Defines how those Unicode code points are encoded into bytes.

Unicode tells us that the pound sign is U+00A3. UTF-8 tells the computer which bytes should be used to represent that character.

// bytes

UTF-8 uses between one and four bytes

UTF-8 is a variable-length encoding.

Different characters require different numbers of bytes.

Character UTF-8 bytes Bytes used
A 41 1
£ C2 A3 2
π CF 80 2
E2 82 AC 3
😀 F0 9F 98 80 4

Important: the hexadecimal byte values shown above are the UTF-8 encoding of each character, not the Unicode code point itself.

// ascii compatibility

UTF-8 is compatible with ASCII

One of the reasons UTF-8 became so successful is its compatibility with ASCII.

The first 128 Unicode characters use exactly the same single-byte values as ASCII.

A = U+0041 = UTF-8 byte 41 B = U+0042 = UTF-8 byte 42 1 = U+0031 = UTF-8 byte 31

This means ordinary English text using basic letters, digits and punctuation is very compact in UTF-8.

// multilingual text

UTF-8 can represent text from many languages

UTF-8 is not limited to English.

English: Hello Português: Olá Español: Información Français: Éducation Greek: π Japanese: 日本 Currency: £ € ¥ Mathematics: ≤ ≥ ± √ ∞ Emoji: 😀

All of these characters can exist within the same UTF-8 encoded document.

// encoding errors

What happens when the wrong encoding is used?

Text can become corrupted-looking when software interprets bytes using the wrong character encoding.

For example, a pound sign encoded as UTF-8 may sometimes incorrectly appear as:

Expected: £50 Incorrect interpretation: £50

This type of garbled text is often called mojibake.

The data may not actually be damaged. The same bytes may simply have been interpreted using the wrong encoding.

// txt files

UTF-8 and .txt files

A .txt file tells us that a file contains plain text, but it does not automatically tell us which character encoding was used.

.txt automatically UTF-8

A text file might use UTF-8, ASCII, Windows-1252 or another encoding.

For modern text files, UTF-8 is generally the most useful and interoperable choice.

// csv files

UTF-8 and CSV

CSV is also a text-based format, so character encoding matters.

Name,City,Amount João,Lisboa,£50 Élodie,Paris,€75 Sofia,Athens,€40

Saving this file using UTF-8 helps preserve accented characters and currency symbols when the file moves between compatible systems.

// xml

UTF-8 and XML

XML documents can explicitly declare their character encoding.

<?xml version="1.0" encoding="UTF-8"?>

This tells the software reading the document that its characters are encoded using UTF-8.

// html

UTF-8 on websites

Websites also need to specify how text should be interpreted.

Modern HTML pages commonly include:

<meta charset="UTF-8">

This tells the browser to interpret the document using UTF-8.

Correct encoding is important for displaying names, symbols, mathematical notation, international text and other characters reliably.

// advantages

Why is UTF-8 so widely used?

Unicode support

It can represent the full range of Unicode code points.

ASCII compatible

Basic ASCII characters retain their original one-byte representation.

Efficient

Common English characters require only one byte, while additional bytes are used when necessary.

Portable

UTF-8 is supported across operating systems, programming languages, databases and web technology.

// where it appears

UTF-8 appears throughout modern computing

UTF-8 can be used with many text-based technologies and file formats.

TXT CSV XML JSON HTML CSS JavaScript APIs Databases Web Pages
// key idea

The file format and the encoding are different things

This is one of the most useful concepts to understand.

File format: describes how information is organised.

Character encoding: describes how the characters themselves are represented as bytes.

CSV = structure of the data UTF-8 = encoding of the characters

A CSV file can therefore be encoded using UTF-8. An XML document can be encoded using UTF-8. A plain .txt file can also be encoded using UTF-8.

// summary

Characters become bytes.

UTF-8 is a character encoding that converts Unicode characters into sequences of one to four bytes. It allows computers to store and exchange text from many languages, symbols and writing systems while remaining compatible with ASCII.

What Is XML?

// file formats

What Is XML?

XML is a text-based format for storing and exchanging structured information. It uses descriptive tags to show what each piece of data means and how different pieces of information relate to one another.

// definition

XML means Extensible Markup Language

XML stands for Extensible Markup Language.

It is a plain-text format designed to describe, organise, store and exchange structured information.

XML does this using tags that identify the meaning and structure of the data.

// example

What does XML look like?

Imagine that we want to store information about a customer.

<customer> <name>Alice Smith</name> <email>alice@example.com</email> <orders>4</orders> </customer>

The information is surrounded by tags such as <name>, <email> and <orders>.

These tags give meaning to the values rather than simply storing them in a fixed position.

// tags

Opening and closing tags

Most XML elements have an opening tag and a closing tag.

<name>Alice Smith</name>

Here:

<name>

This is the opening tag. It marks the beginning of the element.

</name>

This is the closing tag. The forward slash indicates the end of the element.

// structure

XML is hierarchical

One of XML's most important features is that elements can contain other elements.

This creates a tree-like hierarchy.

<shop> <customer> <name>Alice</name> <orders> <order> <id>1001</id> <total>49.99</total> </order> <order> <id>1002</id> <total>25.50</total> </order> </orders> </customer> </shop>

In this example, the shop contains a customer, the customer contains orders, and each order contains its own information.

// root element

An XML document needs a root element

A well-formed XML document has one outermost element that contains the rest of the document.

<customers> <customer> <name>Alice</name> </customer> <customer> <name>Ben</name> </customer> </customers>

Here, <customers> is the root element.

// attributes

XML elements can also have attributes

Attributes provide additional information about an element.

<customer id="1042" status="active"> <name>Alice Smith</name> </customer>

In this example:

id="1042" status="active"

These are attributes attached to the customer element.

// extensible

Why is XML called "extensible"?

XML does not give you a fixed set of tags.

Instead, you can create tags appropriate to the information you are describing.

<book> <title>Introduction to Data</title> <author>Jane Smith</author> </book>

A different system might use:

<product> <sku>ABC-100</sku> <price>29.99</price> </product>

The tags can therefore be designed around the type of information being stored.

// declaration

The XML declaration

XML documents may begin with a declaration such as:

<?xml version="1.0" encoding="UTF-8"?>

This tells software that the document uses XML version 1.0 and that the text is encoded using UTF-8.

Important: XML is a text format, so character encoding matters. UTF-8 is extremely common because it can represent characters from many languages and writing systems.

// escaping

Some characters need special handling

Because characters such as angle brackets are used as part of XML syntax, certain characters must be represented using special entity references when they are intended as data.

Character XML representation
< &lt;
> &gt;
& &amp;
" &quot;
' &apos;
// rules

XML has strict structural rules

XML must be well formed for an XML parser to process it correctly.

Tags must close

Elements normally need corresponding opening and closing tags.

Tags must nest correctly

Elements cannot overlap one another incorrectly.

One root element

The document must have one outermost root element.

XML is case-sensitive

<Name> and <name> are treated as different tags.

// nesting

Correct nesting matters

This is valid:

<customer> <name>Alice</name> </customer>

But this structure is invalid:

<customer> <name>Alice </customer> </name>

The elements have been closed in the wrong order.

// xml vs html

XML and HTML look similar, but they have different purposes

Both use angle-bracket tags, but they are designed for different jobs.

XML HTML
Describes and structures data Structures content for web pages
Custom tags can be created Uses predefined HTML elements
Focused on information Focused on webpage structure and presentation
Strict syntax Browsers are often more forgiving
<!-- XML --> <product> <name>Keyboard</name> <price>49.99</price> </product> <!-- HTML --> <h1>Keyboard</h1> <p>Price: £49.99</p>
// xml vs json

XML and JSON can represent similar information

XML and JSON are both commonly used to represent structured data.

For example, this XML:

<customer> <name>Alice</name> <orders>4</orders> </customer>

could be represented in JSON as:

{ "customer": { "name": "Alice", "orders": 4 } }

JSON is often more compact, while XML offers features such as attributes, namespaces and document-oriented structures that can be useful in more complex systems.

// uses

What is XML used for?

XML has been used extensively for exchanging and storing structured information across many kinds of software.

Configuration Files Data Exchange Web Services Document Formats Product Feeds Sitemaps RSS Feeds APIs Data Imports Data Exports
// real-world example

Website sitemaps commonly use XML

A website can provide an XML sitemap containing information about its pages.

<urlset> <url> <loc>https://example.com/</loc> </url> <url> <loc>https://example.com/about</loc> </url> </urlset>

Search engines and other software can process this structured information automatically.

// data management

Why XML matters in data management

XML allows information to describe its own structure.

Instead of relying purely on column positions or an external explanation, tags can identify what individual pieces of information represent.

<employee> <name>Tiago</name> <department>Technology</department> <active>true</active> </employee>

This makes XML useful when information needs to move between systems while retaining a clear hierarchical structure.

// plain text

XML is still plain text

Although XML can represent complex structures, the file itself is text.

This means an XML file can be opened in a text editor, inspected by a person and processed by software.

Readable Portable Structured Machine-Readable Text-Based
// summary

Text with structure and meaning.

XML is a text-based language for representing structured information. It uses tags, elements, attributes and hierarchical relationships to describe what data means and how different pieces of information fit together.

What Is a .csv File?

// file formats

What Is a .csv File?

A .csv file is a simple way of storing tabular data as plain text. It is commonly used to move information between spreadsheets, databases, websites and software applications.

// definition

CSV means Comma-Separated Values

CSV stands for Comma-Separated Values.

A .csv file stores data as plain text, usually with each line representing a row and commas separating the individual values within that row.

This makes CSV particularly useful for information that naturally fits into rows and columns.

// example

What does CSV data look like?

Imagine a spreadsheet containing customer information:

Name,Email,Orders Alice,alice@example.com,4 Ben,ben@example.com,7 Carla,carla@example.com,2

The first line contains the column headings. Each line after that represents one record.

Name Email Orders
Alice alice@example.com 4
Ben ben@example.com 7
Carla carla@example.com 2

The CSV file and the table contain essentially the same information. The difference is how that information is represented.

// structure

Rows, columns and values

Rows

Each line normally represents one record, such as one customer, one product or one transaction.

Columns

Each position within a row represents a particular field, such as a name, price or date.

Delimiter

Commas normally separate the fields from one another, giving the format its name.

Header row

Many CSV files begin with a row containing the names of the columns, although this is not compulsory.

// plain text

A CSV file is still a text file

CSV is a structured text format.

If you open a CSV file in a plain-text editor, you can normally read its contents directly.

However, spreadsheet software such as Microsoft Excel or Google Sheets can interpret the separators and display the information as rows and columns.

Plain Text Rows Columns Records Fields
// quoted values

What happens if the data itself contains a comma?

Sometimes a value needs to contain a comma of its own. In that situation, the value can be enclosed in double quotation marks.

Name,Location Alice,"Birmingham, England" Ben,"London, England"

The quotation marks tell software that the comma inside the location belongs to the value rather than separating two different columns.

// escaping

What about quotation marks inside a value?

If a quoted field itself contains a double quotation mark, CSV commonly represents it by doubling the quotation mark.

Product,Description Book,"The ""Advanced"" Edition"

This allows the quotation mark to remain part of the actual data.

// csv vs spreadsheet

A CSV file is not an Excel workbook

Excel can open CSV files, but that does not make CSV an Excel format.

A normal Excel workbook can store much more than simple tabular values. It can contain formatting, formulas, multiple worksheets, charts and other spreadsheet features.

Feature CSV Excel workbook
Rows and columns Yes Yes
Plain text Yes No
Multiple worksheets No Yes
Cell formatting No Yes
Charts No Yes

Important: when an Excel workbook is exported to CSV, features such as colours, fonts, charts and multiple worksheets are not preserved as part of the CSV format.

// why csv?

Why is CSV so widely used?

Simple

CSV has a straightforward structure that is relatively easy for both people and software to understand.

Portable

CSV files can move data between many different applications and operating systems.

Lightweight

There is very little additional information surrounding the actual data.

Programmable

Programming languages and data tools can easily read, create and transform CSV files.

// uses

What are CSV files used for?

CSV files are common anywhere structured data needs to move from one system to another.

Customer Data Product Lists Transactions Website Data Analytics Database Exports Affiliate Data Inventory Spreadsheets Data Migration
// encoding

CSV and UTF-8

Like other text files, a CSV file must use a character encoding.

UTF-8 is a particularly useful choice because it supports a huge range of characters and languages.

Name,City,Amount João,Lisboa,£25 Élodie,Paris,€40 Sofia,Athens,€32

Important: the .csv extension does not itself guarantee UTF-8. The character encoding is a separate property of the file.

// delimiters

Is a comma always used?

CSV literally means Comma-Separated Values, and commas are the standard delimiter associated with the format.

In practice, however, data files may also use other separators. For example, semicolons are sometimes used because of regional settings or software conventions.

Name;City;Orders Alice;Birmingham;4 Ben;London;7

Files using tabs as separators are commonly called TSV, meaning Tab-Separated Values.

// data management

Why CSV matters in data management

CSV is particularly useful because it provides a simple bridge between different systems.

A database can export records to CSV. A spreadsheet can open them. A script can transform them. Another application can then import the resulting file.

Database ↓ CSV ↓ Spreadsheet ↓ Script / Automation ↓ Another System

This makes CSV extremely useful for data migration, cleaning, imports, exports and automation.

// txt vs csv

How is CSV different from TXT?

Both .txt and .csv files can contain plain text.

The key difference is that CSV normally follows a tabular structure: values are separated into fields and records so that software can interpret them as rows and columns.

A general .txt file does not necessarily have that structure.

Format Main purpose
.txt General plain-text information
.csv Structured tabular data
// summary

Simple text. Structured data.

A .csv file stores tabular information as plain text, normally using commas to separate values and new lines to separate records. Its simplicity makes CSV one of the most useful formats for exchanging data between spreadsheets, databases, websites and software systems.

What Is a .txt File?

// file formats

What Is a .txt File?

A .txt file is one of the simplest ways of storing information on a computer. It contains plain text without the complex formatting found in documents, spreadsheets or web pages.

// definition

Plain text, stored in a file

A .txt file is a plain-text file. The letters .txt are the file extension, which tells a computer that the file primarily contains text.

Unlike a Microsoft Word document, a .txt file does not normally contain information about fonts, colours, page layouts, images or complex formatting.

It is essentially a sequence of characters stored in a file.

// example

What does a .txt file contain?

A text file might contain something as simple as:

> Customer: Jane Smith Order Number: 10452 Product: Laptop Stand Quantity: 2 Status: Dispatched

There is no special document structure required here. These are simply characters and line breaks stored inside a file.

// why use txt?

Simple files can be extremely useful

Lightweight

Text files usually require very little storage because they contain little more than the characters themselves.

Widely supported

Almost every operating system and programming language can read and write plain-text files.

Easy to inspect

A person can open a .txt file directly and see the information without needing specialist software.

Easy to process

Programs and scripts can search, transform and analyse text files very efficiently.

// data

A .txt file can contain many kinds of information

The .txt extension does not dictate exactly what the text must represent.

A text file could contain notes, lists, configuration information, source data, logs, mathematical expressions, website content or information intended to be processed by another program.

Notes Lists Logs Data Code Configuration URLs Mathematics
// encoding

What does UTF-8 have to do with .txt files?

Computers ultimately store information as numbers. A text encoding defines how those numbers correspond to characters such as letters, numbers and symbols.

UTF-8 is one of the most widely used character encodings. It can represent ordinary English text as well as characters from a huge range of languages and writing systems.

> English Português Mathematics: π ≈ 3.14159 Currency: £50 Symbols: ≤ ≥ ± √

Important: a file ending in .txt is not automatically guaranteed to use UTF-8. Text files can use different character encodings.

When exchanging modern text data, UTF-8 is usually an excellent choice because it supports such a wide range of characters.

// txt vs document

A text file is not the same as a formatted document

Suppose you write:

Hello, world!

A .txt file mainly stores those characters.

A word-processing document may also store information describing the font, font size, colour, margins, paragraph spacing, images and many other formatting properties.

This is why plain-text files are often much simpler to process programmatically.

// related formats

Many important file formats are text-based

Plain text is also the foundation of many structured formats used throughout computing and the web.

.txt .csv .json .xml .html .css .js

These formats add their own rules and structures, but the underlying content can still be represented as text.

This is one reason understanding plain text is so useful when working with data, websites, APIs and automation.

// practical use

When is a .txt file useful?

Saving simple information

Notes, instructions, lists or other information that does not require visual formatting.

Moving data

Text can be transferred between different applications and computer systems with relatively little complexity.

Programming

Scripts can create, read, search and modify text files easily.

Automation

Text files can act as simple inputs, outputs, logs or intermediate data in automated processes.

// summary

Simple format. Huge usefulness.

A .txt file is simply a file containing plain text. Its simplicity makes it one of the most universal, portable and useful ways of storing information on a computer.

What Is UTF-8?

// character encoding What Is UTF-8 ? UTF-8 is a character encoding used to repre...