Let be an error-correcting code consisting of codewords in which each codeword consists of letters taken from an alphabet of length , and every two distinct codewords differ in at least places. Then is said to be nearly perfect if, for every possible word of length with letters in , there is a codeword in in which at most letters of differ from the corresponding letters of . The codeword is unique if it differs from in fewer than places and there is at most one other codeword differing from in places if differs from in places.
A nearly perfect code can be derived from a perfect code by adding a parity check digit to the end of each codeword in , so if is a -perfect binary linear code, then is a -nearly perfect binary linear code. In this way, the nearly perfect extended Golay code can be obtained from the perfect Golay code and the nearly perfect extended Hamming codes from the perfect Hamming codes.