SkarpSkarp

Chapter 4 of 29

IPv4 Addressing, Subnetting, and the Default Gateway

Dive deep into IPv4 addressing and subnetting so you can quickly design and troubleshoot IP schemes, including how hosts use their default gateway to reach remote networks.

27 min readen

IPv4 Addressing Fundamentals

IPv4 as 32 Bits

An IPv4 address is a 32-bit number, usually written as four decimal octets like `192.168.10.25`. Under the hood it is binary, for example `11000000 10101000 00001010 00011001`.

Network vs Host Portion

Every IPv4 address has a network portion and a host portion. A subnet mask or CIDR prefix tells devices how many bits are network bits and how many remain for hosts.

Legacy Classes

Historically, IPv4 used fixed classes: A (0–127), B (128–191), C (192–223) for unicast, plus D (224–239) multicast and E (240–255) experimental. Modern design uses classless CIDR.

Private IPv4 Ranges

Private IPv4 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) are used inside networks and are translated to public addresses using Network Address Translation (NAT).

Subnet Masks and CIDR Notation

What a Subnet Mask Is

A subnet mask is 32 bits where network bits are 1 and host bits are 0. Example: 255.255.255.0 is `11111111 11111111 11111111 00000000`, meaning 24 network bits.

CIDR Slash Notation

CIDR notation like `/24` is just a count of 1-bits in the mask. `/24` and 255.255.255.0 describe the same boundary between network and host bits.

Hosts per Subnet Formula

Given a prefix `/n`: host bits = 32−n, total addresses = 2^(32−n), usable hosts = 2^(32−n) − 2 (excluding network and broadcast addresses).

Example: /26

For `/26`, host bits = 6, total addresses = 64, usable hosts = 62. You will use these quick mental calculations constantly when subnetting.

Finding Network, Broadcast, and Host Range (Step-by-Step)

Block Size Method

To find network info, focus on the interesting octet: block size = 256 − mask_octet. Subnets start at 0, then add the block size repeatedly (0, block, 2×block, ...).

Example 1: /26 on 192.168.10.77

`/26` → 255.255.255.192, block size 64 in last octet. Subnets: .0, .64, .128, .192. 77 is in .64–.127, so network 192.168.10.64/26, broadcast .127.

Host Range for Example 1

For 192.168.10.64/26, first usable host is .65, last usable is .126. Network .64 and broadcast .127 are not assigned to hosts.

Example 2: /20 on 10.2.130.5

`/20` → 255.255.240.0, block size 16 in 3rd octet. 128 ≤ 130 < 144, so network 10.2.128.0/20, broadcast 10.2.143.255, hosts .128.1–.143.254.

Designing Subnets and VLSM

What is VLSM?

Variable Length Subnet Masking (VLSM) means using different prefix lengths in the same major network so each subnet size matches its host requirement without wasting addresses.

VLSM Design Process

Design steps: 1) List subnets and host needs. 2) Find smallest prefix for each. 3) Sort from largest to smallest. 4) Allocate sequentially inside the major block without overlap.

Example Requirements

From 192.168.50.0/24: A needs 100 hosts (/25), B 50 (/26), C 10 (/28), D 2 (/30). Larger subnets get placed first so smaller ones can fit into the gaps.

Example Allocation

Allocate: A 192.168.50.0/25, B 192.168.50.128/26, C 192.168.50.192/28, D 192.168.50.208/30. Each block is aligned to its own block size and does not overlap.

Hands-On VLSM Thought Exercise

Work through this design mentally (or on paper) to solidify VLSM. Then compare your reasoning with the walkthrough.

Scenario:

You are given the major network 10.10.0.0/24 for a small branch office. You must create subnets for:

  • LAN1: up to 60 hosts
  • LAN2: up to 25 hosts
  • LAN3: up to 10 hosts
  • WAN link to HQ: 2 hosts

Tasks:

  1. For each network, decide the smallest prefix that supports its hosts.
  2. Sort the requirements from largest to smallest.
  3. Allocate subnets from 10.10.0.0/24 without overlap.
  4. For LAN2, write down the network address, broadcast address, and first/last usable host.

Pause here and try to solve it before reading the walkthrough below.

---

