Routing and switching are the basic functions of network communication. Routing and Switching are different functions of network communications. The main differences between Routing and Switching are as below.
The function of Switching is to switch data packets between devices on the same network (or same LAN - Local Area Network). The function of Routing is to Route packets between different networks (between different LANs - Local Area Networks).
Switches operate at Layer 2 of the OSI Model (Datalink Layer). A switch knows where to send a data packet by using Layer 2 addresses (MAC address - hardware address of a network adapter). A switch maintains a table of MAC addresses (MAC Address table or CAM Table) and what physical switch port they are connected to. The Switching function can be explained more simply that, Switching is the function of moving data packets (Ethernet Frames) within the same LAN (Local Area Network).
Routers operate at Layer 3 of the OSI Model (Network layer). A Router knows where to send a packet by using Network part of the destination IP address. A Router maintains a table called Routing Table and uses the routing table to determine the route to the destination network.