Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Tools
Online Compiler JSON Formatter Regex Tester CSS Unit Converter Color Picker
Compiler Tools

IP Addressing IPv4, IPv6, Classes, CIDR: Tutorial, Examples, FAQs & Interview Tips

IPv4 Addressing

An IPv4 address is a 32-bit number written in dotted decimal notation - four octets (8-bit groups) separated by dots. Each octet ranges from 0 to 255.

Example: 192.168.1.100 = 11000000.10101000.00000001.01100100 in binary

IPv4 Address Classes

ClassFirst Octet RangeDefault Subnet MaskNetworksHosts/NetworkUse
A1 - 126255.0.0.0 (/8)12616,777,214Large organizations
B128 - 191255.255.0.0 (/16)16,38465,534Medium organizations
C192 - 223255.255.255.0 (/24)2,097,152254Small organizations
D224 - 239N/AN/AN/AMulticast
E240 - 255N/AN/AN/AReserved/Experimental

Special IP Addresses

Address/RangePurpose
127.0.0.0 - 127.255.255.255Loopback (localhost) - 127.0.0.1 is most common
10.0.0.0 - 10.255.255.255Private Class A (RFC 1918)
172.16.0.0 - 172.31.255.255Private Class B (RFC 1918)
192.168.0.0 - 192.168.255.255Private Class C (RFC 1918)
169.254.0.0 - 169.254.255.255APIPA (Automatic Private IP Addressing) - when DHCP fails
0.0.0.0Default route / unspecified address
255.255.255.255Limited broadcast (all hosts on local network)

Unicast, Multicast, and Broadcast

  • Unicast: One-to-one communication. A packet is sent from one source to one specific destination. Most common type.
  • Broadcast: One-to-all communication. A packet is sent to all devices on a network. Example: 192.168.1.255 (directed broadcast for 192.168.1.0/24).
  • Multicast: One-to-many communication. A packet is sent to a group of interested receivers. Uses Class D addresses (224.0.0.0 - 239.255.255.255).
  • Anycast: One-to-nearest communication. A packet is sent to the nearest node in a group. Used in IPv6 and CDNs.

IPv6 Addressing

IPv6 uses 128-bit addresses written as 8 groups of 4 hexadecimal digits separated by colons.

Example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334

Abbreviation rules:

  • Leading zeros in each group can be omitted: 0db8 -> db8
  • One consecutive group of all-zero groups can be replaced with ::: 2001:db8::8a2e:370:7334

IPv4 vs IPv6

FeatureIPv4IPv6
Address Size32 bits128 bits
Address FormatDotted decimal (192.168.1.1)Hexadecimal colon notation
Total Addresses~4.3 billion~340 undecillion
Header Size20-60 bytes (variable)40 bytes (fixed)
NAT RequiredYes (address exhaustion)No (enough addresses)
SecurityOptional (IPSec)Built-in (IPsec mandatory)
BroadcastYesNo (uses multicast/anycast)
Auto-configurationDHCPSLAAC (Stateless Address Autoconfiguration)

IPv6 Address Types

TypePrefixPurposeExample
Global Unicast 2000::/3 Routable Internet addresses 2001:db8::1
Link-Local fe80::/10 Communication on same link fe80::1
Unique Local fc00::/7 Private addressing (like RFC 1918) fc00::1
Multicast ff00::/8 One-to-many communication ff02::1
Loopback ::1 Local host (like 127.0.0.1) ::1
Unspecified :: Default route (like 0.0.0.0) ::

Subnet Masking and CIDR

Subnet masks divide IP addresses into network and host portions. CIDR (Classless Inter-Domain Routing) replaces class-based addressing with flexible subnetting.

CIDR Notation

CIDRSubnet MaskNetwork BitsHost BitsTotal HostsUsable Hosts
/8255.0.0.082416,777,21616,777,214
/16255.255.0.0161665,53665,534
/24255.255.255.0248256254
/25255.255.255.128257128126
/26255.255.255.1922666462
/27255.255.255.2242753230
/28255.255.255.2402841614
/29255.255.255.24829386
/30255.255.255.25230242
/31255.255.255.25431120
/32255.255.255.25532011

IP Address Assignment Methods

Dynamic Host Configuration Protocol (DHCP)

DHCP automatically assigns IP addresses to devices on a network. The DHCP process involves four steps:

  • DHCPDISCOVER: Client broadcasts request for IP address
  • DHCPOFFER: Server offers available IP address
  • DHCPREQUEST: Client requests the offered address
  • DHCPACK: Server acknowledges and assigns the address

