Routing
Routerβ
A router is a device that can forward packets between it's own interfaces using IP address and the routing table.
Router extracts the IP from the Ethernet frame and then uses its routing table and forwards it to another interface.
Routing Rulesβ
It's the rule that simply states
- which network interface to use.
- 'next hop' IP address to use (if any).
It doesn't say which IP to use or which MAC to use. It only says which interface to send it to. This is exactly why L3 routing happens at the beginning of the network transmissions.
Once the interface is selected using routing table, then the L2 address resolution happens to find the MAC address of the next hop.
Router is one single programβ
Even though router has multiple ports, the router has one single routing table. This is how the data coming from one port is routed to another port by the router.
Since router is one single program which just handles data from multiple interfaces, the routing between two domains happen together with the help of switches.
Router and Switch Integrationβ

It's important to keep in mind that, routers always open up the frame until layer 3 and do the routing based on that. Whereas, switches will open only the frame to check MAC address and route based on that.
Both have their software written which reads data from and to multiple ports.