Internet Protocol (IP) addresses contain a host part and a network part. They are used to identify a device on any network.
The IP address is 4B long and each byte is seperated with a .
(period).
IPv4 addresses were classified into 5 classes based on the first byte as follows:
Class | 1st Byte (MSB) | Format | Description (Not that important, ignore) |
---|---|---|---|
A | 1 - 127 | N.H.H.H | Very early. Was reserved for DoD |
B | 128 - 191 | N.N.H.H | Large sites, were hard to get |
C | 192 - 223 | N.N.N.H | Were easy to get. |
D | 224 - 239 | - | Multicast addresses, which were not permanently assigned |
E | 240 - 255 | - | Experimental addresses |
The host and network portions can be specified explicitly using a subnet mask or netmask. A net mask is writted as /xx
at the end of an address.
Related: CIDR
Example
Consider an IP address: 128.138.243.0/26
. For this IP address, the network part is 26 bits long and the remaining 6 bits are used to identify the host.
As the host part can have 6 bits, there can be a total of
Our netmask here will be
1111 1111 . 1111 1111 . 1111 1111 . 1100 0000
As it is 26 bits, we also have 2 extra bits after the end of the 3rd byte. By modifying these two bits to have values 00, 01, 10, 11
we can split the network into 4 sub networks, each with 6 host bits:
128.138.243.0/26
128.138.243.64/26
128.138.243.128/26
128.138.243.192/26
The last byte will be a multiple of the number of hosts on each network, which in our case is 64.
A /31 address does not have a broadcast and a network address. Both of its addresses are used for hosts.
A physical network can still have multiple logical network, each uniquely identified with its network portion of the IP.
A unicast address is sent out to only one destination IP address.
A broadcast packet is sent to all the devices on the logical network including the route but not the sender itself. The router does not forward this packet (by default). Broadcast packets are sent to the special reserved broadcast address: 255.255.255.255
.
A packet can be sent to a number of selective devices that are subscribed to the multicast group. Multicast addresses for IPv4 are limited in the range (both inclusive) from 224.0.0.0
to 239.255.255.255
.
Some IP addresses are not routable through the internet. These are called private IP addresses. When a packet leaves a local network with its source address being a private IP, NAT is used to translate the private IP into a routable public IP.
The ranges for private IP addreses are:
10.0.0.0/8
172.16.0.0/16
192.168.0.0/24
There are some IPs that cannot be assigned to hosts as they are reserved for some special purpose. Some IPs are special and can be assigned to hosts with some restrictions.
127.0.0.0/8
(commonly referred to as 127.0.0.1
) are loopback addresses. They are used by the host to connect and send data to itself.
Link local addresses are self assigned IP addresses in the case when a client is not assigned one. Seems to be a Windows thing. Research required.
Public IP(v4 and v6) are managed by Internet Assigned Numbers Authority (IANA) which assigns blocks of IPs to Regional Internet Registries (RIR). There are 5 RIRs in total. The RIRs are then responsible for giving these IPs to ISPs.
IPv6 addresses are 128 bits or 16 bytes long. They are represented as 8 groups of 16 bits each, seperated by a :
. These addresses do not have a netmask. The network and host parts are just left and right halves. In a way, its like it has a fixed netmask of 64.