Have you ever thought about how your computer can route messages to a system on the other side of the world in less than a second? The simple answer is found by learning how TCP/IP, the standard network protocol (language) of the internet, routes packets.
Every device connected to a TCP/IP network requires two different bits of information to be able to connect to the network: the unique TCP/IP address that identifies that specific device, and the network mask that tells the computer to which network “subnet” it is actually connected. Based upon the network mask, any other device that is located on the same subnet is automatically visible to that network device and the two pieces of networking equipment can “talk” with each other.
However, what happens when your computer needs to communicate with a computer that is located on a different network or subnet? It is at this time that the third element of your TCP/IP address comes into play. This element is the “default router” or “gateway” address for your network/subnet. Though this address is not required to connect to a network; however, it is required to be able to communicate with other networking devices that are located on other networks, including the internet.
If you are in a company, the default gateway address is normally the router that connects your network/subnet to your company’s network “backbone” so that your network can route the traffic to the appropriate system. If you are on a home computer or in a small company with a single subnet, the default gateway address will probably be the router that connects your system to the internet. All traffic that needs to go from your network to a different network must travel through the default gateway.
Going back to the scenario where your computer needs to communicate with a web server that is located on a different network. This server could be located across the street or it could be located on the far side of the world. As far as your computer is concerned, the only thing that is important is whether the server that it wants to talk to is on the same network or not. If, as in most cases, the destination server is on a different network, then your computer will transmit the message to the address as defined by the “default gateway”.
Upon reception of the transmission, the default gateway checks to see if the destination address is in a connected network (a gateway may be attached to multiple networks) or if it has a map to get to the destination network. If either of these is true, the gateway forwards the packet via the shortest path directly towards that network. However, if the gateway does not recognize the packet destination network and does not know which direction it should be sent to get it closer to its destination, then the gateway will direct the packet to its own default gateway. This process will continue until a gateway is reached that does not have its own default gateway parameter is set, or until a gateway is found that knows a route that can reach the destination network.
This would be similar to a person setting off on a cross-country road trip without a map (or GPS) in hand. If the person wanted to drive from Los Angeles to Boston, they could get directions to Salt Lake City, and then upon arrival in Salt Lake City, they could get directions to Denver, and then get directions in Denver to Kansas City and so on until they finally got directions in New York City on how to get to Boston.
When they started in Los Angeles, they did not know how to get to Boston, however, en route to Boston, they kept getting updated directions on how to get closer to their destination until they actually encountered their destination. This is how the default gateway concept works. Your computer does not need to know how to contact the destination computer, it only needs to know how to get to the default gateway. That, and a little bit of faith, gets the packet to its final destination.