This post explains briefly the network protocol IPv4 and summarizes the main aspects of it.
IPv4 Address
An IPv4 address represents a single device on an IP network.
An IPv4 address consist of 32 bits. Example: 11000110001100110110010000000000
These 32 bits are usually divided in 4 octets, and separated with a dot. Example: 11000110.00110011.01100100.00000000
In order to make them more familiar to humans, these 4 octets are usually represented using decimal notation. Example: 198.51.100.0
Networks, Hosts and Subnet Masks
The 32 binary bits are broken down into the network and host sections:
- Network number / routing prefix: identify a network (for example, University of Salamanca).
- Host identifier: identify a host inside a network (for example, Juan Garcia’s laptop at University of Salamanca).
Subnet mask or net mask is used to identify which part of an IPv4 address belongs to a network. The subnet mask can be represented in different ways:
- In Classless Inter-Domain Routing (CIDR) representation, a decimal number placed at the end of the IP address represents the number of bits reserved for the network. This decimal number is written after a slash (/) at the end of IPv4 address. Example: 172.18.230.127/29
- As 32-bit number, where 1 is written for each position that belongs to the network. Example: 11111111.11111111.11111111.11111000. The subnet mask is usually represented with decimal octets in the same way as an IPv4 address: 255.255.255.248. Executing AND operator on the original IPv4 address and submask gives the first value for the network.
If the submask size is not specified, then it would use a default submask. The default submask differs depending on the IPv4 address class where they belong to. See the IPv4 address class for further information.
The wildcard would be the oppositve of the submask, it means, it is used to identify which part of an IPv4 belongs to a host.
Example: 173.18.230.127/29, the mask is 00000000.00000000.00000000.00000111
The first address available within a subnet is the Network Address. It means, it does not represent a host but the network itself. It may be informed along with the subnet mask. The network address is the result of applying the AND operator to the IPv4 address and the submask.
The last address in a subnet is the Broadcast Address. It represents all of the hosts inside that network, and is used to communicate to all hosts within it.
The addresses between network address and broadcast address are the host addresses.
You can calculate these address using some webs like ipcalc.
Example:
Ipv4 address: 173.18.230.125/29
Subnet mask: 255.255.255.248
Wildcard: 0.0.0.7
Network address: 173.18.230.120/29
Broadcast address: 173.18.230.127
Host addresses: 173.18.230.121 – 173.18.230.126
A default gateway is a device on a TCP/IP network, usually a router, which forwards IP packets to other subnets.
In most cases, you can use a Dynamic Host Configuration Protocol (DHCP) server to assign the default gateway automatically to a DHCP client. This approach is more straightforward than manually assigning a default gateway on each host.
IPv4 Address Classes
Internet has networks with many different sizes. Some of them contains thousands of devices, and some other just a couple of them. IPv4 offers an addressing scheme with different address classes, that represent network with different sizes, and optimize the use of addresses.
Without IPv4 Address Classes, smaller networks would cope thousands of unused host IPs. This is why different IPv4 address classes are used.
The IPv4 Address Class can be identified just by inspecting the 8 first bits in the IPv4 address:
- Class A Address: 1.x.x.x – 127.x.x.x
- Class B Address: 128.x.x.x – 191.x.x.x
- Class C Address: 192.x.x.x – 223.x.x.x
- Class D Address: 224.x.x.x – 239.x.x.x
- Class E Address: 240.x.x.x – 255.x.x.x
127.0.0.1 is the loopback address.
APIPA is a OSI layer 3 (network) protocol that only exists on Microsoft Windows OS and that is activated in the absence of a DHCP server. When the server is not found, an APIPA address is self-assigned within the range 169.254.0.1-169.254.255.254.
IPv4 Private Addresses
The Internet Assigned Numbers Authority (IANA) assigns some addresses ranges to public networks and some other to private.
Private addresses are define through the RFC 1918 document “Address Allocation for Private Internets“.
Address ranges to be use by private networks are:
- Class A: 10.0.0.0 – 10.255.255.255
- Class B: 172.16.0.0 – 172.31.255.255
- Class C: 192.168.0.0 – 192.168.255.255
An IP address within private ranges is therefore considered non-routable from any external networks, as it is not unique. Any private network that needs to use IP addresses internally can use any address within these ranges without any coordination with IANA or an Internet registry. Addresses within this private address space are only unique within a given private network.
All addresses outside private ranges are considered public.
Class A Address
Default subnet mask: 255.0.0.0
Private network address range: 10.0.0.0 – 10.255.255.255
Class B Address
Default subnet mask: 255.255.0.0
Private network address range: 172.16.0.0 – 172.31.255.255
Class C Address
Default subnet mask: 255.255.255.0
Address range: 192.x.x.x – 223.x.x.x
Private network address range: 192.168.0.0 – 192.168.255.255
Class D Address
This class is reserved for multicast.
Not equipped with any submask.
Class E Address
This class is reserved for experimental purposes only for R&D or Study by the Internet Engineering Task Force IETF.
Not equipped with any submask.
IPv4 Header
The header contains between 20 and 60 bytes.
40 options bytes are part dedicated to the options. The first 20 bytes are
Each “row” has 32 bits.
The 40
Each 32 bits
IPv4 header contains:
- 1st row
- Version
- Header Length
- Type-of-Service (ToS)
- Total Length
- 3rd row
- Time-to-live (TTL)
- 4 row
- IP Source
- 5th row
- IP Destination
- Protocol
- Fragment Offset
Version has 4 bits.
Header Length indicates the varialble part of the options.
Type of Service (ToS) has 8 bits. This header was never used for its original service. However, it has been reused for DSCP, that is about quality of service.
There are two DSCP modes: DiffServ and IntServer.
Time-to-Live (TTL) is an 8-bit binary value that indicates the remaining “life” of the packet. The TTL value is decreased by at least one each time the packet is processed by a router (that is, each hop). When the value becomes zero, the router discards or drops the packet and it is removed from the network data flow. This mechanism prevents packets that cannot reach their destination from being forwarded indefinitely between routers in a routing loop.
The Maximum Transmission Unit (MTU) is a value set by the transmission link, and defines the maximum size of a datagram.
IPv4 features a Don’t Fragment (DF) bit.
You might be also interested in…
References
- “IPv4: Addresses classes“; TutorialsPoint
- “Subnet mask“; AVI Networks
- “Subnetwork“; Wikipedia.org
- “Private Address Ranges“; IBM
- “Explore IPv4 Settings“, Microsoft
[…] IPv4 […]