#### Before you start

Objectives: learn what is IP address, how it is constructed, how to convert it between its decimal and binary form, which IP address classes are there, and what is Subnetting.

Prerequisites: no prerequisites

IP address is a 32-bit binary number represented as four octets (four 8-bit numbers). Each octet is separated by a period. IP addresses can be represented in decimal or binary notation. In decimal notation, each octet must be between 0 and 255. In binary notation, each octet is an 8-character number. The IP address is a layer 3 address, meaning that it is a logical address associated with a Network layer. The decimal value of some IP address might be 100.100.100.100. IP address is represented as a decimal number because that’s easier for us to work with, but computers use binary numbers. To understand how IP addresses work we need to know about how the binary numbering system works.

#### Binary to Decimal Conversion

Each position within the IP address is called an Octet. Octet consists of eight binary numbers, or a series of ones and zeros. For example, the decimal number 100 would be represented in binary as 01100100. The whole IP address 100.100.100.100, in binary format would then be 01100100.01100100.01100100.01100100.

An Octet that is all zeros gives us the first possible value which is zero. An Octet that is all ones equals 255. That’s why each octet within the IP address must range between zero and 255. As we work with IP addresses sometimes we will need to convert the decimal form of the IP address to a binary form of the IP address. The easiest way to do this is to memorize the decimal equivalent of each bit within an octet. Let’s look that in a case of Octec with all ones (255 decimal).

 Binary: 1 1 1 1 1 1 1 1 Decimal: 128 64 32 16 8 4 2 1

Notice that 1 in the most right position equals a decimal 1. A 1 in the second position equals decimal 2, 1in third position equals decimal 4, fourth position equals decimal 8, fifth position equals decimal 16, and so on. Recognize a pattern in which we’re simply doubling the number that has come before. Now that we know decimal equivalents of binary positions in an Octet, we can easily convert binary number to decimal. To do that we simply need to sum up all decimal values where there is 1 in the binary representation. In the case of 11111111 we have to add 128+64+32+16+8+4+2+1, which equals 255.

Let’s take a look at our other example, which is 01100100.

 Binary: 0 1 1 0 0 1 0 0 Decimal: 128 64 32 16 8 4 2 1

Remember, we need to sum up decimal values which have 1 in the binary representation. So in this case we have to sum 64+32+4, which equals 100. To be more accurate, we actually add zero wherever there’s a zero in the binary form. So we actually add 0+64+32+0+0+4+0+0, which equals 100 again.

Let’s take another example, 10000011 and convert this binary number to decimal.

 Binary: 1 0 0 0 0 0 1 1 Decimal: 128 64 32 16 8 4 2 1

Again, every time we have a 1 in binary, we take the decimal equivalent. In this case that is 128+0+0+0+0+0+2+1, or simply 128+2+1, which equals 131.

#### Decimal to Binary Conversion

To convert from decimal to binary, the process is in reverse. We start with the number as a possible value and working from the left we check if the numbers fit within the decimal value that we have. Let’s look at an example of 100 in decimal, which we want to convert to binary.

 Number: 100 Decimal: 128 64 32 16 8 4 2 1 Binary:

First step is to check if 128 fits in 100. It doesn’t, so we put 0 in that position.

 Number: 100 Decimal: 128 64 32 16 8 4 2 1 Binary: 0

Then we check if 64 fits in 100. It does, so we put 1 in that position. We also have to subtract 64 from 100, which is 36. Now we work with 36.

 Number: 100-64=36 Decimal: 128 64 32 16 8 4 2 1 Binary: 0 1

Next, we check if 32 fits in 36. It does, so we put 1 in that position. We also subtract 32 from 36, which is 4. Now we work with 4.

 Number: 100-64=36, 36-32=4 Decimal: 128 64 32 16 8 4 2 1 Binary: 0 1 1

Next, we check if 16 fits in 4. It doesn’t, so we put zero in that position. The same thing is with 8. We still work with number 4.

 Number: 100-64=36, 36-32=4 Decimal: 128 64 32 16 8 4 2 1 Binary: 0 1 1 0 0

Next, 4 fits in 4, so we put 1 in that position. We also have to subtract 4 from 4, which is zero.

 Number: 100-64=36, 36-32=4, 4-4=0 Decimal: 128 64 32 16 8 4 2 1 Binary: 0 1 1 0 0 1

Since now we work with zero, there is no chance that any number will fit it anymore. Therefore, we can write zeros in all remaining positions.

 Number: 100-64=36, 36-32=4, 4-4=0 Decimal: 128 64 32 16 8 4 2 1 Binary: 0 1 1 0 0 1 0 0

So, the decimal 100 is the 01100100 in binary.

 IP address: 150 150 100 100 Subnet Mask: 255 255 0 0

The thing is, wherever we see 255 we know that that particular octet is part of the network (subnet) address. So in our example, the subnet address is 150.150.0.0, while the host address is 100.100. We can have multiple hosts on the same subnet, and each host has to have a different host address. All hosts on the same subnet would share the same subnet address and would have unique host addresses.

