IP Addressing & Subnetting Notes (Detailed)

1. IPv4 and IPv6 Basics

IPv4 VS IPv6 Comperision

image

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.

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.

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:

image
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.

image
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:

Classless Addressing (CIDR ->classless Inter-Domain Routing) Benefits:

image
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.

  1. Understand /24:
    • 24 bits for network, 8 bits for hosts.
    • Total addresses = 2⁸ = 256 (254 usable, excluding network and broadcast).
  2. Need 4 Subnets:
    • Borrow 2 bits (2² = 4 subnets).
    • New mask: /24 + 2 = /26 (255.255.255.192).
  3. Hosts per Subnet:
    • Host bits = 8 - 2 = 6.
    • Addresses per subnet = 2⁶ = 64 (62 usable).
  4. Calculate Ranges:
    • Block size = 256 - 192 = 64 (each subnet covers 64 addresses).
    • Subnets:
      1. 192.168.1.0 - 192.168.1.63 (Network: 192.168.1.0, Usable: 192.168.1.1–62, Broadcast: 192.168.1.63)
      2. 192.168.1.64 - 192.168.1.127 (Network: 192.168.1.64, Usable: 192.168.1.65–126, Broadcast: 192.168.1.127)
      3. 192.168.1.128 - 192.168.1.191 (Network: 192.168.1.128, Usable: 192.168.1.129–190, Broadcast: 192.168.1.191)
      4. 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:

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.

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)

  1. Convert to Binary:
    • IP: 11000000.10101000.00000001.01100100
    • Mask: 11111111.11111111.11111111.00000000
  2. Bitwise AND: Result = 11000000.10101000.00000001.00000000 = 192.168.1.0 (Network ID).
  3. Broadcast Address: Last IP = 192.168.1.255.

Another Example: IP 172.16.10.50/20

  1. Subnet Mask: /20 = 255.255.240.0 (11111111.11111111.11110000.00000000).
  2. Binary AND:
    • IP: 10101100.00010000.00001010.00110010
    • Mask: 11111111.11111111.11110000.00000000
    • Result: 10101100.00010000.00000000.00000000 = 172.16.0.0 (Network ID).
  3. 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.

Public IPs: Unique addresses routable on the internet, assigned by ISPs or IANA.

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

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!