We give a bound on the expected reconstruction error for a general coding method where data in a Hilbert space are represented by finite dimensional coding vectors. The result can be specialized to Kmeans clustering, nonnegative matrix factorization and the sparse coding techniques introduced by Olshausen and Field.