Routing and switching can be two terms that are difficult to differentiate, so here is a simple explanation that may help to clarify things. First of all switching and routing are not the same thing. Switching involves moving packets between devices on the same network. Conversely, routing involves moving packets between different networks.
Switches operate at layer 2 of the OSI Model. A switch, also referred to as a multi-port bridge, is able to determine where a packet should be sent by examining the MAC address within the data link header of the packet (the MAC address is the hardware address of a network adapter). A switch maintains a database of MAC addresses and what port they are connected to.
Routers, on the other hand, operate at layer 3 of the OSI Model. A router is able to determine where to send a packet using the Network ID within the Network layer header. It then uses the routing table to determine the route to the destination host.