A byte order mark is an invisible instruction at the start of a text file that tells your computer which direction to read the file's characters

When you save a text file in UTF-8 or UTF-16 encoding, your computer can add a few invisible bytes at the very beginning. This marker—called a byte order mark or BOM—is like a label that says "read this file this way." Without it, some programs guess wrong about how to interpret the file, and you end up with garbled text or broken characters.

The BOM matters most when you move files between different programs, operating systems, or devices. A file created on Windows might open differently on Mac or Linux without one. If you work with data files, code, or documents that travel between systems, understanding what a BOM does helps you avoid the frustration of corrupted text that looks fine in one program but breaks in another.

Key Takeaways

  • A byte order mark is an invisible set of bytes at the start of a file that tells programs how to read the text inside.
  • UTF-8 files rarely need a BOM, but UTF-16 files almost always do, because UTF-16 comes in two different byte orders that look identical without the marker.
  • Some programs add a BOM automatically when you save; others let you choose whether to include one.
  • A BOM can cause problems in certain situations, like when you upload code to a web server or import data into a database, so knowing when to remove it matters.

Why computers need to know which direction to read bytes

Text files are made of bytes—tiny units of data. When your computer reads a file, it needs to know the order in which to read those bytes. For most single-character encodings like ASCII, this is not a problem: one character equals one byte, read left to right. But when you use UTF-16 encoding, one character can be made of two or four bytes, and those bytes can be arranged in two different orders.

UTF-16 comes in two flavors: UTF-16 Big-Endian (reads bytes in one order) and UTF-16 Little-Endian (reads them in the opposite order). To a computer, the raw bytes look identical. Without a marker, the program opening the file has to guess which order is correct. A byte order mark removes the guessing by writing a specific sequence of bytes at the start that says "this file is UTF-16 Big-Endian" or "this file is UTF-16 Little-Endian."

UTF-8 encoding does not have this problem because UTF-8 has only one byte order. However, some programs still add a UTF-8 BOM out of habit or for compatibility with older systems.

What a byte order mark looks like in different encodings

A byte order mark is always invisible to you when you open a file normally—you will not see it on screen. But if you open a file in a hex editor or a raw text viewer, you can see the actual bytes. The BOM is always the same bytes for a given encoding, so programs can recognize it instantly.

EncodingBOM bytes (in hexadecimal)What it means
UTF-8EF BB BFThis is a UTF-8 file (optional)
UTF-16 Big-EndianFE FFRead bytes in big-endian order
UTF-16 Little-EndianFF FERead bytes in little-endian order
UTF-32 Big-Endian00 00 FE FFRead bytes in big-endian order (rare)
UTF-32 Little-EndianFF FE 00 00Read bytes in little-endian order (rare)

When you save a file in a text editor like Notepad or VS Code, the program writes these bytes automatically if you choose that encoding. You never type them yourself.

When a byte order mark causes problems

A BOM is helpful most of the time, but in certain situations it breaks things. Web servers and databases often expect files to start with actual content, not a marker. If you upload a UTF-8 file with a BOM to a website, the server might display those invisible bytes as garbage characters at the top of the page. If you import a CSV file with a BOM into a database, the first column name might be unreadable because the BOM is stuck to the beginning of it.

Programming languages also have mixed feelings about BOMs. Python, JavaScript, and most other languages can handle a UTF-8 BOM, but some older systems or strict parsers will reject it. If you are writing code that will run on a web server or be processed by a strict tool, removing the BOM is usually the safer choice.

The most common problem occurs when you save a file in UTF-8 with a BOM on Windows (because Windows Notepad does this by default) and then try to use it on a Linux server or in a tool that expects plain UTF-8 without the marker. The file looks fine when you open it locally, but breaks when you move it.

How to check if a file has a byte order mark

Most text editors do not show you whether a BOM is present—it is invisible by design. But several tools can reveal it. In VS Code, open the file and look at the bottom right of the window; it shows the encoding. If it says "UTF-8 with BOM," there is a BOM. If it says just "UTF-8," there is not.

In Notepad++, open the file and go to Encoding menu; it shows the current encoding and whether a BOM is present. In a terminal on Mac or Linux, you can use the command file filename.txt to see the encoding, or hexdump -C filename.txt | head to see the raw bytes at the start of the file.

If you see the bytes EF BB BF at the very start of a UTF-8 file, that is the BOM. If you see FF FE or FE FF at the start, that is a UTF-16 BOM.

How to add or remove a byte order mark

In VS Code, open the file, click the encoding indicator at the bottom right (it shows "UTF-8" or similar), and select "Save with Encoding." Choose "UTF-8" to remove the BOM or "UTF-8 with BOM" to add one. The file will be saved with your choice the next time you press Ctrl+S (or Cmd+S on Mac).

In Notepad++, open the file, go to Encoding menu, and choose either "Encode in UTF-8 without BOM" or "Encode in UTF-8 with BOM." The change takes effect when you save.

On Mac or Linux, you can use the command line tool sed to remove a UTF-8 BOM: sed '1s/^\xEF\xBB\xBF//' inputfile.txt > outputfile.txt. This reads the input file, strips the BOM from the first line, and writes it to a new file without the BOM.

When you should keep or remove a byte order mark

Keep a BOM if you are working with UTF-16 files or if your files will be opened primarily in Windows programs like Excel or Word. These programs expect and handle BOMs correctly. If you are sharing a document with someone who uses older software, a BOM can actually help ensure the file opens correctly.

Remove a BOM if you are writing code, creating data files for import into databases, uploading files to a web server, or sharing files that will be processed by command-line tools or scripts. Most modern web standards and programming environments expect UTF-8 without a BOM. If you are unsure, UTF-8 without a BOM is the safest default for files that travel between systems.

For everyday documents like Word files or PDFs, the BOM does not matter because those formats handle encoding internally and do not rely on a BOM to work correctly.

Frequently Asked Questions

Will I see the byte order mark when I open a file?

No. The BOM is invisible when you open a file normally in any text editor or program. It only appears if you use a hex editor or a tool specifically designed to show raw bytes. Your computer reads it silently in the background to know how to interpret the rest of the file.

Do all UTF-8 files have a byte order mark?

No. UTF-8 does not require a BOM because UTF-8 has only one byte order. Many UTF-8 files have no BOM at all. Some programs add one for compatibility, but it is optional. UTF-16 files almost always have a BOM because UTF-16 comes in two different byte orders and needs the marker to tell them apart.

What happens if I remove a byte order mark by accident?

If the file is UTF-8 or UTF-16 Big-Endian, nothing bad happens—the file still opens and reads correctly. If the file is UTF-16 Little-Endian and you remove the BOM, some programs might misread the byte order and display garbled text. You can undo the change in most text editors by pressing Ctrl+Z (or Cmd+Z on Mac).

Why does Windows Notepad add a byte order mark to UTF-8 files?

Windows Notepad adds a UTF-8 BOM by default for historical reasons—older versions of Windows and some legacy software expected it. Modern versions of Windows and most other programs handle UTF-8 without a BOM just fine. If you want to save UTF-8 without a BOM in Notepad, use a different editor like VS Code or Notepad++.