Look what I found!! This is an archive of what my site/life was about 4-5 years ago. For the modern JobyBednar.com, try here.
JobyBednar.com
To be pleased with one's limits is a wretched state.
- Johann Wolfgang von Goethe

Ruby Development
/root
  ./apple I
  ./articles
  ./code
  ./decode
  ./hobbies
  ./mac
  ./pics
  ./ruby
  ./www



 Use OpenOffice.org
Articles >> IP Subnetting and Subnet Masks
IP Subnetting and Subnet Masks
IP Subnetting and subnet masks form the basis of all networks, either professional or personal in-home uses like having a cable modem. Yet, understanding what they are and why they exist has a tendency to lose a few people once you start juggling around the binary. Hopefully, this article will dispel some of the mystery and help you understand what those numbers mean in your Network Connection's properties for TCP/IP. (aka "those numbers you need to connect to the Internet with.") The topic is pretty easy to understand as long as you have a solid foundation of understanding for: IP addresses, basic network functionality, and some binary arithmetic.

IP Addresses - An IP address (like 192.168.0.1) is a unique identifier for any computer connected to a network, or better yet, the Internet. When you are browsing online and type in something like "http://www.jobybednar.com", your computer connects to a server and finds the IP address of that URL and uses that to send and receive info. The protocol used for accessing web sites is TCP/IP. IP is a protocol that allows info to be sent and received from system to system across the Internet, and TCP is a protocol that uses IP and adds in a little error correction and flow control. TCP/IP isn't limited to just websites, but that is probably the most commonly understood use for people not familiar with the protocols in general. Amazingly, as the name might suggest, "IP addressing" is the addressing system used in the IP protocol. The IP address can be thought of as being like your home address. When you send a letter to anyone in the US, you use the US addressing system of number, street, city, state, zip. When you send a message across the Internet, you use the IP address.

The structure of the IP address is very simple, and very important to understand for subnetting. An IP address consists of four blocks of numbers ranging from 0-255 (like 192.168.0.1). The information is actually stored in a binary structure, where each number block uses 8 bits of 1s and 0s (thus the 0-255 range)... a total of 32 bits. Doing some quick math, that allows for 232 unique IP addresses, better known as 4,294,967,296 unique IP addresses in the world.

Quick Note: There are actually two different IP protocols: IPv4 and IPv6. IPv4 is what every refers to when saying IP and uses the 32 bits for the address. IPv6 is the newer protocol still being developed and implemented that will eventually replace IPv4. IPv6 uses 128 bits for it's addressing which allows for a whopping 2128 unique IP addresses (more than 340,000,000,000,000,000,000,000,000,000,000,000,000)! Why so many? With over 6 billion people on the planet, and everyone and their brother owning a plethora of Internet related devices, only 4.2 billion addresses just doesn't cut it, especially when we discuss the waste involved in an IP address class system (keep reading).


IP Address Structure (IPv4)
192 168 0 1
1 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1


IP addresses were originally divided into classes. They are Class A,B,C,D and E. This was done to be able to assign a large block of IP addresses to a given entity instead of assigning one at a time. If you are a home user, one or two IP addresses may be fine, but for a large corporation that spans the world, you'll need hundreds or possibly tens of thousands. The class system, allowed a block of IP addresses to be assigned and it was to the freedom of that entity to decide how to split them up. The class was determined by the first few bits of the IP address. Any IP address starting with a '0' was given the Class A title. Class B is any address starting with a '10', Class C starts with a '110', Class D starts with '1110', and Class E starts with '1111'. The rest of the bits could be anything, so each Class therefor allowed for a specific numerical range, of which all IP addresses falling within that range would be part of that Class. Class D is reserved for broadcasting, and Class E is just reserved for later use, so in reality, Class A-C is mainly just used.

Class IP Class Structure IP Ranges
Class A 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0.0.0.0 - 127.255.255.255
Class B 1 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 128.0.0.0 - 191.255.255.255
Class C 1 1 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 192.0.0.0 - 223.255.255.255
Class D 1 1 1 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - 224.0.0.0 - 239.255.255.255
Class E 1 1 1 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - 240.0.0.0 - 255.255.255.255


As mentioned before, you would be assigned a Class address block rather than individual addresses. The blocks/Class relationship was as follows:
  • Class A - The first 8 bits are unique to you and you can assign the remaining 24 bits as needed. (Example: 120.x.x.x is given to you and you can use 120.0.0.0 to 120.255.255.255)
  • Class B - The first 16 bits are unique to you and you can assign the remaining 16 bits as needed. (Example: 128.12.x.x is given to you and you can use 128.12.0.0 to 120.12.255.255)
  • Class C - The first 24 bits are unique to you and you can assign the remaining 8 bits as needed. (Example: 200.14.120.x is given to you and you can use 200.14.120.0 to 200.14.120.255)
