# Text Encoding Converter

> Decodes well-formed UTF-8, UTF-16LE or UTF-16BE bytes into Unicode text, optionally normalises line endings, then writes the same characters in one of those three encodings with an explicit byte-order-mark choice.

Use it: https://tessalor.com/en/text/text-encoding-converter

This tool runs entirely in the browser. Nothing entered into it is uploaded.

## How it is done

1. 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.
2. 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.
3. 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.
4. 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.
5. 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.

## Assumptions

- 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.

## Inputs

| Name | Label | Type | Default | Range |
| --- | --- | --- | --- | --- |
| `source` | Text file | file | chosen on your device | text/plain, application/octet-stream, up to 25 MB |
| `sourceEncoding` | Read the source as | select | auto |  |
| `targetEncoding` | Write the result as | select | utf-8 |  |
| `writeBom` | Write a byte-order mark | toggle | false |  |
| `lineEndings` | Line endings | select | preserve |  |

## Outputs

- `characters` — Unicode code points (integer), primary
- `sourceEncoding` — Read as (text)
- `targetEncoding` — Written as (text)
- `inputBytes` — Input bytes (integer)
- `outputBytes` — Output bytes (integer)

## Questions

### Is the text file uploaded for encoding conversion?

No. The bytes are decoded and re-encoded inside a worker in this browser tab, and the new file is assembled locally. The generated browser test fails if using a real file sends a request away from Tessalor's origin.

### What happens when an invalid UTF-8 or UTF-16 sequence is found?

The conversion stops with an explanation. Substituting U+FFFD can be a useful recovery policy, but it changes data; a general converter should not make that choice without being asked.

### Does UTF-8 need a byte-order mark?

UTF-8 is byte-oriented, so it has no endian ambiguity. EF BB BF is only an encoding signature and is usually unnecessary in modern web and command-line workflows, though some older software expects it.

### Why can one emoji occupy four bytes in both UTF-8 and UTF-16?

A supplementary Unicode character uses a four-byte UTF-8 sequence and a pair of two-byte UTF-16 surrogate code units. It is still one code point, which is why the result count does not call it two characters.

### Does changing encoding also change Windows and Unix line endings?

Not by default. Character encoding maps characters to bytes; CRLF and LF are character sequences. The advanced control keeps those jobs separate and preserves the original sequence unless a conversion is selected.

## Sources

- [Encoding Standard](https://encoding.spec.whatwg.org/) — WHATWG, applies to Living Standard, August 2026. Retrieved 2026-08-01.
- [UTF-8, UTF-16, UTF-32 & BOM FAQ](https://www.unicode.org/faq/utf_bom.html) — The Unicode Consortium, applies to Unicode encoding forms and byte-order-mark guidance. Retrieved 2026-08-01.
- [RFC 3629: UTF-8, a transformation format of ISO 10646](https://www.rfc-editor.org/rfc/rfc3629.html) — RFC Editor / Internet Engineering Task Force, applies to Standards Track, November 2003. Retrieved 2026-08-01.

## Variants

- [How do I convert a text file to UTF-8?](https://tessalor.com/en/text/text-encoding-converter/convert-text-file-to-utf-8)
- [How do I remove a UTF-8 BOM from a text file?](https://tessalor.com/en/text/text-encoding-converter/remove-utf-8-bom-from-file)

---

Estimate, not advice. See https://tessalor.com/en/disclaimer.
Machine-readable catalogue: https://tessalor.com/api/tools.json
