There are 3 major components to the network configuration:
- IP Address
- Network Mask
- Default Gateway
The Operating System needs to know the network mask in order to determine where the data needs to travel. Your IP address combined with the network mask tell the OS whether a target IP address exists on the local subnet, or if it exists outside of your subnet. Some computers have multiple network connections, whether physical (multi NIC) or logical (think VPN). Without a subnet mask for each network, the OS would not be able to determine which traffic should leave which interface.
If the target exists within your subnet:
- Your OS determines the hardware address of the destination by referencing its ARP table. If there is no entry in the ARP table for that address, the system sends out a hardware broadcast that is flooded to all devices on the layer 2 network. The system who owns the IP address would then respond to the broadcast with its hardware address (MAC ADDR). The OS would then send the data along, with it never leaving the local network.
If the target does NOT exist within your subnet:
- Your OS determines where to send the packet based on its routing table. Most often than not, the packet will be destined for the default gateway. This gateway is generally a router which will use its own routing tables to send the packet on its way to its final destination. The process of sending to the default gateway is the same as sending to another host on the subnet. If the gateways MAC address isn't in the ARP table, it will send a broadcast out to determine the gateways hardware address, and then forward the frame.
So as you can see, the subnet mask is very important as it is used to determine the location of the destination network, and route them accordingly.