Class IP Class Structure Unique IP Addresses
Class A 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 224 = 16,777,216
Class B 1 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 216 = 65,536
Class C 1 1 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 28 = 256


This allowed an entity to be assigned an IP range like 64.x.x.x which they could brake up as needed. An ISP for example can break the addresses up for their hosting clients. As handy as this was, however, huge volumes of IP addresses were wasted. Suppose a business has 260 systems they need unique addresses for. Under this method, they would have to be assigned two Class C address blocks. They would then use 260 of them, but would have available 512... wasting 252 addresses. This was even worse in the use of Class B and A addresses. What to do? Enter Subnet Masks.

A Subnet Mask is simply the amount of bits unique to your assigned IP address block. As noted above in red, Class A has a subnet mask of the first 8 bits, Class B uses the first 16 bits, etc. Effectively, the subnet mask describes the range of usable IP addresses that were assigned to you to use within your network. For the Class based method of subnet masking, they are preset based on the first few bits of the IP address. In a subnet mask, however, you can specify what your subnet mask is. Instead of getting a Class C where the first 24 bits are unique, you can be given a Class C address with a subnet mask of the first 28 bits. The remaining 4 bits can be used as you see fit, allowing for only 16 unique IP address combinations! Much less chance of wasting IP addresses. The number of bits within your subnet mask is often written as "/x", where 'x' is the number of bits. (eg "194.23.56.0" with a subnet mask of "/28") The subnet mask can also be written as an IP address where the assigned bits are 1s and your variable range are 0s. (eg "194.23.56.0" with a subnet mask of "255.255.255.240")

IP Address Subnet Mask IP Structure w/Mask Unique IP Address Range
12.127.8.7 Class A (255.0.0.0) 0 0 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 12.0.0.0 - 12.255.255.255
12.127.8.7 255.240.0.0 0 0 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 12.112.0.0 - 12.127.255.255
12.127.8.7 255.255.255.128 0 0 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 12.127.8.0 - 12.127.8.127


I have said that the subnet mask can be expressed as an IP address such as 255.255.255.0. The unique bits are 1s and the variable bits are 0s when determining the IP address form of the mask. In reality, the computer is performing a simple AND bit operation to the IP address and subnet mask to determine the network range. Let's further explore basic networks and then get back to the subnet mask.

Basic Network Structure - If you connect to the Internet you are part of a network. To keep the discussion basic, I'm going to assume you are within a simple LAN (local area network) that consists of a router and a bunch of computers (one or more). The computers all sit behind a router, on the other side is the magic Internet. Either you own the router at home, our the router is part of your ISP (Internet service provider)... but one way or another your computer is part of a network with a router sitting between you and the glory of the Internet. Each router, as mentioned, keeps track of a routing table that lists IP addresses (network identities), subnet masks, and ports. When a router receives a packet, it will see which IP address it is going to. It performs a calculation on the IP address to see if it matches any of the entries for the network IDs. If so, it sends it through the proper port and the packet enters that local network. Each computer needs to be given a unique IP address within that network range. The router needs to know what the network range is. The computers, in turn, need to know where that router is so they can send packets to it to be sent outside the local network and out to the Internet. The computer also needs to know what network range (subnet mask) it is within so if it needs to send data to another system, it knows if it should talk to the router for the data to be sent out, or keep the signal internal to the local network.

