routing table

What is a routing table?

A routing table is a set of rules, often viewed in table format, that's used to determine where data packets traveling over an Internet Protocol (IP) network will be directed. This table is usually stored inside the Random Access Memory of forwarding devices, such as routers and network switches.

In computer networking, each routing table is unique and acts as an address map for networks. It stores the source and destination IP addresses of the routing devices in the form of prefixes along with the default gateway addresses and corresponding routing information.

Routing tables are typically updated dynamically through network routing protocols. But sometimes network administrators might add static entries manually.

How does a routing table work?

The main purpose of a routing table is to help routers make effective routing decisions. Whenever a packet is sent through a router to be forwarded to a host on another network, the router consults the routing table to find the IP address of the destination device and the best path to reach it. The packet is then directed to a neighboring router -- or the next hop listed in the table -- until it reaches its final destination.

According to AWS, to handle network traffic, a router consults its routing tables millions of times each second.

Routing table entries

Each routing table might contain different entries and information, such as IPv4 or IPv6 address classes. But the primary fields of all routing tables stay the same.

The following are the main entries of a routing table:

  • Destination. This is the IP address of the packet's final destination.
  • Subnet mask. Also known as the netmask, this is a 32-bit network address that identifies whether a host belongs to the local or remote network. To enhance routing efficiency and reduce the size of the broadcast domain, administrators can apply a custom subnet mask through the process of subnetting, which can divide a network into two or smaller connected networks.
  • Gateway. This is the next hop, or the neighboring device's IP address to which the packet is forwarded.
  • Interface. Routers typically use Ethernet interfaces to connect to other devices on the same network, such as eth0 or eth1, and serial interfaces to connect to outside wide area networks (WANs). The routing table lists the inbound network interface, also known as the outgoing interface, that the device should use when forwarding the packet to the next hop.
  • Metric. This entry assigns a value to each available route to a specific network. The value ensures that the router can choose the most effective path. In some cases, the metric is the number of routers that a data packet must cross before it gets to the destination address. If multiple routes exist to the same destination network, the path with the lowest metric is given precedence.
  • Routes. This includes directly attached subnets, indirect subnets that aren't attached to the device but can be accessed through one or more hops, and default routes to use for certain types of traffic or when information is lacking.
routing table
Screenshot of the contents of a routing table.

How does network routing work?

A network packet must take various steps to reach its destination. To understand the relationship between routing and the routing table, examine the following steps that occur during the transfer of data packets:

  1. A computer sends a packet to a router. Similar to the address on a postal package, a sending device -- such as a computer -- attaches IP addresses to data packets and sends them to a router. This helps the router determine the best routes to transport the packets to their destinations. A computer typically connects to a local area network (LAN) to send packets while a router can send packets between different LANs and WANs.
  2. The router receives the packet. Once the router receives the packet, it analyzes it against its internal routing tables to determine the most efficient path to send the packet through. The goal of the router is to forward the packet to the router closest to its ultimate destination.
  3. The router routes the packets. It's unlikely that the initial router will get the packet directly to its destination. It looks at the routing table to get the packet to the next hop. The routing table keeps the hop count low by providing the router with the most effective route. The final hop count is the number of times a packet goes from one router to another until it reaches its destination.
  4. The process is repeated. At the next hop, another router takes over and repeats the same process of determining where to send the packet by looking at its internal routing tables. This process repeats several times before the packet reaches its destination. The routing process might sound lengthy, but it's extremely quick due to the routing protocols involved.
  5. The packet reaches its destination. Once a packet has finally reached a router that resides on the same network as the destination IP address, it's directly routed to the device or server that it was intended for.

Types of routing: static routing vs. dynamic routing

Routing is the process of selecting the most ideal path to a network and routers use the information entered in a routing table to determine the best route. Essentially, there are two methods of building and maintaining a routing table: static routing and dynamic routing.

How static routing compares to dynamic routing
The differences between static and dynamic routing.

The pros and cons of static routing

  • A network admin manually creates, manages and updates static routing table entries.
  • The entries for static network devices don't change unless a network admin manually changes them.
  • Static routes provide a granular level of control over routing, as each route is manually configured for full connectivity.
  • For large networks, it can become practically impossible to add a manual entry for every route.
  • Static routing saves bandwidth and overhead because routers don't share static routes.
  • Static routing isn't fault tolerant. Any changes to the network infrastructure, such as the addition of a new network or a link going down, aren't automatically updated and require manual intervention.
  • In a static environment, if a link becomes unavailable, the routers don't have the option to automatically switch to a better route.
  • Static routes always have an administrative distance (AD) of 1, which is given preference over dynamic routes, unless the AD is changed. A modified AD is known as a floating static route.

The pros and cons of dynamic routing

  • In dynamic routing, devices automatically build and maintain their routing tables by using routing protocols to exchange information about the surrounding network topology. Examples of routing protocols include Routing Information Protocol, Enhanced Interior Gateway Routing Protocol and Open Shortest Path First.
  • Dynamic routing tables let devices listen to the network and respond to occurrences such as device failures and network congestion.
  • Dynamic routing consumes more bandwidth and overhead because routers share the dynamic routes with each other.
  • A router can dynamically choose a better path if there's a change in the routing infrastructure.
  • Dynamic routing is easier and simpler to configure on larger networks.
  • Dynamic routing lets routers load balance between multiple links.
  • The routing protocols -- not the network admin -- choose the best routes to the destination.

Subnetting plays a vital role in the world of IP routing. Learn how to break a network into smaller subnets and calculate the subnet mask of an IP address based on the required number of subnets and hosts.

This was last updated in November 2022

Continue Reading About routing table

Dig Deeper on Network infrastructure

Unified Communications
Mobile Computing
Data Center