A character encoding specifies how a sequence of Unicode characters is converted to bytes (while decoding transforms such bytes back to respective Unicode characters again).
Determining the character encoding of a file or a byte stream
uchardet (by freedesktop.org) takes a sequence of bytes in an unknown character encoding and attempts to determine the encoding of the text. The returned encoding names are iconv-compatible.
In a Unix shell, the character encoding of a file might be determined with file or file -i.