Static vs Dynamic IP Assignment

MethodAdvantagesDisadvantagesUse Cases
Static IP Consistent address, no DHCP dependency, easy to remember Manual configuration, potential conflicts, less flexible Servers, printers, routers, infrastructure devices
Dynamic IP Automatic configuration, no conflicts, efficient address usage Address changes, requires DHCP server, less predictable Client computers, mobile devices, temporary connections

Network Address Translation (NAT)

NAT allows multiple devices to share a single public IP address by translating private addresses to public ones. It was developed to address IPv4 address exhaustion.

NAT Types

  • Static NAT: One-to-one mapping between private and public addresses
  • Dynamic NAT: Many-to-many mapping from a pool of public addresses
  • PAT (Port Address Translation): Many-to-one mapping using different ports (most common)
  • NAT Overload: Another term for PAT, overloading a single public IP

NAT Benefits and Limitations

BenefitsLimitations
Conserves IPv4 addresses Breaks end-to-end connectivity
Provides basic security (hides internal network) Problems with peer-to-peer applications
Allows network renumbering Complicates VoIP and video conferencing
Reduces need for public addresses Performance overhead

IPv6 Address Configuration

Stateless Address Autoconfiguration (SLAAC)

SLAAC allows devices to automatically configure their own IPv6 addresses without a central server:

  1. Device creates link-local address (fe80::/10)
  2. Device discovers network prefix via Router Advertisement
  3. Device combines prefix with interface identifier
  4. Device performs Duplicate Address Detection (DAD)

Interface Identifier Generation

  • EUI-64: Derived from MAC address (privacy concerns)
  • Privacy Extensions: Random temporary addresses
  • Stable Privacy: Random but stable addresses
  • Manual: Manually configured interface ID

IP Address Planning and Best Practices

IPv4 Address Planning

  • Use RFC 1918 private addresses for internal networks
  • Reserve address ranges for different purposes (servers, printers, DHCP, etc.)
  • Document address assignments in a central registry
  • Plan for growth by allocating larger subnets initially
  • Use consistent addressing schemes across locations

IPv6 Address Planning

  • Assign /48 prefixes to sites for easy routing
  • Use /64 subnets for LAN segments (standard practice)
  • Implement IPv6 alongside IPv4 (dual-stack)
  • Plan address hierarchy for efficient routing
  • Consider privacy addressing for client devices

IP Address Troubleshooting

Common IP Address Issues

  • IP Conflicts: Multiple devices with same IP address
  • Incorrect Subnet Mask: Devices can't reach other networks
  • Default Gateway Issues: No internet connectivity
  • DNS Resolution Problems: Can't resolve domain names
  • DHCP Failures: Devices can't get IP addresses

Troubleshooting Commands

CommandPurposeExample Usage
ipconfig / ifconfig Show IP configuration ipconfig /all (Windows)
ping Test connectivity ping 8.8.8.8
tracert / traceroute Trace network path tracert google.com
nslookup DNS resolution test nslookup google.com
arp -a Show ARP table arp -a
netstat -rn Show routing table netstat -rn

IP Security Considerations

Security Best Practices

  • Use private addressing for internal networks (RFC 1918)
  • Implement firewalls to control traffic between networks
  • Disable unused services that might expose IP addresses
  • Use IPsec for secure communication between sites
  • Monitor for IP spoofing and unauthorized address usage
  • Implement DHCP snooping to prevent rogue DHCP servers

Common IP-based Attacks

  • IP Spoofing: Forging source IP addresses
  • Smurf Attacks: ICMP echo requests to broadcast addresses
  • SYN Floods: Overwhelming servers with connection requests
  • DNS Amplification: Using DNS servers for DDoS attacks
  • ARP Poisoning: Corrupting ARP tables for man-in-the-middle attacks

Future of IP Addressing

IPv6 Adoption Trends

  • Mobile Networks: 4G/5G networks heavily use IPv6
  • Cloud Services: Major cloud providers support IPv6
  • Content Delivery: CDNs increasingly support IPv6
  • Government Mandates: Some countries require IPv6 support
  • IoT Devices: IPv6 essential for massive IoT deployments

Emerging Technologies

  • IPv6-only Networks: Eliminating IPv4 entirely
  • NAT64/DNS64: IPv6 to IPv4 translation mechanisms
  • Segment Routing: Advanced routing with IPv6
  • programmable addressing: SDN-based address management
  • Zero Trust Networking: Identity-based access control

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.