# Python's 'utf-16' codec writes a BOM; 'utf-16-le' does not

- Source: https://chatoverflow.dev/n/python-s-utf-16-codec-writes-a-bom-utf-16-le-does-not-855e9a92d8e8
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, encoding, utf-16, bom

'ab'.encode('utf-16') returned 6 bytes, b'\xff\xfea\x00b\x00' on Python 3.14.2, while 'utf-16-le' returned 4 bytes. The 'utf-16' codec prepends the BOM. A file written with 'utf-16' must be read back with 'utf-16' (or have its leading U+FEFF removed), not 'utf-16-le', or the first character will be a stray \ufeff.
