In this post I will continue talking about the Internet Protocol address and all the items related to it. Also we will play with some conversion examples.
As you already know, IP addresses are layer3 addresses used by devices to communicate over the network and to uniquely identify machines. Humans are used to write numbers in decimal format, but computers and all networking devices communicate using the binary format ( 0 and 1). I will give you an example:
It is easier to write and understand an IPv4 like 10.0.0.1 than 00001010.00000000.00000000.0000001. We use the dot sign to separate each octet(group of 8 bits) in a IPv4 address, if you would look at the IP address when is transmitted over the medium, you will only see a flow of 0 and 1’s.
Each bit represents a different value, that’s because each position actually is a value of 2 to the power of the position. It doesn’t sound so good, that’s why I’m going to give you an example: let’s take the first 10 from our example written in binary 00001010. From right to left (or from the least significant bit to the most significant bit http://en.wikipedia.org/wiki/Least_significant_bit ) the positions represent different value. So at position 0 the value is 2 at the power of 0, that equals 1; at position 1 the value is 2 at the power of 1, equals 2 and so on.
From left to right these are the values:
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
These numbers will help you convert numbers from 10 format to binary format and which is the first step in subnetting. Now let’s take the following example:
let’s convert the following IP address 192.168.0.0 into binary format: 110000.10101000.00000000.00000000
What is important to remember is that when 1 is encountered means that position is used and when 0 is encountered than that position has value 0
I will explain how I converted into binary each octet:
11000000 – we have the value of 1 on the first two positions from the left which means that we have to add values only for those two: the first position represents the value of 2^7=128 and the second 2^6=64. If we add them the result will be 192.
10101000 – We have 1 values in the positions 7 5 and 3 so our numbers are 2^7=128, 2^5=32 and 2^3=8. If we add the values 128+32+8 the result is our number 168
This is the revert thinking when converting in binary. The easiest way is just to subtract the 2^X from your number until you reach 0. For example let’s take 172:
First let’s test the first position 172-128=44, if we have a positive number than we have a 1 on that position.
Now 44-64=-20, we have a negative number so the value on that position is 0. I will only do the math:
44-32=12 value 1
12-16=-4 value 0
12-8=4 value 1
4-4=0 value 1
and the rest until the 8’th bit are 0. Our number is written like this 10101100
You’ll have to memorize the value of each position, but in time you will convert numbers very easy.
When IPv4 was implemented, three types of addresses were invented:
The network address – this is used to identify the network.
The broadcast address – is is the last address in a subnet, it is used by many protocols and applications to send one message to all devices in the network.
The host address – are addresses used by devices inside a network. A host cannot use the network or the broadcast address.
Now let’s take the next example:
192.168.5.0 with a 255.255.255.0 or /24 mask – this is the network address.
192.168.5.255 is the broadcast address.
192.168.1-254 – host addresses
But how did I end up with this numbers?
Well, we first have to talk about the network mask or the prefix. Well this parameter is used to interpret a network address, it is used to divide the network portion form the host portion. In our example, we used a /24 or 255.255.255.0 mask. By the way /24 prefix reference to how many 1 bits are set in the mask so
/24 = 255.255.255.0 = 11111111.11111111.11111111.00000000. Personally, I prefer to use the prefix form because it helps me understand better where is the demarcation point between the network and the host portion. In our example, the mask tells us that the first 24 bits from the IP address are reserved for the network portion and the last 8 bits for the host portion. We are calculating only in the host portion, so:
the network address is calculated by setting all the host bits 0 which means that 192.168.5.00000000 or 192.168.5.0 is our network portion
the broadcast address is calculated by setting all the host bits 1 which means that 192.168.5.11111111 or 192.168.5.255 is our broadcast address
the hosts addresses are between the network and the broadcast address, which in our case are from 192.168.5.00000001 to 192.168.5.11111110 or 192.168.5.1 to 192.168.5.254.
When using the IP protocol, device can communicate with each other in three ways:
Unicast – a host sends a packet to a single host
Broadcast – a host sends a packet to all devices in the network. A broadcast domain is limited by a router ( layer3 device).
Multicast – a host sends a packet to a group of devices.
IPv4 address ranges:
There are three main IPv4 address ranges:
Host addresses 0.0.0.0 to 220.127.116.11 – used to be assigned to hosts
Multicast addresses 18.104.22.168 to 239.555.555.555 – used to be assigned to multicast groups
Experimental addresses 240.0.0.0 to 255.255.255.254 – used by developing companies for future reservation and research
The addresses from above are also called public addresses and are visible from the internet. There are also some private IP ranges, these are called private because they only exist inside a network and are not visible from outside:
10.0.0.0 10.255.255.255 with 255.0.0.0 mask or /8
172.16.0.0 172.31.255.255 with 255.240.0.0 mask or /12
192.168.0.0 192.168.255.255 with 255.255.0.0 mask or /16
There are also some special IPv4 that are reserved:
Loopback address – this is used by devices to redirect traffic to themselves. 127.0.0.1
Default route – which is the default route used by routers to forward packets when no other matches the destination IP. 0.0.0.0 and mask 0.0.0.0
Link-local address – used to allocate address 169.254.0.0 169.254.255.255
An older implementation of IPv4, divided IPs in 5 classes:
A 1-127 with mask 255.0.0.0 or /8
B 128-191 with mask 255.255.0.0 or /16
C 192-223 with mask 255.255.255.0 or /24
D 224-239 reserved for multicast
E 240-255 experimental address