Most of us have a private network at home and, when configuring it, we are always asked for a subnet mask. Whoa, what’s that? And what has a “mask” to do with my tiny network?
Let’s start off with some definitions that should be common sense, bu who knows.
For instance, everybody here knows what an IP address is, and even how a LAN works and what are the main problems we may encounter configuring one (if not, then Google is your friend!).
In a domestic setting, the subnet mask should always be set to the default 255.255.255.0 thus allowing 254 hosts to be connected altogether; in a slightly different reality (that is, a office or some other department), there’s the need for a more complicated and intelligent network configuration, as well as a huge number of hosts connected at the same time.
And here comes the subnetting thing.
You must know (hell, you already should, anyway) that a IP address is 32 bits (4 bytes, yay) long and made up of two components, a network potion and a host portion.
The network address is used to identify the network and is common to all the hosts attached to the network; the host address is used to identify a specific host (or node) attached to the network.
IP addresses are usually represented in dotted decimal notation, that is 4 octets in decimal format separated by decimal points.
Classes exist to split IP addresses into 6 major groups, based on their main use.

Note Class A addresses’ first octet cannot be either 0 or 127 as these values are used respectively for host identification and loopback facilities.
Also note the maximum amount of addresses available are (2E32)-2.
Subnetting comes into play whenever we want to divide the network into smaller portions called subnets. This is done by “borrowing” bits from the host portion of the IP address enabling more efficient use of the network address.
A subnet mask is thus useful to define which portion of the address is used as network identification and which part is the host address.
Every time a frame is delivered to a routing device, the latter does two things:
If the result of the two operations is the same, the hosts are part of the same network (router then forwards the frame); else the two hosts are on different networks and it’s time to apply some routing procedure to send the frame correctly.
Calculating the subnet mask required for a particular purpose (i.e. number of subnets) is all but difficult.
Once defined the number of subnets desired N (say, 8) and identified the IP address class (say, Class C 192.168.100.x), the very first thing to do is finding how many bits are required to obtain N combinations (in our example, 3 — always choose the upper number if not a power of 2).
Binary speaking, the subnet would be
1111 1111.1111 1111.1111 1111.1110 0000
thus equal to the decimal 255.255.255.224
This is because we borrowed three bis from the host portion for subnetting.
The maximum number of hosts per subnet will then be 2^(32-H)-2 where H is the number of bits of the subnet mask set high (in the example, we set high 27 bits, yielding 2^5 -2 thus 30 hosts per subnet).
At this point, IP addresses can also be written in the form X.X.X.X/H where X and H are respectively decimal values and the number of bit set high in the subnet mask.
For detailed subnet tables showing all possible ways a major network can be subnetted and, in each case, how many effective subnets and hosts are possible, see Subnetting tables (TXT)
32 bits is 4 bytes, not 8.
Yep, definitely.
Thanks for reporting, I have fixed it
Nice technical overview.
By way of summary, I would like to add that all hosts in the same subnet are on the same data link. I.e. hosts in the same subnet are able to address each other directly by MAC address. A host applies the subnet mask against a destination address and if it sees ones left over, it knows the destination host’s network address is outside of its subnet, and it sends packets to the MAC address of the subnet’s gateway. If the host sees only zeros left over after the mask operation, it knows the destination host is on the same data link (i.e. is in the same subnet), and it sends packets directly to the MAC of the destination host.
Pete, thanks for your valuable addition!
Wow this is a great resource.. I’m enjoying it.. good article
it was very interesting to read.
I want to quote your post in my blog. It can?
And you et an account on Twitter?
Feel free to quote whatever you like on your blog, just add a simple link to this page if possible.
I am on twitter, too — but I rarely log in though (@screamingagony)