Ipv4 Datagram header
Datagram : is a unit of data transfer in packet-switched network, containing header and the payload.
The Internet Protocol (IP) header contains fields to manage the logical addressing and forwarding function. The IP header contains two field for 32 bit source and destination addresses, plus other fields to support forwarding functions.

Image refrence: https://en.wikipedia.org/wiki/IPv4
Some network layer protocols run directly on IP. These IP protocol types include the following:
- Internet Control Message Protocol (ICMP/1) is used for status messaging and connectivity testing.
- Internet Control Message Protocol (ICMP/2) is used with multicasting
- Generic Routing Encapsulation (GRE/47) is used to tunnel packets across an intermediate network.
- This is used in some virtual private network implementation
- Encapsulating Security Payload (ESP/50) and Authentication Header (AH/51) are used with the encrypted form of IP(IPSec)
- Enhanced Interior Gateway Routing Protocol(EIGRP/88) and Open Shortest Path First(OSPF/89) are protocols used by routers to exchange information about the paths to the remote networks.
Layer 2 vs. Layer 3 Addressing and Forwarding
- The packets forwarding at layer 3 is called routing. Router functions at layer 3 and uses the IP address to forward the packets from one host or network to another.
- Switches functions at layer 2, switches use the MAC or media access control address to forward the frames. In switch each port acts as a single broadcast domain, switches uses the inbuilt MAC table to forward the frames to each ports according to the table. The process of forwarding these frames is called switching at layer 2.
- When there are multiple subnets in the network routers are needed to create the communication between these subnets, as switch functions at layer 2, subnets or the IP address falls under layer 3 and in order to communicate with these subnets layer3 (router) device is needed
Address Resolution Protocol
Address Resolution protocol is the TCP protocol which is used to translate layer 3 Ip address to layer 2 MAC address, The layer 2 MAC address is also known as physical address, which is unique to each devices.
When a host or the node in a network needs to establish a connection with an IP address that is with in the same network an ARP request is generated. When an ARP request is sent the host broadcast the IP address with in the network, ARP is a broadcast request and each host with in the broadcast domain receives this request. When the ARP request is received by the host in the network with the IP address, it responds with its mac address, the rest of the hosts discard the ARP request.
The use of ARP request is to match the IP address with the MAC address, here the initiator asks who have this IP address and the host with that IP address responds to the request with its MAC address.
ARP request is a broadcast, but the ARP response is unicast.
Unicast and Broadcast Addressing
Unicast:
When a host in the network needs to send a packet to a single Node in the network the method of communication is Unicast. The host uses unicast packet to the IP address of the receiving host as a destination address. Unicast can be at layer 2 or layer 3 this depends upon the type of communication, when the host is using an IP address to create a communication it uses layer 3, similarly if the host uses layer 2 address (MAC) then the communication will be layer 2.
BroadCast:
When a single host is communicating to all the host with in the network or the same broadcast domain the communication is broadcast. When using an IP address the very last IP address within the network is called broadcast address. Similar to unicast broadcast also functions as both layers 2 and 3 depending upon the type of the communication. At layer 3 all the hosts in the same network receives the broadcast traffic, however when layer 2 broadcast is send all the devices with in the same broadcast domain or the devices in the same VLAN receives the broadcast traffic.
Layer 2 broadcast address is by default sent with the destination mac address ff.ff.ff.ff.ff.ff, this means all the devices. In general if the switch is not configured with VLAN, broadcast traffic is forwarded to all the ports except the port that the broadcast has received. In presence of VLAN broadcast traffic is only send to the same VLAN. Similar to VLAN the broadcast traffic is also blocked by the routers.
Multicast and Anycast Addressing
Multicast:
The method of transmitting data from one host to many hosts over a network is called Multicast. Unlike broadcast multicast is not sent to all the hosts with in the network, multicast traffic is only sent to the hosts if they are interested in receiving the traffic. Internet group management protocol (IGMP) is typically used to configure group memberships and IP addresses. In IPv4 224.0.0.0 to 239.255.255.255 is reserved for multicast addressing.
- media streaming is a good example of multicast
Anycast:
When a group of hosts in a network share the same IP address it is called as anycast. When the packet is forwarded to the anycast group the metric, priority or algorithm is used to identify which host will receive the anycast traffic. Anycast is mostly used for load balancing and failover between the server hosts sharing the IP address.
IPv4 Address Format
- An Ipv4 address is 32 bits long, containing network portion and the host portion.
Network Masks
In binary 1 in the mask the corresponding binary digit in the IPv4 address is part of the network ID. The 1s in the mask are always contiguous.
eg: 11111111.11111111.11111111.00000000
In decimal: 255.255.255.0
Network masks can also be written as slash notation.
Subnet Masks
The subnet mask contains:
- network Id
- subnet id
- host Id
The purpose of subnetting is to create layer 3 broadcast domain segments with fewer hosts. The trick with subnet design is to fit the scheme to the requiements for number of subnetworks and number of hosts per subnet. Each bit added to the mask approximately halves the number of available host addresses.
reference: Comptia network plus(certmaster)