Days 7, 8: IPv4
IPv4 Addressing
Overview
IPv4 Fundamentals
IPv4 (Internet Protocol Version 4) is the primary Layer 3 protocol used in modern networks. It provides:
-
Logical addressing via 32-bit IP addresses
-
Connectivity between different networks (requires routers)
-
Path selection between source and destination hosts
Key Distinction from Layer 2:
-
Layer 2 (Switches) expands networks using MAC addressing within the same LAN
-
Layer 3 (Routers) separates and connects different networks using IP addressing
IP Address Structure
The IPv4 Address Format
IPv4 addresses consist of 32 bits divided into 4 octets (8 bits each), written in Dotted Decimal Notation:
192.168.1.254
Each decimal number = 8-bit octet
Each octet can range from 0 to 255
Binary Representation:
192 . 168 . 1 . 254
11000000 . 10101000 . 00000001 . 11111110
Network and Host Portions
An IP address is split into two parts:
-
Network Portion — Identifies the network itself
-
Host Portion — Identifies the device within that network
Notation: CIDR (Classless Inter-Domain Routing)
The slash notation /X indicates how many bits are the network portion:
192.168.1.254/24
/ 24 = The first 24 bits are the NETWORK portion
The remaining 8 bits are the HOST portion
NETWORK: 192.168.1 (first 3 octets)
HOST: .254 (last octet)
All devices on the same network must have the same network portion but different host portions:
192.168.1.100 ← Same network (192.168.1)
192.168.1.105 ← Same network (192.168.1)
192.168.1.205 ← Same network (192.168.1)
Network Boundaries
Routers separate networks. When a router is placed between two networks:
Network 1: 192.168.1.0/24
Router Interface 1 (G0/0): 192.168.1.254
Router Interface 2 (G0/1): 192.168.2.254
Network 2: 192.168.2.0/24
Each router interface gets a unique IP address on the network it connects to.
Broadcasts do not cross routers: When a broadcast packet hits a router, it stops. Broadcasts stay within the local LAN.
Number Systems for IP Addressing
Converting Binary to Decimal
Each bit position represents a power of 2:
Bit positions: 128 64 32 16 8 4 2 1
Example: 1 0 0 1 1 1 1 1 = 10011111
Calculation:
1 × 128 = 128
0 × 64 = 0
0 × 32 = 0
1 × 16 = 16
1 × 8 = 8
1 × 4 = 4
1 × 2 = 2
1 × 1 = 1
Sum: 128 + 16 + 8 + 4 + 2 + 1 = 159
Another Example: 01110110
64 + 32 + 16 + 4 + 2 = 118
Converting Decimal to Binary
Method 1: Subtraction (Left to Right)
Convert 221 to binary:
221 - 128 = 93 ✓ → write 1 in 128 position
93 - 64 = 29 ✓ → write 1 in 64 position
29 - 32 = X ✗ → write 0 in 32 position
29 - 16 = 13 ✓ → write 1 in 16 position
13 - 8 = 5 ✓ → write 1 in 8 position
5 - 4 = 1 ✓ → write 1 in 4 position
1 - 2 = X ✗ → write 0 in 2 position
1 - 1 = 0 ✓ → write 1 in 1 position
Result: 11011101
Method 2: Subtraction from 255
Convert 207 to binary:
255 - 207 = 48
Now find where 48 appears in binary positions:
48 = 32 + 16
So the 0's are in positions 32 and 16
The 1's are everywhere else
Result: 11001111
Convert Binary IP to Decimal
Binary: 10011010.01001110.01101111.00100000
Octet 1: 128 + 16 + 8 + 2 = 154
Octet 2: 64 + 8 + 4 + 2 = 78
Octet 3: 64 + 32 + 8 + 4 + 2 + 1 = 111
Octet 4: 32
IPv4 Address: 154.78.111.32
IPv4 Address Classes
IPv4 addresses are divided into 5 classes based on the first octet:
|
Class |
First Bit Pattern |
First Octet Range |
Network Bits |
Host Bits |
CIDR |
|
A |
0xxxxxxx |
0–126 (127 = loopback) |
8 |
24 |
/8 |
|
B |
10xxxxxx |
128–191 |
16 |
16 |
/16 |
|
C |
110xxxxx |
192–223 |
24 |
8 |
/24 |
|
D |
1110xxxx |
224–239 |
Multicast (reserved) |
— |
— |
|
E |
1111xxxx |
240–255 |
Experimental (reserved) |
— |
— |
For CCNA, focus on Classes A, B, and C.
Class A (0–126)
Example: 10.0.0.0/8
Range: 10.0.0.1 to 10.255.255.254
Hosts: 2^24 - 2 = 16,777,214
Network portion: First octet only
Host portion: Last 3 octets
-
Very large networks
-
Rarely used in modern networks (reserved for special use)
Class B (128–191)
Example: 172.16.0.0/16
Range: 172.16.0.1 to 172.16.255.254
Hosts: 2^16 - 2 = 65,534
Network portion: First 2 octets
Host portion: Last 2 octets
-
Medium-sized networks
-
Common in larger enterprises
Class C (192–223)
Example: 192.168.1.0/24
Range: 192.168.1.1 to 192.168.1.254
Hosts: 2^8 - 2 = 254
Network portion: First 3 octets
Host portion: Last octet
-
Smaller networks
-
Most common in small to medium businesses
Special Addresses: Loopback (Class A)
127.0.0.0 to 127.255.255.255 — Reserved for loopback testing
127.0.0.1 is the standard loopback address
Used to test the network stack (OSI & TCP/IP model) on a local device
Does not go to the network; stays on the local machine
Useful for testing TCP/IP implementation without actual network traffic
Subnet Masks and Network Addresses
Subnet Mask (Netmask)
A subnet mask identifies which bits are the network portion and which are the host portion:
-
1's in the binary netmask = network bits
-
0's in the binary netmask = host bits
Standard Class Netmasks:
|
Class |
CIDR |
Dotted Decimal |
Binary |
|
A |
/8 |
255.0.0.0 |
11111111.00000000.00000000.00000000 |
|
B |
/16 |
255.255.0.0 |
11111111.11111111.00000000.00000000 |
|
C |
/24 |
255.255.255.0 |
11111111.11111111.11111111.00000000 |
Example: Identifying Network and Host with Mask
IP Address: 192.168.1.100
Netmask (/24): 255.255.255.0
Match the 1's in the netmask:
Network: 192.168.1.0
Host portion: .100
Network Addresses and Broadcast Addresses
Network Address (First Address)
When the host portion is all 0's, it's the network address — the identifier of the network itself.
192.168.1.0/24 = NETWORK ADDRESS (not assigned to any host)
Broadcast Address (Last Address)
When the host portion is all 1's, it's the broadcast address — used to send data to all hosts on the network.
192.168.1.255/24 = BROADCAST ADDRESS (not assigned to any host)
Destination IP: 192.168.1.255
Destination MAC: FFFF.FFFF.FFFF
First and Last Usable Addresses
Because network and broadcast addresses are reserved, the usable host range is:
Network Address: 192.168.1.0 ← Not usable
First Usable Address: 192.168.1.1 ← Usable
...
Last Usable Address: 192.168.1.254 ← Usable
Broadcast Address: 192.168.1.255 ← Not usable
Calculating Maximum Hosts per Network
Formula: 2^N - 2
Where N = number of host bits
(The "-2" accounts for the network address and broadcast address)
Class A Example
10.0.0.0/8
Host bits: 24 (since /8 network bits)
Maximum hosts: 2^24 - 2 = 16,777,216 - 2 = 16,777,214
Class B Example
172.16.0.0/16
Host bits: 16
Maximum hosts: 2^16 - 2 = 65,536 - 2 = 65,534
Class C Example
192.168.1.0/24
Host bits: 8
Maximum hosts: 2^8 - 2 = 256 - 2 = 254
IPv4 Header (Layer 3)
Header Overview
The IPv4 header contains many more fields than the Ethernet header:
Minimum Header Length: 20 bytes Maximum Header Length: 60 bytes
Key Header Fields
Source IP Address (32 bits)
-
IP address of the sender/originating device
Destination IP Address (32 bits)
-
IP address of the intended receiver/destination
Total Length (16 bits)
-
Indicates the total length of the packet (header + data)
-
Measured in bytes (not 4-byte increments like IHL)
-
Minimum: 20 bytes (header only, no data)
-
Maximum: 65,535 bytes (2^16 - 1)
Header Checksum (16 bits)
-
Calculated checksum for error detection
-
Routers calculate this and drop the packet if checksums don't match
-
Only checks the IPv4 header, not the encapsulated data
-
The encapsulated protocol (TCP/UDP) handles data error checking
Time To Live (TTL) (8 bits)
-
Prevents packets from circulating indefinitely
-
Decremented by 1 at each router
-
When TTL reaches 0, the packet is dropped
-
Default value: typically 64 or 255
Version (4 bits)
-
IP version: 4 for IPv4, 6 for IPv6
Cisco Router Interface Configuration
Viewing Interface Status
Router# show ip interface brief
Output columns:
|
Column |
Meaning |
|
Interface |
Physical port name (Gi0/0, Fa0/1, etc.) |
|
IP Address |
Assigned IP address (or unassigned) |
|
Method |
How the IP was assigned (manual, DHCP, etc.) |
|
Status (L1) |
Physical layer status (up/down/administratively down) |
|
Protocol (L2) |
Data link layer status (up/down) |
Status Meanings:
-
up — Interface is operational
-
down — Interface has a problem or no cable
-
administratively down — Interface has been disabled with shutdown command
Default Behavior:
-
Router interfaces are administratively down by DEFAULT
-
Switch interfaces are NOT administratively down by default
Entering Interface Configuration Mode
Router# configure terminal
Router(config)# interface gigabitethernet 0/0
Shorthand can be used: g0/0, fa0/0, etc.
Assigning an IP Address
Router(config-if)# ip address 10.255.255.254 255.0.0.0
Format: ip address <IP> <netmask>
Enabling the Interface
Router(config-if)# no shutdown
This removes the "administratively down" status.
Expected output:
Interface GigabitEthernet0/0 changed state to up
Line protocol on Interface GigabitEthernet0/0, changed state to up
Verifying Configuration
From interface configuration mode, use do to execute privileged commands:
Router(config-if)# do show ip interface brief
This confirms the interface is up and the IP address is assigned correctly.
Detailed Interface Information
Router# show interfaces gigabitethernet 0/0
Shows extensive Layer 1, Layer 2, and Layer 3 information:
-
MAC address (BIA)
-
IP address
-
Interface encapsulation
-
MTU size
-
Error statistics
-
And much more
Router# show interfaces description
Displays descriptions assigned to each interface (if any).
Summary: Common IPv4 Classes at a Glance
|
Feature |
Class A |
Class B |
Class C |
|
First Octet |
0–126 |
128–191 |
192–223 |
|
CIDR |
/8 |
/16 |
/24 |
|
Netmask |
255.0.0.0 |
255.255.0.0 |
255.255.255.0 |
|
Networks |
126 |
16,384 |
2,097,152 |
|
Hosts per Network |
16,777,214 |
65,534 |
254 |
|
Example Network |
10.0.0.0 |
172.16.0.0 |
192.168.1.0 |
|
First Usable Host |
10.0.0.1 |
172.16.0.1 |
192.168.1.1 |
|
Last Usable Host |
10.255.255.254 |
172.16.255.254 |
192.168.1.254 |
|
Broadcast Address |
10.255.255.255 |
172.16.255.255 |
192.168.1.255 |
Quick Conversion Reference
Common Decimal to Binary for Octets:
|
Decimal |
Binary |
Decimal |
Binary |
|
0 |
00000000 |
128 |
10000000 |
|
1 |
00000001 |
192 |
11000000 |
|
127 |
01111111 |
224 |
11100000 |
|
255 |
11111111 |
254 |
11111110 |
Key Takeaways for CCNA
✅ IPv4 addresses are 32-bit logical addresses, split into network and host portions
✅ The CIDR notation (/8, /16, /24) indicates the network portion length
✅ Routers separate networks; switches expand networks within the same LAN
✅ IPv4 Classes A, B, C differ in network size (more hosts = more network bits needed)
✅ Network addresses (all host bits = 0) and broadcast addresses (all host bits = 1) are reserved and not usable
✅ Usable host range = 2^(host bits) - 2
✅ Router interfaces must be enabled with no shutdown (administratively down by default)
✅ Subnet masks use 1's for network bits and 0's for host bits
✅ Binary-to-decimal conversion is crucial for subnetting (coming next!)
✅ Broadcasts don't cross routers — they stay within the local LAN
✅ Verify interface configuration with show ip interface brief and show interfaces <interface>