1. A method for a forwarding element that forwards packets, the method comprising: receiving a packet; identifying a prefix length associated with an IP address in a header of the packet by traversing a tree structure to count a number of bits of the packet header IP address that match a set of values in the tree structure, the tree structure comprising sets of values for comparing to one or more bits of the packet header, each set of values corresponding to an IP address in a rule for matching against the packet header IP address; identifying a matching rule corresponding to the packet header IP address by looking up a first set of subtables comprising rules matching IP addresses with up to the identified prefix length, wherein lookups of a second set of subtables comprising rules matching IP addresses longer than the identified prefix length are skipped; and generating a flow entry based on the matching rule, wherein the flow entry is used to process packets that have a prefix length up to the identified prefix length.