ternary content-addressable memory (TCAM)

What is ternary content-addressable memory (TCAM)?

Ternary content-addressable memory (TCAM) is a specialized type of high-speed memory that searches its entire contents in a single clock cycle. The term ternary refers to the memory's ability to store and query data using three different inputs: 0, 1 and X. TCAM is most used in network routers to store address lookup tables.

TCAM is a more flexible version of content-addressable memory (CAM).

What is content-addressable memory?

Content-addressable memory is a special type of computer memory that stores data, like RAM. In RAM, the central processing unit (CPU) can only access the data by specifying the memory address and reading out the data. CAM can also essentially work in reverse; the CPU specifies what data it is trying to match -- the key -- and the memory returns the memory location that matches the search key. CAM can only search on exact matches of binary strings.

TCAM, for its part, searches the memory to match the key, like CAM, and can also use a mask to indicate "don't care" or wildcard bits. This results in three possible states: 0, 1 and X, a wildcard. Using mask bits allows for much more flexibility in searching.

How is TCAM used?

TCAM can perform one search each clock cycle. This is much faster than searching traditional RAM, which requires many clock cycles to query and check each memory location.

To illustrate the power of TCAM for searching compared with traditional RAM, imagine you were looking for a specific sentence in a book. Searching in traditional RAM would be like looking through each page one at a time to find the sentence. CAM would be a book with an index or concordance that you could check to tell you exactly where in the book a certain word is used.

CAM and TCAM do have some disadvantages. These memory cells require additional transistors to support the search feature. This makes it more expensive and less dense compared with traditional RAM. Each memory cell needs to be active on every cycle to perform the search, so it requires more power and produces additional heat.

The benefits of transistors.
To support its advanced search capabilities, TCAM requires more transistors than standard memory, which makes it more expensive.

Given the tradeoffs, CAM and TCAM are mainly used as an additional memory location for special applications to store a relatively small data set that needs to be searched very quickly, very often. The most popular use is in network routers to store rule lookup tables. Other uses are within a CPU's translation lookaside buffer, in database systems or in artificial neural networks.

TCAM in networks

Large network routers can process tens of millions of packets every second. That means it needs to do millions of small searches to match the packet to the routing table. TCAM enables the router to perform a search and find a result in only one cycle.

For example, a rule could be set up to match all IP addresses in the subnet. This could be recorded as 00001010,XXXXXXXX,XXXXXXXX,XXXXXXXXX in TCAM. If the IP address came in, it would be translated to the binary string 00001010,01100100,00010100,00000101, and it would match the rule.

Routing tables will often contain rules for things such as media access control addresses, IP addresses, network protocols or ports. These are all directly encoded as binary data in a packet header, so they are easy to search on TCAM.

Due to its specialized use, the TCAM in a router is often much smaller than the general RAM. A smaller enterprise router might only have about 20 megabytes' worth of TCAM storage. Large internet routers in use at backbone internet service providers might need to store the entire Border Gateway Protocol table in TCAM, which is quickly approaching a million entries. These routers often use dedicated application-specific integrated circuits and can have separate TCAM storage for different uses. If a router is unable to store all its routing entries in TCAM, it will fall back to slower memory, which will result in high CPU use and dropped packets.

The administrator often does not directly control the TCAM storage. When programming the router, the software will take the rules and translate them to the TCAM. The administrator can define how the TCAM storage is partitioned. For example, IPv4 rules use less memory space than IPv6, so setting the router to mainly store IPv4 will allow for more saved rules.

TCAM can also be used in network intrusion detection. These devices can store known malicious fingerprints or hashes and quickly compare observed traffic with the malicious data stored in TCAM.

Diagram of an IPv6 header.
Routing table rules are directly encoded in a packet header, making them easy to search on ternary content-addressable memory.

TCAM in neural networks, machine learning and AI

The possible uses of TCAM for neural networks, machine learning and artificial intelligence (AI) is currently an active area of research. It is understood that the highly parallel nature of searching in TCAM compared with typical memory could greatly speed up many of these processes. As this is still being researched, there are currently no major hardware devices available on the market for this use.

Learn about common network protocols and their functions, common types of networks with their use cases and types of network devices. Explore the differences between AI vs. machine learning vs. deep learning and check out memory management strategies to improve virtual machine performance.

This was last updated in November 2023

Continue Reading About ternary content-addressable memory (TCAM)

Dig Deeper on Network infrastructure

Unified Communications
Mobile Computing
Data Center