Every device on the internet needs a logical address so that packets can find it across many networks. The Internet Protocol provides this.
The TCP/IP Protocol Suite
The TCP/IP suite is the family of protocols used on the internet. At the internet layer: IP (addressing and routing), ICMP (error reporting and diagnostics, used by ping and traceroute), ARP (finding MAC addresses) and IGMP (multicast groups). At the transport layer: TCP and UDP. At the application layer: HTTP, DNS, DHCP (automatic address assignment), SMTP, FTP and many more. IP is connectionless and best-effort: each packet is routed independently, with no guarantee of delivery or order, which TCP adds if needed.
Definition: IP address. A logical address assigned to a network interface, 32 bits long in IPv4 and 128 bits long in IPv6, which identifies both the network and the host so that packets can be routed to it.
IPv4 Addresses
An IPv4 address is 32 bits, written in dotted-decimal notation as four octets, such as 192.168.10.25. It has a network part and a host part. In the old classful scheme: Class A (first octet 1–126, default mask 255.0.0.0, /8), Class B (128–191, 255.255.0.0, /16), Class C (192–223, 255.255.255.0, /24), Class D (224–239, multicast) and Class E (240–255, reserved). 127.0.0.0/8 is the loopback range (127.0.0.1 is "this computer"). Private addresses, used inside organisations and not routed on the internet, are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. In each network, the first address (all host bits 0) is the network address and the last (all host bits 1) is the broadcast address. IPv4 provides about 4.3 billion addresses, which have run out, a problem eased by NAT and solved by IPv6.
IPv6 Addresses
An IPv6 address is 128 bits, giving about 3.4 × 10³⁸ addresses. It is written as eight groups of four hexadecimal digits separated by colons, such as 2001:0db8:0000:0000:0000:ff00:0042:8329. Leading zeros in a group may be dropped, and one run of all-zero groups may be replaced by ::, giving 2001:db8::ff00:42:8329. Types are unicast, multicast and anycast (delivered to the nearest of a group); there is no broadcast. ::1 is the loopback, and fe80::/10 is link-local. IPv6 has a simpler fixed 40-byte header, stateless address autoconfiguration (SLAAC), built-in support for IPsec, no fragmentation by routers, and better support for mobile and IoT devices. IPv4 and IPv6 coexist through dual stack, tunnelling and translation.
Table 2.5: IPv4 and IPv6
| Feature | IPv4 | IPv6 |
|---|---|---|
| Length | 32 bits | 128 bits |
| Notation | Dotted decimal | Hexadecimal with colons |
| Addresses | About 4.3 × 10⁹ | About 3.4 × 10³⁸ |
| Header | 20–60 bytes, with checksum | 40 bytes, no checksum |
| Broadcast | Yes | No (multicast instead) |
| Configuration | Manual or DHCP | SLAAC or DHCPv6 |
Example 2.5: Classifying addresses
Problem: For each address, give the class and whether it is private: (a) 10.4.5.6, (b) 172.20.1.1, (c) 192.168.1.100, (d) 8.8.8.8. Shorten the IPv6 address 2001:0db8:0000:0000:0000:0000:0000:0001.
Solution:
- 10.4.5.6: class A, private (10.0.0.0/8).
- 172.20.1.1: class B, private (172.16.0.0/12).
- 192.168.1.100: class C, private.
- 8.8.8.8: class A, public.
- Drop leading zeros and replace the run of zero groups with ::: 2001:db8::1.
Result: (a)–(c) private, (d) public; the IPv6 address is 2001:db8::1.
import ipaddress
for a in ["10.4.5.6", "172.20.1.1", "192.168.1.100", "8.8.8.8",
"127.0.0.1"]:
ip = ipaddress.ip_address(a)
first = int(a.split(".")[0])
cls = "A" if first < 128 else "B" if first < 192 else "C"
print(f"{a:<14} class {cls} private={ip.is_private} "
f"loopback={ip.is_loopback}")
v6 = ipaddress.ip_address("2001:0db8:0000:0000:0000:0000:0000:0001")
print("IPv6 short form:", v6.compressed, "| bits:", v6.max_prefixlen)
Output
10.4.5.6 class A private=True loopback=False
172.20.1.1 class B private=True loopback=False
192.168.1.100 class C private=True loopback=False
8.8.8.8 class A private=False loopback=False
127.0.0.1 class A private=True loopback=True
IPv6 short form: 2001:db8::1 | bits: 128
Common mistakes
- Using :: twice in one IPv6 address, which makes it ambiguous.
- Assigning the network or broadcast address to a host.
- Thinking private addresses can be reached directly from the internet.
Key takeaways
- IP is connectionless, best-effort and handles addressing and routing.
- IPv4: 32 bits, dotted decimal; private ranges 10/8, 172.16/12, 192.168/16.
- IPv6: 128 bits, hexadecimal, :: for one run of zeros, no broadcast.
- The first address of a network is the network address; the last is broadcast.
Practice questions
- How many bits are in an IPv6 address?
- Name the three private IPv4 ranges.
- What is the IPv4 loopback address?
Answers to the practice questions
-
- 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.
- 127.0.0.1.
Sources
- Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit II
