A router is a device, in computer networking, that forwards data packets to their destinations, based on their addresses. The work of a router is called routing, which is somewhat like switching, but a router is different from a switch. The latter is simply a device to connect machines to form a LAN (Local Area Network).
How a Router Works?
When data packets are transmitted over a network (say the Internet), they move through many routers (because they pass through many networks) in their journey from the source machine to the destination machine. Routers work with IP packets, meaning that it works at the level of the IP protocol.
Each router keeps information about its neighbors (other routers in the same or other networks). This information includes the IP address and the cost, which is in terms of time, delay and other network considerations. This information is kept in a routing table, found in all routers.
When a packet of data arrives at a router, its header information is scrutinized by the router. Based on the destination and source IP addresses of the packet, the router decides which neighbor it will forward it to. It chooses the route with the least cost, and forwards the packet to the first router on that route.
Do I need a router? If you have a LAN (Network) and want to connect it to the Internet, then you need a router.