In this work, we propose a general framework for constructing rate-compatible ECCs based on cosets and syndromes of a set of nested linear codes. We evaluate our construction from two points of view. From a combinatorial perspective, we show that we can construct rate-compatible codes with increasing minimum distances. From a probabilistic point of view, we also prove that we are able to construct capacity-achieving rate-compatible codes. Performance of two-level rate-compatible codes is evaluated for a multi-level cell (MLC) flash memory.