For argument's sake, lets make this simple. You have a computer and a laptop. Both of them are connected to your wireless router, which is connected to your cable modem. Your local network consists of your computer (we'll assign it IP address 192.168.1.1) and your laptop (assigned IP address 192.168.1.2). Your router will also be given an IP address so your computers can connect to it (we'll assign it 192.168.1.254). Let's also say that you have been given the IP address 192.168.1.0 with a subnet mask of 255.255.255.0. As you have guessed, you can use any IP address between 192.168.1.0 to 192.168.1.255.

Quick Note: Although you are given the ability to use all the IP addresses within a range, in actuality, the - and bottom-most IP addresses are reserved. The bottom-most IP address (in our example 192.168.1.0) is the Network Identity, and the top-most address (in our example 192.168.1.255) is for broadcasting to all systems within the network group. Your usable IP address range are all the others. In this example I am using the top-most USABLE IP address as the router's IP address and each system assigned from the bottom-most USABLE IP address up.


Let's say your computer wants to get a web page from some server. The server's URL is "http://www.jobybednar.com"... but what is the IP address? Your computer needs to know this for the TCP/IP packet which requires IP addresses. Your computer will then also need to know where a DNS (Domain Name Server) is that it can ask to translate the URL to an IP address. Your cable modem provider gave you a DNS system they manage and told you what it was. Your computer converts the URL to an IP using the DNS system. The IP address is 64.7.34.67. Your computer performs a binary AND operation on the IP address and subnet mask to see if it resides within your local network. They don't match, so it sends the packet to request a web page to the router to send outside of the network. On the other hand, if you were sharing files, the IP address in question would be your laptop, so the binary AND operation would result in a match with your network, so the system would know to send it internally, rather than bothering the router. That is all the info your computers need to access the Internet, or other networks: Their IP address, their subnet mask for their network range, a DNS server, and the IP address for the router (aka Default Gateway). But what is this "binary AND operation on the subnet mask and IP address?" Let's review Binary Logic and how it applies.

Binary Logic and Arithmetic - Binary is either a 1 or a 0. That's it. Done. To express numbers other than just one and zero, a collection of binary digits are used... just like we use a collection of decimals (0-9) to express numbers larger than 9... like 192. In binary, the smallest digit is to the right, just like in decimal numbers. As in the first table above, 192 can be expressed as 11000000 in binary. Each digit in decimal notation is x*10y where x is the digit used and y is the place of the digit. 192 is actually (1*102)+(9*101)+(2*100). In binary, the notation is x*2y, so 192 is (1*28)+(1*27). A subnet mask of 255.255.255.0 is then expressed as 11111111 11111111 11111111 00000000 in binary IP addressing.

Logical operations consist of True and False being evaluated to arrive at an answer that is either True or False, in the following manner:

X Y Opperation Result
False (0) False (0) AND False (0)
False (0) True (1) AND False (0)
True (1) False (0) AND False (0)
True (1) True (1) AND True (1)
False (0) False (0) OR False (0)
False (0) True (1) OR True (1)
True (1) False (0) OR True (1)
True (1) True (1) OR True (1)


Logic of True and False can easily be represented by 1 and 0. An IP address and a subnet mask can be logical ANDed together to obtain the Network ID, or the low-end IP number within the network range. Each bit in each position of the IP numbers are compared:

IP Address AND Subnet Mask
IP 192 168 2 7 1 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1
Subnet Mask 255 255 255 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
Network Identity 192 168 2 0 1 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0


That's pretty much it! Subnets and Subnet Masking is a way to breakup a larger Class-based network into a smaller group of systems... preventing IP address waste. Every network has a subnet mask with the IP addresses assigned. To check what your IP address, subnet mask, DNS server and default gateway are, refer to the previous article on Setting Up and Securing a Wireless Router. Take a look at your settings that have been configured into your network and see what sense you can make of them. For example, on my cable modem config settings, my subnet mask for my router's IP address within the cable modem's local network is 255.255.254.0, which means that I am on a network that can support 510 users. The way cable modems are designed, I'm sharing the bandwidth with those 510 other people. Ouch.

Quick Note: In addition to breaking up IP addresses in smaller subnets, a couple addresses have been reserved to be used ONLY within local networks. This allows for even greater prevention of IP address waste. Using a system called NAT, a single IP address can be assigned to a router connected to the outside world, however, inside the network, you can use all the IP addresses you can. Every router in the world knows that if it sees one of these reserved IP addresses, it doesn't pass the packet on beyond it's border and knows the packet is destined for an internal system. The most common of the reserved IP addresses is 10.x.x.x with a subnet mask of 255.0.0.0, and 192.168.x.x with a 255.255.0.0 subnet mask. In the example of my cable modem, I have been given an IP address which I set to the router's IP address for the port that connects to the cable modem's network. Internally, my default gateway on my router is a 192.168.x.x IP number and my systems are also a 192.168.x.x IP address. This allows me to only use the one IP address my ISP provided, but still be able to use any number of systems within my local network to use the TCP/IP protocols to connect to the outside world.


Hope this helps dispel some of the mystery to networking and subnet masks! You should be able to look at your computer and better understand the network your are on. Better yet, if you need to reinstall your ISPs configuration settings, you now know what info you need to get your computer online as fast as possible and not be subject to being on hold with tech support.

--Joby Bednar