What role do the subnet & default gateway play in a network? Are networks differentiated by IP address and what to the subnet mask & default gateway do?

Jan F

May 11, 2014 at 2:46 am

As Oron said networking is a very complex topic and a proper explanation on how it works would become quit extensive. It would involve explaining basic networking, part of the OSI (abstraction) layers, routing and what not.

Keeping it very short and simple (while neglecting a lot of this topic):
Each device or host on an IP network has an (unique) IP address.
The subnet mask tells your system which other IP addresses (hosts) are part of your (sub)network.
The gateway is your networks "gate" to the outside world, to hosts outside of your (sub)network.

Oron J

May 10, 2014 at 5:32 pm

These are things that are a little difficult to explain if you don't have some background in computer networks, but I'll try... A network is a collection of computers connected to each other, for example, the computers you have at home, which are all connected via the same router (the internet is a "network of networks" as it were, not a single network).

Every machine on a network must have a unique address so that each computer (or other network device) can be contacted individually and without any ambiguity. That address is called an an Internet Protocol address (or "IP address in short). Most networks at the moment use IP version 4, which uses addresses made of four numbers in the range 0-255, separated by dots, such as 50.2.123.234 .

Now, let's say you have a router and several computers at home, and you want to connect them all to the internet. Your connection to the ISP, however, consists of a single line, so they can't simply all be "plugged in". What you do is you use a router. The router's essential job is to look at all network communication (which comes in "packets" containing a "to:" address), and route the communication either to the internet, or to another computer in the home. When communication from the internet reaches the router, it likewise needs to figure out which way to forward it (or whether it should reject it). The router is your gateway, and your computers need to know it's address as they obviously need to communicate with it!

Subnets are a more difficult topic as they require a discussion of how ranges of addreses are allocated, and most home networks actually use a particularly complicated trick called NAT, which I will skip. Each gateway is allocated a number from "up high" (for example, your router is given an IP address by the ISP), and permission to allocated IP addresses within a specific range in its network. For the sake of argument, let's say your router has the address 100.0.0.0 and it can allocate 256 addresses from the one above and up to 100.0.0.255. This way, all devices on hte internet have unique numbers and nobody gets hurt... The subnet mask is a way to describe the number of addresses your network will have, and it can be expresses either as a number in its right (e.g. 255.255.255.0) or as a suffix to the "top" number in the network (e.g. 100.0.0.0/8).

All of this is important because, for networks to operate, the IP addresses must make sense. If your computer has an address which is not part of its own network, other computers/routers will not be able to find it, if your gateway address is wrong then traffic won't be routed properly (which in the home would mean no Internet access) and if you have machines with duplicate IP addresses, well, who knows what will happen... I hope this helps.

Bruce E

May 15, 2014 at 8:43 pm

The easy explanation of a subnet mask: It allows the computer to identify what part of an IP address is referring to a network address and what part is referring to the host address (the individual device, or node). It is a string of binary 1s followed by a string of binary 0s that the computer (or router) uses to perform a bitwise-AND with the IP address to determine the network address where the host computer resides. A computer may reside on a network that has gateways to more than one other network, so it will use the network address to determine which gateway it needs to forward the data packet through. A router does the same thing in determining if the packet needs to go to a node that is on a network the router has a direct connection to or if it needs to forward it to another router to get it closer to its destination.

A couple of clarifications: A host number of 0 or 'max' (the value of max can change depending on the subnet mask used) might not be assigned to a device on the network for legacy support reasons. For example, a network using an IP range of 192.168.0.0-192.168.0.255 and a subnet mask of 255.255.255.0 (also expressed as 192.168.0.0/24) can have a maximum of 254 hosts on it if it doesn't support CIDR. The network itself would be identified as 192.168.0.0 and the network broadcast address would be 192.168.0.255. If the network supports CIDR (most current setups do), this does not apply. Even today, most home routers use a subnet mask of 255.255.255.0 but do not use the .0 network address or the .255 broadcast address for any devices it allocates via DHCP and the router will almost always take the host address of .1.

A default gateway is where a device will ship any packets that are not destined for a node on the (sub)network with the source device that is not explicitly directed elsewhere based on entries in the source machine's routing table. In my apartment, for example, I have 2 networks that are separated by a router/firewall. The routing table on the computer I am using right now has these entries (others irrelevant to discussion omitted):
0.0.0.0 0.0.0.0 192.168.2.1
192.168.10.0 255.255.255.0 192.168.2.2
The second one is telling the computer that if it needs to send a packet to an address on network 192.168.10.0, it needs to send it to the machine at the address 192.168.2.2 on this network. The entry for 0.0.0.0 is the default gateway which is my router that is attached to my broadband modem to connect me to the Internet and the outside world. Any packet that is not addressed to a host on either 192.168.2.0 or 192.168.10.0 will go through the router at 192.168.2.1.