A Subnet Mask defines which range of IP Addresses are within a local network, and which ones are not. Subnet masks always work from left to right. Devices are said to be within the same subnet if their IP Address starts with the same digits, but ends with a different set of digits. Sometimes, it's easy to tell which part of an IP address is part of the local network and which is not (when the subnet mask consists only sections that are 255 and 0), but sometimes it may not be as clear.
The very first address and very last address in a subnet are specially reserved addresses and cannot be assigned to devices. Devices that are within the same subnet will be able to communicate with one another, but a gateway is required to communicate with devices in different subnets. When traffic is intended for a device outside of the subnet, it is sent to the gateway to be routed to the correct destination. The gateway then sends the response back to the device that originally sent the request.
What is default Gateway?
When a computer on one network needs to communicate with a computer on another, it uses a router. A router specified on a host, which connects the host's subnet to other networks, is called a default gateway. This passes traffic on one subnet to devices on other subnets. This gateway often connects the local subnet to the internet.
If the subnet mask is 255.255.0.0, then the first two octets of all devices must be the same. The combination of the last two octets must be different and unique. 65,534 devices can be used in this subnet.
If the subnet mask is 255.255.255.0, then the first three octets of all devices must be the same. The 4th octet must be different and unique. A maximum of 254 devices can be used in this subnet.