Convert a Text File to UTF-8
Choose automatic source detection when the file has a Unicode byte-order mark, or name UTF-16LE or UTF-16BE when you know it has no marker. Write the result as UTF-8 and leave the BOM off for a modern plain-text file unless the receiving application specifically requires one.
A plain-text file up to 25 MB. Binary formats such as Word documents are not text encodings and are refused.
Results are provided as-is, with no warranty of accuracy. The method and its sources are published below so you can check the working.
Auto recognises UTF-8, UTF-16LE and UTF-16BE byte-order marks; an unmarked file defaults to UTF-8.
Invalid byte sequences are refused instead of silently replacing characters.
Line-ending conversion is optional and independent from character encoding.
How it works
How it is done
- Inspect the first three bytes for EF BB BF (UTF-8), FF FE (UTF-16LE) or FE FF (UTF-16BE). In automatic mode the marker chooses the decoder; without one, require UTF-8 rather than guessing a legacy code page.
- When the source encoding is selected manually, require any existing marker to agree. Remove the agreed marker, then decode in fatal mode so an illegal byte sequence stops the conversion instead of becoming a silent replacement character.
- Preserve every CR, LF and CRLF sequence by default. Only when selected, normalise all three forms to LF or to CRLF as a separate operation from character encoding.
- Count Unicode code points, treating a valid UTF-16 surrogate pair as one supplementary character. Encode the resulting string as UTF-8 bytes or as two-byte UTF-16 code units in the selected byte order.
- Add the selected target marker—EF BB BF, FF FE or FE FF—only when requested, then offer a separate .txt file. The source file is never changed.
What it assumes
- Auto is intentionally bounded to the three Unicode byte-order marks. An unmarked file defaults to strict UTF-8; Windows-1252, ISO-8859 variants and other legacy code pages cannot be distinguished reliably from bytes alone.
- A byte-order mark at the start is metadata and is consumed before the first text character. A U+FEFF later in the file is content and remains content.
- UTF-8 has no byte-order question; its BOM is only a signature. UTF-16LE and UTF-16BE serialize the same 16-bit code units in opposite byte order.
- Invalid UTF sequences are refused instead of repaired. The input cap is 25 MB, and the code-point and UTF-16 loops yield every 250,000 code units for progress and cancellation.
Common questions
Can the tool guess Windows-1252 or another legacy code page?
No. Many legacy encodings have no reliable signature, so guessing can silently change text. This converter handles the three explicit Unicode encodings and asks you to use a known legacy decoder first.
Should a UTF-8 file have a BOM?
Usually not for modern web and command-line workflows. Some older Windows software uses it as a hint, so the choice remains explicit rather than being added automatically.
Sources
The full method, worked example and every assumption behind this figure are on Text Encoding Converter.