Routing – the point of a subnet mask on a local network

iprouterroutingsubnetswitch

I have a question regarding subnet masks and my understanding (or misunderstanding of them).

So when a subnet mask is used, a bitwise AND is performed using the subnet mask and the IP address(es). Traffic is exchanged (routed) between subnetworks with special gateways (routers) when the routing prefixes of the source address and the destination address differ. A router constitutes the logical or physical boundary between the subnets.

OK so far. But surely on everything has to be sent to a router/switch anyway right? So why do you need to have the subnet mask on your computer? If all data goes through the router, surely it is only the router that needs to have the subnet mask on it?

Best Answer

What a mask does is to define the separation between the network portion of an address, and the host portion of an address. IPv4 lets you slide these two pieces around to get a network which has enough host addresses to match your needs. This answer may help you to visualize this.

You can also use shorter masks to aggregate or summarize networks. This allows you to advertise a single route instead of a bunch of smaller routes.

But surely on everything has to be sent to a router/switch anyway right? So why do you need to have the subnet mask on your computer? If all data goes through the router, surely it is only the router that needs to have the subnet mask on it?

Not everything needs to be sent to a router. Traffic destined for the same network will never go through the router. Switches don't count since they don't participate in layer-3, where IP is.

When a host wants to send something to another host, it masks the destination address to see if it is on the same network as itself. If it is, it just sends the traffic directly to the host on the same network. If the destination is on another network, it sends the traffic to its configured gateway. It does this using layer-2 (e.g. MAC) addresses, not by changing the destination IP address.

With IPv6, you basically have a single network size (/64), so much of address manipulation is easier.

Related Topic