1. A non-transitory machine readable medium storing a program that when executed by at least one processing unit forwards packets, the program comprising sets of instructions for: receiving a packet; examining a first set of rules to find a common match which includes a set of one or more bits that the rules have in common with one another, each bit of the common match corresponding to a bit in a header of the packet; defining a wildcard mask comprising a plurality of bits, each bit in the wildcard mask (i) corresponding to a bit in the header of the packet and (ii) initially set as a wildcard bit; identifying a position of a differing bit from a first set of bits of the packet header that is different from a corresponding bit in the common match; from the wildcard mask, unmasking a bit that is at a same bit position as the position of the differing bit; comparing a second set of bits in the packet header with a second set of rules to find a matching rule; and generating a flow entry comprising a set of un-wildcarded bits based on the matching rule and said unmasked bit of the wildcard mask, wherein the flow entry is used to process other packets that match each un-wildcarded bit of the flow entry.