Let’s say that we modify the Subnet Mask to include 255 in the third octet.

 IP address: 150 150 100 100 Subnet Mask: 255 255 255 0

To configure a network device, supplying just the IP address is not enough. The device needs to know which part of the address identifies the network (subnet) and which part identifies the host. For this reason we will typically supply the subnet mask in addition to the IP address.

IP addresses have what is called a default subnet mask, which is identified by the address class. IP addresses are divided into classes, each class having a default IP subnet mask. There are five IP address classes: A, B, C, D, and E. The IP addresses that fall into each class is identified by looking at the first octet in an IP address. So, to find the IP address class we simply look at the number in the first octet. The remaining numbers can be ignored for the purpose of identifying the address class.

#### Class A

Class A address in the first octet has a value between one 1 and 126. The default Subnet Mask associated with class A is 255.0.0.0. There are only 126 Class A network IDs. Each class A address gives us 16777214 hosts per network.

#### Class B

Class B address has a value of 128 to 191. It’s subnet mask is 255.255.0.0. There are 16384 Class B network IDs. Each class B address gives us 65534 hosts per network.

#### Class C

A class C address begins at 192 and goes up to 223, and it’s default Subnet Mask is 255.255.255.0. There are 2097152 Class C network IDs. Each class C address gives us 254 hosts per network.

#### Class D and E

These classes are used for special addresses, so they are not used to assign to hosts. They also don’t have a default subnet mask. Still, they have an address range. Class D addresses are between 224 and 239, and class E is 240 to 255. Class D addresses are what are called Multicast addresses. A Multicast address identifies multiple computers rather than a single host. Hosts may have multicast addresses assigned to them, but they will not be used for normal communication, since every host has to have a unique host IP address. Class E addresses are experimental.

Let’s do the same thing with the IP address 150.150.100.100. The class is B, since the number in first Octet lies between 128 and 191. The default Subnet Mask for class B addresses is 255.255.0.0. Because of the Subnet Mask, we know that the network address is 150.150.0.0, and the host address is 100.100.

#### Classes in Binary

If we take the first octet and convert it into binary, a class A address always begins with a zero and is followed by seven additional values (00000001-01111110), last value being 0 (to get 126, and not 127). A class B address begins with a 1 followed by a zero, followed by six additional characters (10000000-10111111). Class C address begins with two 1, followed by a zero, and then five additional characters (11000000–11011111). So if we can’t remember decimal boundaries between classes, we can remember the binary equivalent and then convert those to the decimal. It might be easier, or it might be easier to try to remember these ranges.

Let’s take another example, on IP address 150.150.100.100. This is class B address since the first Octet falls between 128 and 192. The subnet Mask is 255.255.0.0, so the network address is 150.150.0.0. Now we need to fill both host Octets with ones on a binary level, giving us 255.255 in decimal. The whole Broadcast address is then 150.150.255.255. Just like the network address we can not assign the Broadcast address to a host.

In the case of 200.150.100.0 network address, the possible values that we can assign to hosts on that network would be from 200.150.100.1 up to 200.150.100.254. Remember that we cannot assign the first address or the last address to hosts. In the case of class B network address 150.150.0.0, the host range would be 150.150.0.1 all the way up to 150.150.255.254.

### Subnetting

Subnetting is the process of dividing a large network into smaller networks. When we subnet a network, each network segment (called a subnet) has a different network address (also called a subnet address). In practice, the terms network and subnet are used interchangeably to describe a physical network segment with a unique network address. From a physical standpoint, subnetting is necessary because all network architectures have a limit on the number of hosts allowed on a single network segment. As our network grows, we will need to create subnets (physical networks) to increase the number of devices that can be added to the LAN (to overcome the architecture limits), to reduce the number of devices on a single subnet so that we reduce congestion and collisions, to reduce the processing load placed on computers and routers or to combine networks with different media types within the same internetwork (subnets can not be used to combine networks of different media type on to the same subnet).

#### Public vs Private IPv4 Addresses

Addresses which are used on the Internet are public addresses. Public addresses can be routed on IP networks. Private addresses can only be used in private networks, like our home or company network. Hosts on the private network do not use the public address in local communication. Public address is only used in communication with the public network like the Internet. This is usually implemented by using the Network Address Translation service (NAT), which enables us to use one public IP address and share it with all hosts on our private network when they need to communicate on the public network.

There are four private address ranges that are reserved by IANA for the purpose of private addressing. The ranges are:

• 10.0.0.0 /8
• 172.16.0.0 /12 to 172.31.255.255 /12
• 192.168.0.0 /16
• 169.254.0.0 /16 – this is used for Automatic Private IP Addressing (APIPA) feature in Windows. This range should not be used manually. This range is used automatically if our hosts can’t get an IP address from the DHCP server.