Skip to main content

IPv4 Addressing

This page provides introduction to IPv4 Addressing.

Overview

Layer 22 uses MAC addresses, which are assigned to a device during manufacturing. At layer 33, IP addresses serve as logical addresses that are assigned during device configuration. Routers operate at layer 33.

In diagram below we have 11 network connected by switches.


computer-network-3.svg


Let's say if we add a router between Switch 11 and Switch 22, the PCs will be split into two separate networks instead of being part of a single network.

Two networks are:

  • Network 11: 192.168.1.0/24192.168.1.0/24
  • Network 22: 192.168.2.0/24192.168.2.0/24

computer-network-4.svg

In both networks, the /24/24 subnet mask indicates which part of the IP address is used for the network ID and which part is used for the host ID. Since each octet consists of 88 bits, the first three octets (192.168.X.192.168.\text{X}.) represent the network ID, while the last octet is used for the host ID.

IPv4 Address Classes

IPv4 addresses are 3232 bits long.

For example, in 12.128.251.23/812.128.251.23/8, each group (octet) consists of 88 bits, and the /8/8 at the end of the IP address indicates that the first 88 bits are used for network addressing, while the last three octets are used for host addressing.

This notation is also called the prefix length, and based on it, IPv4 addresses are divided into five different classes, as shown below:

ClassFirst OctetFirst Octet Numberic RangePrefix LengthNumber of NetworksAddresses Per Network
A0001270-127/8/8272^{7}2242^{24}
B1010128191128-191/16/162142^{14}2162^{16}
C110110192223192-223/24/242212^{21}282^{8}
D11101110224239224-239N/AN/AN/A
E1111011110240255240-255N/AN/AN/A
info

Addresses in Class D are reserved for multicast and are different from unicast and broadcast addresses. Class E addresses are reserved for experimental use.

In each network, the first address is reserved as the network address, and the last address is the broadcast address. Therefore, the number of usable host addresses per network is reduced by two.

On Juniper network devices, the prefix length is written using slash notation, as shown in the table above. However, Cisco devices still use the older method of specifying the prefix length with a subnet mask.

For example, the subnet masks for different classes are:

  • Class A addresses: 255.0.0.0255.0.0.0
  • Class B addresses: 255.255.0.0255.255.0.0
  • Class C addresses: 255.255.255.0255.255.255.0

Private IP Address Ranges

The Internet Assigned Numbers Authority (IANA) defines the following as:

  • 10.0.0.010.0.0.0 to 10.255.255.25510.255.255.255 (Class A).
  • 172.16.0.0172.16.0.0 to 172.31.255.255172.31.255.255 (Class B).
  • 192.168.0.0192.168.0.0 to 192.168.255192.168.255 (Class B).

Loopback Address

The end of the Class A range is usually considered to be 01260-126 because the 127127 range is reserved for loopback addresses. The addresses from 127.0.0.1127.0.0.1 to 127.255.255.255127.255.255.255 are designated for the network stack on the local device.

IPv4 Header

Below are the Protocol Data Units (PDUs) created at each level of the OSI model:

  • The upper layers of the OSI model prepare data for transmission across the network.
  • A Segment consists of Data + Layer 4 (L4) header.
  • A Packet consists of Data + L4 header + Layer 3 (L3) header.
  • A Frame consists of Layer 2 (L2) trailer + Data + L4 header + L3 header + L2 header.

Let's understand the IPv4 header, which is responsible for generating a packet.

  • Version field:

    • It is 44 bits in length.
    • Identifies version of IP used.
  • IHL field

    • It is 44 bits in length.
    • Indicates length of IPV44 header.
  • DSCP field

    • It is 66 bits in length.
    • This field is used for Quality of Service. (For example prioritising delay sensitive data).
  • ECN field

    • It is 22 bits in length.
    • Provides end to end notification of network congestion without dropping packets.
  • Total length field

    • It is 1616 bits in length.
    • Indicates the total length of the packet.
    • Max length of IPv4 packet is 6553565535.
  • Identification field

    • It is 1616 bits in length.
    • If packet is fragmented due to being too large, this field is used to identify which packet the fragment belongs to.
    • All fragements of the same packet will have same value in this field.
    • Packets are fragemented if it is larger than MTU.
    • MTU is usually 15001500 bytes long.
    • Fragments are reassembled by the receiving host.
  • Flags

    • It is 33 bits in length.
    • Used to control and identify fragments.
    • Bit 00 is reserved and always 00.
    • Bit 11 is don't fragment bit, used to indicate if packet should be fragmented.
    • Bit 22 is more fragment bit which is set to 11 if there are more fragment in packet or else set to 00 if it is last packet in the fragment.
  • Fragment Offset

    • It is 1313 bits in length.
    • Used to indicate position of fragment within the original packet.
  • TTL

    • It is 88 bits in length.
    • Router will drop a packet with a TTL of 00.
    • Used to prevent infinte loops.
  • Protocol

    • It is 88 bits in length.
    • Indicate the protocol of encapsulated L44 PDU.
    • Value of 66 is TCP.
    • Value of 1717 is UDP.
    • Value of 11 is ICMP(Ping).
    • Value of 8989 is OSPF(Dynamic Rounting Protocol).
  • Header Checksum

    • It is 1616 bits in length.
    • A calculated checksum used to check for erros in IPV44 header.
  • Source IP Address

    • It is 3232 bits in length.
    • It is IPv4 address of sender.
  • Destination IP Address

    • It is 3232 bits in length.
    • It is IPv4 address of receiver.
  • Options

    • It is optional field which can have any size between 00 to 320320 bits.
    • If IHL field is greater than 55, it means options are present.

Summary

PC11 has an IP address of 43.109.23.12/843.109.23.12/8

  • Network address of PC11 is 43.0.0.043.0.0.0.
  • Maximum number of hosts in the network is 22422^{24} - 2.
  • Network broadcast address is 43.255.255.25543.255.255.255.
  • First usable address of network is 43.0.0.143.0.0.1.
  • Last usable address of network is 43.255.255.25443.255.255.254.