The router is the device responsible for connecting two computers to each other. Inside contains the appropriate instructions and protocols to allow the sending and receiving of information packets between both. So, that it reaches its destination and is not lost.
Always using the most appropriate route at all times. It may seem difficult, but in reality it is very simple. Suppose an example in which a router wants to send information from one server in Spain to another in Argentina. When trying sending it directly, the connection fails.
Then calculate that the best route is to use an intermediary server. The router in Spain will send the information to the English router, and, know that the final destination is the Argentine server, send it to a US server, which sends it to another in Brazil, who sends it to its final destination.
Each router calculates when the information arrives which is the best way for the information to arrive correctly, and also checks the information received to verify that it has arrived correctly.
So, as its name suggests, it gives you a route (and forgive the reiteration) to the information you must follow to send it from one computer to another correctly. For this, it uses, as we have said, certain instructions, commonly called routing protocol, and which are inside it.
This protocol will vary according to the type of network. In Ethernet, for example, the protocol is called IP, which identifies each computer with its own number, to avoid confusion, but they can vary.
There are routers that allow several protocols, but currently most are very specific, because they have been optimized for use with a single protocol.
The router can also work by receiving information from a network to which it is connected and then transferring it to computers that are in its scope of use. This is the typical operation of for example, wireless routers.
They are connected to the Internet, and within their coverage, any computer can access the network by connecting directly to the router, who will give an IP address to that device and will serve as an intermediary to connect to the Internet.
Also, there are particular routers for closed networks (such as companies), which operate at the local network level. These routers that create a home network are commonly referred to as SOHO (which comes from the English words Small Office-Home Office), although in large companies and multinationals the internal network can be considerable and require more sophisticated routers.