Range rules require multiple TCAM entries to encode them. This algorithm  based on complementary set is proved to an optimal encoding scheme, which means that the algorithm encodes general rules with least number of TCAM entries.