IP Addressing & Subnetting Notes (Detailed)
1. IPv4 and IPv6 Basics
IPv4 VS IPv6 Comperision
IPv4
What is IPv4? IPv4 (Internet Protocol version 4) is like a unique address for devices (computers, phones, routers) to communicate on a network, similar to a phone number for a person.
- Format: Four numbers separated by dots, e.g.,
192.168.1.1
. Each number (octet) is 0–255.
- Size: Uses 32 bits (4 bytes, each octet is 8 bits). This allows ~4.3 billion unique addresses (2³²).
- Structure: Divided into Network ID (identifies the network) and Host ID (identifies the device).
- Problem: Limited addresses due to the growth of devices (phones, IoT, etc.), leading to address exhaustion.
- Solution: NAT (Network Address Translation) lets multiple devices share one public IP, and IPv6 provides more addresses.
Example: IP 192.168.1.1
is like a home address for a device in a local network, used for unicast communication.
Interview Tip: Explain that IPv4 is widely used but running out of addresses. Mention NAT and IPv6 as solutions.
IPv6
What is IPv6? IPv6 (Internet Protocol version 6) is a newer version with a much larger address space to support the growing number of devices.
- Format: Eight groups of hexadecimal digits (0–9, a–f) separated by colons, e.g.,
2001:0db8:85a3:0000:0000:8a2e:0370:7334
. Can shorten zeros, e.g., 2001:db8::8a2e:370:7334
.
- Size: Uses 128 bits, allowing ~340 undecillion addresses (2¹²⁸).
- Advantages:
- Huge address space, no need for NAT.
- Simpler header for faster routing.
- Built-in security (IPsec) and autoconfiguration for devices.
- Transition: IPv6 is used alongside IPv4 because not all systems support it yet.
Example: IPv6 address 2001:db8::1
can be used for unicast to a specific device on the internet.
Interview Tip: Highlight IPv6’s massive address space and its role in future-proofing the internet.
Unicast, Broadcast, Multicast
These are ways devices communicate using IP addresses:
- Unicast: Data sent to one specific device. Example: Sending an email to one person. In IPv4, most addresses (e.g.,
192.168.1.1
) are unicast. In IPv6, unicast addresses start with 2000::/3
.
- Broadcast: Data sent to all devices in a network. Example: Announcing something to everyone in a room. In IPv4, the last IP in a subnet (e.g.,
192.168.1.255
for /24) is the broadcast address. IPv6 does not use broadcast; it uses multicast instead.
- Multicast: Data sent to a group of devices that choose to listen. Example: Streaming a video to specific viewers. In IPv4, Class D addresses (224–239) are for multicast. In IPv6, multicast addresses start with
ff00::/8
.
Question: What’s the difference between unicast, broadcast, and multicast?
Answer: Unicast is a private message to one device. Broadcast is a message to all devices in a network (IPv4 only). Multicast is a message to a group of devices (like a group chat).
Interview Tip: Mention that IPv6 replaced broadcast with multicast for efficiency. Be ready to give examples like email (unicast), network alerts (broadcast), and video streaming (multicast).
2. IP Classes (A to E) and Why Classless (CIDR)
IP Classes
Classful Addressing is an old system that divides IPv4 addresses into five classes (A, B, C, D, E) based on the first octet to organize networks.
- Class A, B, C: For unicast (one-to-one communication). Class A has 1 network bit (huge networks), B has 2, C has 3.
- Class D: For multicast (group communication, e.g., video streaming).
- Class E: Reserved for experiments, not used in practice.
- Special:
127.0.0.0/8
is for loopback (e.g., 127.0.0.1
, unicast).
Example: 192.168.1.1
is a Class C address for small networks, used for unicast. 224.0.0.1
is Class D for multicast.
Interview Tip: Explain that Class A–C are for unicast, Class D for multicast, and broadcast uses the last IP in a subnet (e.g., 192.168.1.255
).
Why Classless (CIDR)?
Classful Addressing Problems:
- Fixed Sizes: Classes have fixed network sizes (e.g., Class A = 16M hosts, Class C = 254 hosts). If a company needs 500 hosts, Class C is too small, and Class B (65,534 hosts) wastes IPs.
- IP Waste: Many unused IPs in large Class A/B networks, contributing to IPv4 exhaustion.
- Not Flexible: Can’t create custom-sized networks for specific needs.
- Inefficient Routing: Large network blocks make internet routing complex.
Classless Addressing (CIDR ->classless Inter-Domain Routing) Benefits:
- Flexible Sizes: Uses a prefix like
/24
or /23
to define network size, allowing custom subnets (e.g., 512 hosts).
- Saves IPs: Allocates only the needed number of addresses, reducing waste.
- Better Routing: Groups networks efficiently, making internet routing faster.
- Supports All Communication: Works with unicast, broadcast (IPv4), and multicast.
Example: A company needing 500 devices gets a Class B (172.16.0.0/16
, 65,534 hosts) in classful, wasting IPs. With CIDR, they get 172.16.0.0/23
(512 hosts), saving IPs.
Interview Tip: Say classful addressing is outdated due to fixed sizes and waste. CIDR is flexible, saves IPs, and improves routing.
Question: Why did we switch from classful to classless addressing?
Answer: Classful has fixed sizes (e.g., Class A = 16M hosts), wasting IPs. CIDR uses /24, /23, etc., to create custom-sized networks, saving IPs and making routing easier.
3. Subnetting with CIDR
What is Subnetting? Subnetting divides a large network into smaller networks (subnets) to save IP addresses, improve security, reduce network traffic, and organize devices.
What is CIDR? Classless Inter-Domain Routing uses a prefix (e.g., /24
) to define the network portion of an IP address, replacing fixed classful sizes.
Detailed Subnetting Example
Task: Divide 192.168.1.0/24
into 4 subnets.
- Understand /24:
- 24 bits for network, 8 bits for hosts.
- Total addresses = 2⁸ = 256 (254 usable, excluding network and broadcast).
- Need 4 Subnets:
- Borrow 2 bits (2² = 4 subnets).
- New mask: /24 + 2 = /26 (255.255.255.192).
- Hosts per Subnet:
- Host bits = 8 - 2 = 6.
- Addresses per subnet = 2⁶ = 64 (62 usable).
- Calculate Ranges:
- Block size = 256 - 192 = 64 (each subnet covers 64 addresses).
- Subnets:
192.168.1.0 - 192.168.1.63
(Network: 192.168.1.0
, Usable: 192.168.1.1–62
, Broadcast: 192.168.1.63
)
192.168.1.64 - 192.168.1.127
(Network: 192.168.1.64
, Usable: 192.168.1.65–126
, Broadcast: 192.168.1.127
)
192.168.1.128 - 192.168.1.191
(Network: 192.168.1.128
, Usable: 192.168.1.129–190
, Broadcast: 192.168.1.191
)
192.168.1.192 - 192.168.1.255
(Network: 192.168.1.192
, Usable: 192.168.1.193–254
, Broadcast: 192.168.1.255
)
Unicast/Broadcast/Multicast in Subnetting:
- Unicast: Usable IPs (e.g.,
192.168.1.1–62
) for one-to-one communication.
- Broadcast: Last IP in each subnet (e.g.,
192.168.1.63
) for all devices in that subnet.
- Multicast: Uses Class D addresses (224–239), not tied to subnets.
Question: How many usable devices in a /27
subnet?
Answer: /27 has 5 host bits (32 - 27 = 5). Total = 2⁵ = 32 addresses (30 usable, excluding network and broadcast).
Interview Tip: Practice subnetting /24 or /27 into 2, 4, or 8 subnets. Clearly list network ID, usable IPs, and broadcast address.
4. Subnet Mask and Network ID
Subnet Mask: A 32-bit number that separates the network and host portions of an IP address. It shows which bits are for the network.
- Format: Four octets (e.g.,
255.255.255.0
) or CIDR (e.g., /24
).
- Binary:
255.255.255.0
= 11111111.11111111.11111111.00000000
(24 bits for network, 8 for hosts).
Network ID: The first IP address in a subnet, identifying the network. Found using bitwise AND (1 AND 1 = 1, else 0).
Broadcast Address: The last IP in a subnet, used to send data to all devices in that subnet.
Example: IP 192.168.1.100
, Mask 255.255.255.0
(/24)
- Convert to Binary:
- IP:
11000000.10101000.00000001.01100100
- Mask:
11111111.11111111.11111111.00000000
- Bitwise AND: Result =
11000000.10101000.00000001.00000000
= 192.168.1.0
(Network ID).
- Broadcast Address: Last IP =
192.168.1.255
.
Another Example: IP 172.16.10.50/20
- Subnet Mask: /20 =
255.255.240.0
(11111111.11111111.11110000.00000000
).
- Binary AND:
- IP:
10101100.00010000.00001010.00110010
- Mask:
11111111.11111111.11110000.00000000
- Result:
10101100.00010000.00000000.00000000
= 172.16.0.0
(Network ID).
- Broadcast Address: Block size = 256 - 240 = 16 (third octet). Broadcast =
172.16.15.255
.
Interview Tip: Be ready to calculate Network ID and Broadcast Address manually. Explain that Network ID is the first IP, and broadcast is the last.
5. Public vs Private IPs
Private IPs: Used inside homes, offices, or companies. Not routable on the public internet.
- Ranges (RFC 1918):
10.0.0.0 - 10.255.255.255
(/8, 16M addresses).
172.16.0.0 - 172.31.255.255
(/12, 1M addresses).
192.168.0.0 - 192.168.255.255
(/16, 65,536 addresses).
- Use: Saves public IPs, enhances security by isolating networks, uses NAT to connect to the internet.
- Communication: Supports unicast (individual devices) and broadcast (all devices in subnet).
Public IPs: Unique addresses routable on the internet, assigned by ISPs or IANA.
- Example:
8.8.8.8
(Google DNS).
- Problem: Limited IPv4 addresses due to exhaustion.
- Communication: Supports unicast and broadcast.
Example: A home router uses private IPs (192.168.1.1–254
) for devices and one public IP via NAT to access the internet.
Interview Tip: Explain private IPs as internal extensions and public IPs as main numbers. Mention NAT for internet access.
Question: Why use private IPs?
Answer: Private IPs save public IPs, keep networks secure, and allow many devices to share one public IP via NAT.
Interview Preparation Tips
- Understand Basics: Know IPv4 (4 numbers, limited), IPv6 (long addresses, future-proof), unicast (one-to-one), broadcast (all devices, IPv4 only), multicast (group communication).
- Why CIDR: Classful addressing wastes IPs with fixed sizes; CIDR is flexible, saves IPs, and supports efficient routing.
- Subnetting: Practice splitting
/24
or /27
into subnets. List network ID, usable IPs, and broadcast address.
- Binary Math: Be quick at binary-to-decimal conversion and bitwise AND for Network ID.
- Explain Simply: Use analogies like “Subnetting is cutting a pizza. Unicast is a private call, broadcast is shouting, multicast is a group chat.”
- Common Questions:
- Divide
192.168.1.0/24
into 4 subnets and list ranges, network ID, and broadcast.
- Why use CIDR instead of classful addressing?
- Explain unicast, broadcast, multicast with examples.
- Calculate Network ID and Broadcast Address for an IP and mask.
Final Note: Practice makes these concepts easy! Save this HTML file and open it in a browser to study. If you need more examples, ask away!