—Designers of TCAMs (ternary CAMs) for packet classification often have to deal with unpredictable sets of rules. These result in highly variable rule expansions, and can only rely on heuristic encoding algorithms with no reasonable guarantees. In this paper, given several types of rules, we provide new upper bounds on the TCAM worst-case rule expansions. In particular, we prove that a W-bit range can be encoded in W TCAM entries, improving upon the previously-known bound of 2W − 5. We also introduce new analytical tools based on independent sets and alternating paths, and use these tools to prove the tightness of the upper bounds. In particular, no prefix encoding can encode all ranges in less than W TCAM entries. Last, we propose a modified TCAM architecture that can use additional logic to significantly reduce the rule expansions, both in the worst case and using real-life classification databases.