Walkthrough:

  1. Prefix sizes:
  • LAN1 (60 hosts): needs `/26` (62 usable)
  • LAN2 (25 hosts): needs `/27` (30 usable)
  • LAN3 (10 hosts): needs `/28` (14 usable)
  • WAN (2 hosts): needs `/30` (2 usable)
  1. Sort: LAN1, LAN2, LAN3, WAN.
  1. Allocate from 10.10.0.0/24:
  • LAN1: 10.10.0.0/26
  • LAN2: 10.10.0.64/27
  • LAN3: 10.10.0.96/28
  • WAN: 10.10.0.112/30
  1. LAN2 details (10.10.0.64/27):
  • Block size in last octet: 256 - 224 = 32
  • Network: 10.10.0.64
  • Next subnet: 10.10.0.96 → broadcast: 10.10.0.95
  • First usable: 10.10.0.65
  • Last usable: 10.10.0.94

Reflect: could you do this quickly under exam timing? If not, practice with a few more made-up host counts until the pattern feels automatic.

How the Default Gateway Works

Default Gateway Definition

A default gateway is the IP address of a router interface on the local network segment that a host uses to send traffic destined for remote networks.

Local vs Remote Decision

A host uses its IP and subnet mask to compute its network ID, then compares that to the destination’s network ID. Same network: send directly. Different network: send to the default gateway.

Example: Local Traffic

PC1 192.168.10.10/24 to Server1 192.168.10.50/24 are in the same subnet. PC1 ARPs for 192.168.10.50 and sends frames directly to Server1’s MAC address.

Example: Remote Traffic

PC1 192.168.10.10/24 to Server2 10.20.30.40/24 is remote. PC1 ARPs for 192.168.10.1 (default gateway) and sends frames to the router, which forwards based on its routing table.

Troubleshooting IPv4 Addressing and Default Gateway Issues

Four Key Host Settings

Most IPv4 connectivity issues involve IP address, subnet mask, default gateway, or DNS. Always verify these on the host before chasing complex routing problems.

Scenario 1: Mask Mismatch

If a PC uses /25 but the router and peers use /24, the PC misclassifies some peers as remote. This causes strange reachability or asymmetric routing issues.

Scenario 2: Wrong Gateway IP

If the default gateway IP is mistyped, local pings still work but all remote traffic fails. The host ARPs for a non-existent or wrong device and never reaches other networks.

Scenario 3: Gateway in Another Subnet

The default gateway must be in the same subnet as the host. If the gateway is 192.168.6.1 but the host is 192.168.5.10/24, ARP for the gateway never succeeds and remote traffic fails.

Quick Check: Subnet and Host Range

Use this quiz to test your ability to calculate subnet information from an address and prefix.

You are given the host address 172.16.9.130/25. What is the correct network address and the range of usable host addresses for this subnet?

  1. Network: 172.16.9.0, usable hosts: 172.16.9.1 – 172.16.9.126
  2. Network: 172.16.9.128, usable hosts: 172.16.9.129 – 172.16.9.254
  3. Network: 172.16.9.128, usable hosts: 172.16.9.129 – 172.16.9.254 (excluding 172.16.9.255)
  4. Network: 172.16.9.128, usable hosts: 172.16.9.129 – 172.16.9.254 (broadcast 172.16.9.255)
Show Answer

Answer: A) Network: 172.16.9.0, usable hosts: 172.16.9.1 – 172.16.9.126

`/25` means mask 255.255.255.128, block size 128 in the last octet. Subnets start at .0 and .128. 130 falls in 128–255, so the network is 172.16.9.128. Broadcast is 172.16.9.255, so usable hosts are 172.16.9.129–172.16.9.254. Option A is the only one with a valid network and host range; the others either use the wrong network or include the broadcast as a host.

Quick Check: Default Gateway Behavior

Test your understanding of how a host uses its default gateway.

A PC has IP 192.168.20.10/24 and default gateway 192.168.20.1. It tries to reach 172.16.5.5. Which statement best describes what happens on the PC’s local network?

  1. The PC ARPs for 172.16.5.5 and sends the frame directly to that host.
  2. The PC ARPs for 192.168.20.1 and sends the frame to the router, which then forwards it toward 172.16.5.5.
  3. The PC sends the packet with a destination MAC of the switch, which decides whether to forward it to the router.
  4. The PC drops the packet immediately because the destination is not in the same subnet.
Show Answer

Answer: B) The PC ARPs for 192.168.20.1 and sends the frame to the router, which then forwards it toward 172.16.5.5.

The PC compares its own network (192.168.20.0/24) with the destination (172.16.5.0/24) and sees they are different. It keeps the IP destination as 172.16.5.5 but sets the layer 2 destination to the default gateway. To do that it ARPs for 192.168.20.1, then sends the frame to the router, which routes it onward.

Key IPv4 and Gateway Terms

Flip these cards to reinforce essential definitions and facts you will need on the CCNA.

