# 59 n. What is a netmask and how do I use one?

## Description

This article is from the MachTen & CodeBuilder FAQ, by Jaime Julca jjulca@tenon.com with numerous contributions by others.

# 59 n. What is a netmask and how do I use one?

Note: for this answer "address" refers to just the last number in an IP
address (e.g. 236.192.43.79 is just 79).

Think of the addresses that have been given to you as binary numbers.
161 would be represented as:
10100001 ( 128 + 32 + 1 = 161 )
And 175 would be represented as:
10101111 ( 128 + 32 + 8 + 4 + 2 + 1 = 175 )
Your netmask, 240, would be represented as:
11110000 ( 128 + 64 + 32 + 16 = 240 )

A netmask is like a face mask, with holes in it. The 1's are the holes, and
the 0's are the rest of the mask. So if you see the addresses as faces, and
the netmask as the mask, you can actually only see the first 4 bits - 1010.
Kind of like this:

"Face" (Address) 10100001
"Mask" (Netmask) 11110000
"You" (Router) 1010----

The router "looks" through the netmask at each bit of data on the network,
and if it's going to a destination that doesn't start with 1010, then it
knows it has to route that bit of data somewhere else. That's how routers
work. So your ISP has said that all of the machines on your network must
have addresses beginning with 1010. If you look at those numbers in binary,
that comes out as 10100000 to 10101111 (160-175).

Now, suppose you're trying to split this network, which has a total netmask
of 240 (11110000) into two networks. You can see that the largest either of
these subnets can be is 8 machines, because you'll need to have a larger
netmask for the router to work correctly. The next netmask you could pick
would be 248 (11111000), which only allows 8 machines to "look the same" to
the router:

10100000 (160) 10100100 (164)
10100001 (161) 10100101 (165)
10100010 (162) 10100110 (166)
10100011 (163) 10100111 (167)
- or -
10101000 (168) 10101100 (172)
10101001 (169) 10101101 (173)
10101010 (170) 10101110 (174)
10101011 (171) 10101111 (175)

So, if you're going to split your network up, you can't have more than 8
machines on each subnetwork - otherwise routing won't work. The only other
solution would be to call your Internet Service Provider and request more IP
numbers, say 160-191. That would give you a netmask of 224, and you could
use 240 as a subnet mask, giving you up to 16 machines on each subnet.

Continue to: