7. The program product of claim 6 , where n is two.
6. A computer program product, encoded on a non-transitory computer-readable medium, operable to cause data processing apparatus to: receive a sequence of bytes representing text in a document; identify a plurality of byte-n-grams occurring in the sequence of bytes, each byte-n-gram comprising n adjacent bytes from the sequence of bytes, where n is an integer greater than 1; identify, for multiple encodings, a respective likelihood of each byte-n-gram occurring in each of the respective multiple encodings; receive multiple likelihoods associated with a top-level-domain of the document, each of the multiple likelihoods indicating a likelihood that documents from the top level domain are in a respective one of the multiple encodings; determine a respective encoding score for each of the multiple encodings, each respective encoding score being based on the likelihood of the plurality of byte-n-grams occurring in the corresponding one of the multiple encodings and based on the likelihoods associated with the top-level-domain the corresponding one of the multiple encodings; and identify a most likely encoding of the document based on a highest encoding score among the encoding scores.