Memory - CAM and TCAM

Content-Addressable Memory (CAM) and Ternary Content-Addressable Memory (TCAM) are two types of special computer memory used in various very-high-speed searching applications. These are also known as types of "associative memory" or "associative storage" especially useful for comparing input search data against a table of stored data, which returns matching data.

Cisco devices such as switches, routers, and firewalls use these types of hardware memory for particular purposes, such as MAC address table lookups, Access-List (ACL) lookups, or Routing Table lookups.

What makes CAM and TCAM memory fast is the fact that all entries can be searched for in parallel. So if you have hundreds of entries, you can search for a particular value in all the entries in just a single clock cycle.

The difference between CAM and TCAM has to do with the search algorithm that each uses, an algorithm that is hardwired into the circuitry of the memory itself.

CAM requires an exact match to return a result. This means that the value that is being searched for (in binary) must contain either 0s or 1s.

TCAM does not require an exact match, and is queried using 0s, 1s, and Xs, where X essentially means “anything” (that is, either 0 or 1). It’s kind of like a wildcard state. The name "ternary" CAM comes from the fact that you use three states rather than two.

Now applying this to networking devices, when looking up an address in the MAC address table, you always require an exact match, so CAM is used. When looking up a prefix in a routing table, you don’t need an exact match, as long as the destination is contained within the prefix in the routing table, and that is where TCAM is used.