IPv4 address length
An IPv4 address is 32 bits long, typically shown as four decimal octets separated by dots (for example 192.168.1.10).
Subnet mask purpose
A subnet mask marks which bits of an IPv4 address are the network portion (1s) and which bits are the host portion (0s), enabling devices to determine local vs remote addresses.
CIDR prefix length
CIDR notation like /24 indicates the number of 1-bits in the subnet mask. /24 corresponds to 255.255.255.0.
Hosts per subnet formula
Usable hosts per subnet = 2^(32 − prefix_length) − 2, subtracting the network and broadcast addresses.
Private IPv4 ranges
10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 are private ranges used inside networks and translated using Network Address Translation (NAT).
Default gateway (canonical)
A default gateway is the IP address of a router interface on the local network segment that a host uses to send traffic destined for remote networks.
Network Address Translation (NAT)
Network Address Translation (NAT) is a method of translating private IP addresses to public IP addresses, and vice versa, as packets traverse a router or firewall.
Dynamic Host Configuration Protocol (DHCP)
The Dynamic Host Configuration Protocol (DHCP) automatically assigns IP configuration parameters such as IP address, subnet mask, default gateway, and DNS servers to clients.
Domain Name System (DNS)
The Domain Name System (DNS) is a distributed database that maps human-readable hostnames to IP addresses and other resource records.
Common /24 mask mnemonic
Remember /24 as 255.255.255.0 and 254 usable hosts. This is one of the most common subnet sizes in small and medium networks.

CLI Practice: Verifying IPv4 and Gateway on Cisco IOS

You will not configure full routing here, but you should be comfortable reading and setting basic IPv4 and default gateway parameters on Cisco IOS. These snippets mirror what you might see in CCNA labs.

Example 1: Configure an IPv4 address on a router interface

```plaintext

R1(config)# interface gigabitEthernet0/0

R1(config-if)# ip address 192.168.10.1 255.255.255.0

R1(config-if)# no shutdown

R1(config-if)# exit

```

This makes 192.168.10.1 the default gateway for hosts in the 192.168.10.0/24 subnet (assuming they point to it).

Example 2: Configure a default gateway on a Layer 2 switch

On a pure Layer 2 switch, the default gateway is used only for the switch’s own management traffic (for example SSH, SNMP), not for end hosts.

```plaintext

SW1(config)# interface vlan 1

SW1(config-if)# ip address 192.168.10.2 255.255.255.0

SW1(config-if)# no shutdown

SW1(config-if)# exit

SW1(config)# ip default-gateway 192.168.10.1

```

Example 3: Verify interface addresses

```plaintext

R1# show ip interface brief

Interface IP-Address OK? Method Status Protocol

GigabitEthernet0/0 192.168.10.1 YES manual up up

GigabitEthernet0/1 10.1.1.1 YES manual up up

```

On an endpoint (Windows example), you might verify:

```plaintext

C:\> ipconfig

Ethernet adapter Ethernet:

IPv4 Address. . . . . . . . . . . : 192.168.10.10

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.10.1

```

Being able to quickly interpret these outputs is essential for troubleshooting in labs and on the exam.

Key Terms

DNS
The Domain Name System (DNS) is a distributed database that maps human-readable hostnames to IP addresses and other resource records.
NAT
Network Address Translation (NAT) is a method of translating private IP addresses to public IP addresses, and vice versa, as packets traverse a router or firewall.
DHCP
The Dynamic Host Configuration Protocol (DHCP) automatically assigns IP configuration parameters such as IP address, subnet mask, default gateway, and DNS servers to clients.
VLSM
Variable Length Subnet Masking, the practice of using different prefix lengths within the same major network to match subnet sizes to host requirements.
Subnet mask
A 32-bit value that indicates which bits of an IPv4 address are the network portion (1s) and which bits are the host portion (0s).
IPv4 address
A 32-bit logical address written in dotted-decimal notation (for example 192.168.1.10) used to identify interfaces in an IP network.
CIDR notation
Classless Inter-Domain Routing notation; represents a subnet mask as a slash followed by the number of 1-bits (for example /24).
Network address
The first address in a subnet, with all host bits set to 0. It identifies the subnet itself and is not assigned to a host.
default gateway
A default gateway is the IP address of a router interface on the local network segment that a host uses to send traffic destined for remote networks.
Broadcast address
The last address in a subnet, with all host bits set to 1. Packets sent to this address are delivered to all hosts in the subnet.

Finished reading?

Test your understanding with a custom practice exam on this chapter.

Test yourself