Skip to content

Computer Networks — Level 3 Reference Notes

Network Layer: IP Addressing, Subnetting, Routing, Routing Protocols, ARP/RARP and NAT. Placement preparation, technical interviews, conceptual revision and MCQ preparation.


1. IP Addressing Fundamentals

1.1 What is an IP Address

An IP address is a logical address used to identify a network interface and help deliver packets across interconnected networks.

For example:

192.168.1.10

This is an IPv4 address.

IPv4 addresses are 32 bits long, divided into four 8-bit groups called octets.

Each octet represents a number from 0 to 255.

An IP address helps routers determine where a packet should be forwarded. It is different from a MAC address, which is used for delivery on a local link.

1.2 Network and Host Portions

An IP address alone does not tell us which network it belongs to. We also need the prefix length, commonly written using CIDR notation.

Example:

192.168.1.10/24

  • 192.168.1.10 is the interface's IPv4 address.
  • /24 means the first 24 bits form the network prefix.
  • The remaining 8 bits identify addresses within that subnet.

The corresponding subnet mask is:

255.255.255.0

The network address is:

192.168.1.0/24

Understanding different prefixes

Prefix Subnet mask Network bits Host bits Total addresses
/8 255.0.0.0 8 24 16,777,216
/16 255.255.0.0 16 16 65,536
/24 255.255.255.0 24 8 256
/25 255.255.255.128 25 7 128
/26 255.255.255.192 26 6 64
/27 255.255.255.224 27 5 32
/28 255.255.255.240 28 4 16
/29 255.255.255.248 29 3 8
/30 255.255.255.252 30 2 4

Important: /24 does not mean 24 devices. It means 24 network-prefix bits.

A /16 generally contains more addresses than a /24, because it leaves more bits available for host addresses.

1.3 Calculating Addresses

For IPv4:

  • Network bits = prefix length
  • Host bits = 32 − prefix length
  • Total addresses = 2^(host bits)

For a conventional IPv4 subnet:

  • Usable host addresses = 2^(host bits) - 2

The two normally excluded addresses are:

  1. Network address — identifies the subnet.
  2. Broadcast address — addresses all hosts on that IPv4 subnet.

This subtraction rule has exceptions, notably /31 point-to-point links and /32 host routes.

Example: 192.168.1.50/24

The prefix is /24, so there are 8 host bits.

Address type Address
Network address 192.168.1.0
First usable host 192.168.1.1
Example device 192.168.1.50
Last usable host 192.168.1.254
Broadcast address 192.168.1.255

Yes, 192.168.1.0 is the first numerical address in this subnet. However, it is reserved as the network address under conventional subnetting and is not normally assigned to an ordinary host.

The subnet contains 256 total addresses and normally supports 254 usable host addresses.

1.4 Private and Public Addresses

Private IPv4 ranges

The three major private IPv4 ranges are:

Range CIDR
10.0.0.0 – 10.255.255.255 10.0.0.0/8
172.16.0.0 – 172.31.255.255 172.16.0.0/12
192.168.0.0 – 192.168.255.255 192.168.0.0/16

Private addresses are intended for private networks and are not globally routed as public destination addresses across the Internet.

Examples:

  • 192.168.1.10 — private
  • 10.20.30.40 — private
  • 172.20.5.4 — private
  • 172.40.5.4 — not in the private 172.16.0.0/12 range

Placement trap: Not every address beginning with 172 is private. The second octet must be between 16 and 31, inclusive, for this private range.

Public IPv4 addresses

Public IPv4 addresses are globally usable according to Internet addressing and routing policies.

A private device can access public Internet services through a suitable routing arrangement, commonly using NAT at a network gateway.

However, private addressing and NAT are separate concepts: NAT is not inherently required for two privately addressed networks to communicate if routing is configured appropriately.

1.5 Same or Different Subnet

The prefix length determines how the address space is divided into subnets.

Example A: /24

  • 192.168.1.10/24
  • 192.168.1.20/24

Both belong to 192.168.1.0/24, so they are in the same IP subnet.

Example B: /24

  • 192.168.1.10/24
  • 192.168.2.20/24

These belong to different subnets:

  • 192.168.1.0/24
  • 192.168.2.0/24

Example C: /16

  • 192.168.1.10/16
  • 192.168.2.20/16

Both belong to 192.168.0.0/16, so they are in the same IP subnet under these prefix settings.

Important: Being in the same subnet does not guarantee connectivity. VLAN configuration, physical connectivity, firewall rules and other network settings can still prevent communication.

1.6 Remote Destination Delivery

Suppose your laptop has IP 192.168.1.10/24 and wants to contact 8.8.8.8.

The destination is outside the laptop's local subnet.

The laptop normally sends the packet to its default gateway.

In the first Ethernet frame:

  • Source MAC = laptop's MAC address
  • Destination MAC = router's LAN-interface MAC
  • Destination IP = 8.8.8.8

The IP destination identifies the final destination, while the Ethernet destination MAC identifies the next recipient on the current link.

As the packet crosses routers, the Layer 2 frame is replaced for each outgoing link. The IP destination normally remains unchanged unless a mechanism such as NAT modifies it.


2. IPv4 Subnetting

2.1 What is Subnetting

Subnetting divides a larger IP address block into smaller logical networks called subnets.

Each conventional IPv4 subnet has its own:

  • Network address
  • Usable host-address range
  • Broadcast address

Subnetting helps organize networks, manage address allocation, and separate network segments.

2.2 Three Key Addresses

For a conventional IPv4 subnet:

  1. Network address: The first numerical address in the subnet.
  2. Usable host addresses: Addresses normally assignable to interfaces.
  3. Broadcast address: The final address in the subnet.

Example: 192.168.1.64/26

  • Network: 192.168.1.64
  • Usable range: 192.168.1.65–192.168.1.126
  • Broadcast: 192.168.1.127

The address 192.168.1.128 belongs to the next /26 subnet.

2.3 Subnetting Formulas

For an IPv4 prefix /p:

  • \(\text{Host bits} = 32 - p\)
  • \(\text{Total addresses} = 2^{32-p}\)

For conventional subnets:

  • \(\text{Usable hosts} = 2^{32-p} - 2\)

Examples:

Prefix Host bits Total addresses Usable hosts
/24 8 256 254
/25 7 128 126
/26 6 64 62
/27 5 32 30
/28 4 16 14
/29 3 8 6
/30 2 4 2

Every time the prefix increases by one bit, the address count is halved.

For example:

  • /25: 128 total addresses
  • /26: 64 total addresses
  • /27: 32 total addresses

2.4 Block Size Method

For many basic subnetting questions, the block-size method is the quickest approach.

When the subnet boundary is within an octet, calculate:

  • \(\text{Block size} = 256 - \text{mask value in that octet}\)

Examples:

Prefix Mask in final octet Block size
/25 128 128
/26 192 64
/27 224 32
/28 240 16
/29 248 8
/30 252 4

For a /26, the subnet boundaries within a /24 are:

.0, .64, .128, .192

For a /27:

.0, .32, .64, .96, .128, .160, .192, .224

For a /28:

.0, .16, .32, .48, .64, .80, .96, .112, .128, .144, .160, .176, .192, .208, .224, .240

The boundaries are the starting network addresses of the subnets.

2.5 Worked Example: 192.168.1.77/26

Step 1: Find the mask.

/26 corresponds to 255.255.255.192.

Step 2: Find the block size.

  • \(256 - 192 = 64\)

Step 3: List the subnet boundaries.

.0, .64, .128, .192

Step 4: Find where .77 belongs.

Since .77 is between .64 and .127, it belongs to the subnet starting at .64.

Step 5: Calculate the range.

Property Result
Network 192.168.1.64
First usable 192.168.1.65
Last usable 192.168.1.126
Broadcast 192.168.1.127
Total addresses 64
Usable hosts 62

Important boundary correction

The next boundary after .128 is .192, so:

  • Subnet starting at .128 ends at .191.
  • .191 is its broadcast address.
  • .192 starts the next subnet.

The next subnet's network address is not included in the previous subnet.

2.6 Worked Example: 192.168.1.77/27

Step 1: /27 means mask 255.255.255.224.

Step 2: Block size is 256 − 224 = 32.

Step 3: Boundaries are .0, .32, .64, .96, .128, .160, .192, .224.

Step 4: .77 falls in the .64–.95 block.

Results:

  • Network: 192.168.1.64
  • First usable: 192.168.1.65
  • Last usable: 192.168.1.94
  • Broadcast: 192.168.1.95
  • Total addresses: 32
  • Usable hosts: 30

2.7 Worked Example: 192.168.5.150/27

The block size is 32.

The relevant subnet boundaries are .128 and .160.

Since .150 lies between .128 and .159:

  • Network: 192.168.5.128
  • First usable: 192.168.5.129
  • Last usable: 192.168.5.158
  • Broadcast: 192.168.5.159
  • Usable hosts: 30

2.8 Worked Example: /29

Consider 192.168.1.0/29.

Host bits:

  • \(32 - 29 = 3\)

Total addresses:

  • \(2^3 = 8\)

Usable hosts:

  • \(2^3 - 2 = 6\)

The subnet is:

  • Network: 192.168.1.0
  • Usable: 192.168.1.1–192.168.1.6
  • Broadcast: 192.168.1.7

The next /29 subnet begins at 192.168.1.8 and ends at 192.168.1.15.

2.9 Choosing a Subnet Size

Suppose a subnet needs to support 100 hosts.

Choose the smallest number of host bits \(h\) that satisfies:

\[ 2^h-2 \geq 100 \]

Try 6 host bits:

  • \(2^6 - 2 = 62\)

Not enough.

Try 7 host bits:

  • \(2^7 - 2 = 126\)

Enough.

Therefore:

  • \(\text{Prefix} = 32 - 7 = /25\)

A /25 provides 126 usable host addresses.

Similarly, 50 hosts require a /26, because it provides 62 usable addresses. A /27 provides only 30, which is insufficient.

2.10 Dividing Into Equal Subnets

Suppose you want to divide a /24 network into four equal subnets.

The number of bits to borrow is determined by:

  • \(2^b \geq \text{required number of subnets}\)

For four subnets:

  • \(2^2 = 4\)

Borrow 2 bits from the host portion:

  • \(/24 + 2 = /26\)

The four resulting subnets are:

Subnet Network Usable range Broadcast
1 .0/26 .1–.62 .63
2 .64/26 .65–.126 .127
3 .128/26 .129–.190 .191
4 .192/26 .193–.254 .255

To create at least eight equal subnets from a /24, borrow three bits and use /27.

Number of equal subnets New prefix
2 /25
4 /26
8 /27
16 /28

2.11 Subnetting Placement Traps

  • /26 means 26 network bits, not 26 hosts.
  • A /26 has 64 total addresses and normally 62 usable hosts.
  • A /27 has 32 total addresses and normally 30 usable hosts.
  • Network and broadcast addresses are not normally assigned to ordinary hosts.
  • The broadcast address is one less than the next subnet boundary.
  • When calculating the network address, use the subnet prefix, not just the first three octets.
  • Two IP addresses are in the same subnet only if their network prefixes match.
  • The conventional minus-two host formula has exceptions for /31 and /32.

3. Routing Fundamentals

3.1 What is Routing

Routing is the process of determining how packets should travel from a source network toward a destination network.

Routers use routing information to select a next hop or outgoing interface.

A router generally makes its forwarding decision using the packet's destination IP address.

Switch vs router

Feature Layer 2 switch Router
Primary forwarding information Destination MAC Destination IP
Main role Forward frames within a Layer 2 network Forward packets between IP networks
Main data structure MAC address table Routing/forwarding tables
Typical scope LAN/VLAN Different IP networks

A Layer 3 switch can also route packets. The distinction above describes the typical roles of a Layer 2 switch and a router.

3.2 Routing Table

A routing table stores routes that help a router determine how to reach destination networks.

Simplified example:

Destination prefix Route type Next hop
192.168.1.0/24 Directly connected Local interface
10.0.0.0/8 Learned/configured route Router A
172.16.0.0/16 Learned/configured route Router B
0.0.0.0/0 Default route Upstream router

A directly connected route refers to a network attached to one of the router's interfaces.

A default route is used when no more specific matching route is available and the default route is configured.

3.3 Longest Prefix Match

Longest Prefix Match is one of the most important routing concepts for placements.

When several routes match the destination IP, a router normally selects the matching route with the longest prefix—the most specific route.

Consider these routes:

Destination prefix Next hop
10.0.0.0/8 Router A
10.1.0.0/16 Router B
10.1.2.0/24 Router C
0.0.0.0/0 Router D

Example 1: Destination 10.1.2.55

This address matches:

  • 10.0.0.0/8
  • 10.1.0.0/16
  • 10.1.2.0/24
  • 0.0.0.0/0

The router selects /24, which is the longest matching prefix.

Selected next hop: Router C.

Example 2: Destination 10.1.8.20

This address matches:

  • 10.0.0.0/8
  • 10.1.0.0/16
  • 0.0.0.0/0

It does not match 10.1.2.0/24.

The router selects /16.

Selected next hop: Router B.

Key rule

A longer prefix is more specific, not necessarily a physically shorter path.

Longest Prefix Match is a forwarding decision based on the destination prefix. Route selection among competing routes to the same prefix involves additional factors, such as route preference and metrics.

3.4 Default Route

The default IPv4 route is:

0.0.0.0/0

It has a prefix length of zero and matches every IPv4 destination. Because more specific routes take precedence under Longest Prefix Match, it is used when no more specific matching route is selected.

Example: A home router may send traffic for unknown public destinations to the ISP's upstream router.

If no suitable route or default route exists, the router generally drops the packet and may return an ICMP Destination Unreachable message.

3.5 Destination vs Next-Hop IP

Suppose a packet is going to:

8.8.8.8

Its next hop is:

192.168.1.1

These are different concepts:

  • Destination IP: 8.8.8.8 — the final destination.
  • Next-hop IP: 192.168.1.1 — the router to which the packet is sent next.

The router does not normally replace the destination IP with the next-hop IP. It uses the next hop to determine how to forward the packet.

The Ethernet frame on the local link uses the next-hop device's MAC address.

This distinction is fundamental to understanding ARP and routing together.

3.6 Static vs Dynamic Routing

Static routing

Static routes are manually configured by an administrator.

Advantages:

  • Predictable and straightforward.
  • Useful for small or stable networks.
  • No routing-protocol exchange is required to learn that route.

Limitations:

  • Requires manual maintenance.
  • Does not automatically adapt to every topology change or failure unless additional tracking, backup routes, or other mechanisms are configured.

Dynamic routing

Dynamic routing uses protocols to exchange routing information and calculate or select routes.

Examples:

  • RIP
  • OSPF
  • BGP

Advantages:

  • Can adapt to topology changes.
  • Reduces the need to configure every route manually.
  • Useful for larger or changing networks.

Dynamic routing is not instantaneous. After a change, routers may need time to exchange information and converge on updated routes.

3.7 Routing Table vs Forwarding Table

The terms are related but not identical in the usual conceptual model.

  • Routing table: Maintains route information, potentially learned from connected networks, static configuration and routing protocols.
  • Forwarding table: Contains the information used to make packet-forwarding decisions, such as the appropriate outgoing interface and next-hop information.

Implementations vary, and the routing information base and forwarding information base are often described as RIB and FIB, respectively.

A router may use the routing table to select routes and install the resulting forwarding information into the forwarding table.

3.8 Equal-Cost Multi-Path

Sometimes multiple routes to the same destination have equal cost.

A router may use Equal-Cost Multi-Path to forward traffic across multiple eligible paths instead of selecting only one.

Example:

  • Path A: cost 10
  • Path B: cost 10

If the router and routing configuration support ECMP, both paths may be used.

This is different from Longest Prefix Match: LPM selects the most specific matching prefix, while ECMP can distribute traffic among multiple eligible equal-cost paths.


4. Routing Protocols

Routing protocols help routers exchange routing information and choose routes.

The three protocols to recognize are RIP, OSPF and BGP.

4.1 RIP

RIP is a distance-vector routing protocol.

It uses hop count as its routing metric.

A hop is a router traversed along the route.

Important facts:

  • Maximum usable hop count: 15.
  • A metric of 16 represents an unreachable destination.
  • Relatively simple, but limited in scalability.
  • Historically important; generally less suitable for large modern enterprise networks than more capable protocols.

Example

Suppose a destination can be reached through:

  • Route A: 2 hops
  • Route B: 4 hops

RIP normally prefers Route A because it has the lower hop count.

Trap: RIP counts hops, not the actual transmission delay or bandwidth of every link.

4.2 OSPF

OSPF is a link-state routing protocol.

Routers exchange link-state information, build a view of the network topology, and calculate shortest paths using a cost metric.

Important facts:

  • Link-state protocol.
  • Uses cost rather than simply counting router hops.
  • Uses a Shortest Path First algorithm.
  • Supports hierarchical areas, including Area 0 as the backbone area.
  • Commonly used within an organization or autonomous system.

Example: fewer hops does not always win

Suppose there are two possible routes:

Route Hops Total OSPF cost
Route A 2 100
Route B 3 30

OSPF can prefer Route B because it has the lower total cost, despite having more hops.

The exact cost depends on the configured metric and implementation.

Trap: OSPF does not simply choose the route with the fewest routers.

4.3 BGP

BGP is a path-vector routing protocol and is central to routing between autonomous systems on the Internet.

An autonomous system (AS) is a collection of networks under a common routing administration and policy.

BGP exchanges reachability information between autonomous systems and uses path attributes and routing policies to select routes.

Important facts:

  • Path-vector protocol.
  • Used for inter-domain routing.
  • Uses AS-PATH and other attributes.
  • Route selection is policy-driven.
  • Does not simply select the route with the fewest routers.

What is AS-PATH

AS-PATH records the autonomous systems a route has traversed.

Suppose a route has AS-PATH:

100 → 200 → 400

This indicates that the route advertisement has traversed those ASes.

AS-PATH helps with route selection and loop prevention. BGP normally rejects routes containing the local AS in the AS-PATH when appropriate, preventing common inter-AS routing loops.

Does BGP always choose the shortest AS-PATH

No.

Suppose two routes are advertised:

  • Route A: 100 → 200 → 400
  • Route B: 100 → 300 → 250 → 400

Route A has fewer AS hops. However, BGP route selection depends on policy and path attributes, so the shorter AS-PATH does not guarantee that Route A wins.

For example, LOCAL_PREF is an important attribute: a higher value is generally preferred within the relevant BGP decision context, assuming earlier decision criteria have not already determined the result.

Other attributes and configuration can also influence route selection.

4.4 Internal vs External BGP

Two useful terms:

  • eBGP: BGP sessions between different autonomous systems.
  • iBGP: BGP sessions between routers in the same autonomous system.

BGP is used extensively between ISPs and other independently administered networks. It can also distribute external routing information within an organization through iBGP.

OSPF is commonly used for internal routing within an organization, while BGP handles routing between autonomous systems. This is a common deployment pattern, not an absolute rule.

4.5 RIP vs OSPF vs BGP

Feature RIP OSPF BGP
Protocol type Distance vector Link state Path vector
Main metric/selection basis Hop count Cost and shortest-path calculation Path attributes and policy
Maximum usable hop count 15 No RIP-style 15-hop limit No RIP-style 15-hop limit
Typical scope Small/legacy networks Internal routing Inter-AS routing; also internal BGP
Key concept Simplicity Topology and shortest paths AS-PATH and policy
Common interview association Hop count Link-state algorithm Internet routing

Key comparison to remember

  • RIP asks, conceptually: How many hops?
  • OSPF asks, conceptually: Which path has the best total cost?
  • BGP asks, conceptually: Which advertised route is best according to attributes and routing policy?

4.6 Route Selection vs Forwarding

Don't confuse these steps:

  1. A routing protocol learns or advertises route information.
  2. The router evaluates candidate routes and selects preferred routes.
  3. The selected routes inform the forwarding table.
  4. The forwarding plane uses the destination IP to forward packets.

Routing protocols do not need to be consulted from scratch for every packet. Packet forwarding normally uses the installed forwarding information.


5. ARP and RARP

5.1 Why ARP is Needed

Suppose Laptop A wants to send data to a device with IPv4 address:

192.168.1.20

Laptop A knows the destination IP, but it does not know the destination MAC address.

On an Ethernet LAN, the sender needs the appropriate destination MAC address to construct a frame for local delivery.

ARP — Address Resolution Protocol — discovers the MAC address associated with a known IPv4 address on the local link.

5.2 How ARP Works

Suppose:

Device IP address MAC address
Laptop A 192.168.1.10 AA-AA
Laptop B 192.168.1.20 BB-BB

Laptop A wants to contact Laptop B.

Step 1: Check the ARP cache

Laptop A first checks whether it already has a valid mapping for 192.168.1.20.

If the mapping exists, it may not need to send a new ARP request.

Step 2: Broadcast an ARP request

If the mapping is missing, Laptop A sends a broadcast ARP request:

"Who has 192.168.1.20? Tell 192.168.1.10."

The Ethernet destination MAC for the request is normally the broadcast address:

FF:FF:FF:FF:FF:FF

Step 3: Receive an ARP reply

Laptop B recognizes its IP address and sends an ARP reply containing its MAC address.

The reply is typically unicast to Laptop A.

Step 4: Cache the mapping

Laptop A stores the mapping and can use it when constructing subsequent frames.

ARP cache entries are temporary and can expire or be updated.

5.3 ARP for Remote Destinations

Suppose Laptop A wants to contact 8.8.8.8.

If 8.8.8.8 is outside the local subnet, Laptop A normally does not ARP for the remote server's MAC address.

Instead, it resolves the MAC address of its default gateway, if that mapping is not already cached.

For the first Ethernet frame:

  • Destination IP: 8.8.8.8
  • Destination MAC: default gateway's LAN-interface MAC

The router then forwards the packet toward the next hop.

At each routed Ethernet hop, the frame uses the appropriate local-link MAC addresses. ARP may be used to resolve the next-hop MAC on an Ethernet network.

5.4 ARP Cache and Gratuitous ARP

An ARP cache avoids repeatedly broadcasting requests for mappings that are already known.

A device may also send a Gratuitous ARP announcement or probe. Common uses include announcing an address-to-MAC mapping change, checking for an IPv4 address conflict, or helping update neighboring devices' ARP caches, depending on the implementation and use case.

Gratuitous ARP is a useful awareness-level topic for interviews.

5.5 RARP

RARP was historically designed for a device that knew its MAC address but needed to discover its own IPv4 address.

Protocol Known information Desired information
ARP IPv4 address Corresponding MAC address
RARP MAC address Own IPv4 address

RARP is now largely obsolete.

BOOTP and DHCP replaced its role with more capable configuration mechanisms.

5.6 DHCP Compared with RARP

DHCP can provide a device with:

  • An IPv4 address
  • A subnet mask or prefix information
  • A default gateway
  • DNS server information
  • Lease information and other configuration options

RARP was much more limited, primarily providing an IP address based on a hardware address.

5.7 ARP Placement Traps

  • ARP resolves IPv4 addresses to MAC addresses, not domain names.
  • ARP requests are typically Layer 2 broadcasts.
  • ARP replies are typically unicast.
  • Routers do not normally forward Ethernet ARP broadcasts across different networks.
  • A remote Internet server's MAC address is not used directly by your laptop.
  • ARP operates for local-link resolution; routing decides where the IP packet should go.
  • RARP is historical; DHCP is the modern configuration mechanism to know.

6. NAT

6.1 What is NAT

NAT translates selected IP address information as packets pass through a translating device.

A common use case is allowing devices with private IPv4 addresses to communicate with public Internet services through a router's public IPv4 address.

Example home network:

Device Private IP
Laptop 192.168.1.10
Phone 192.168.1.11
Tablet 192.168.1.12

The router has a public address, for example:

203.0.113.5

This is a documentation-only example address.

The router can translate outgoing traffic so the external server sees the public source address rather than the laptop's private address.

6.2 NAT vs Routing

  • Routing: Decides where a packet should be forwarded.
  • NAT: Changes selected address information as a packet passes through the translating device.

A router can perform both functions.

NAT is not required for every form of communication between private networks; properly configured routing can allow private networks to communicate without translation.

6.3 NAT/PAT Worked Example

Suppose:

  • Laptop IP: 192.168.1.10
  • Laptop source port: 51500
  • Router public IP: 203.0.113.5
  • Website IP: 93.184.216.34
  • Website port: 443

The laptop opens a TCP connection to the website.

Before translation

Field Value
Source IP 192.168.1.10
Source port 51500
Destination IP 93.184.216.34
Destination port 443

After PAT

For illustration, suppose the router maps the connection to public source port 62001.

Field Value
Source IP 203.0.113.5
Source port 62001
Destination IP 93.184.216.34
Destination port 443

The router maintains a mapping between the public-side connection and the internal connection.

Public-side mapping Internal connection
203.0.113.5:62001 192.168.1.10:51500

When the response returns to the mapped public address and port, the router consults its translation state and forwards the response to the corresponding internal device.

PAT may translate ports as well as addresses. This allows many internal connections to share one public IP.

6.4 Types of NAT

Static NAT

Static NAT uses a fixed one-to-one mapping between an internal address and a public address.

Example:

192.168.1.10 ↔ 203.0.113.10

A static mapping can be useful when an internal system needs a consistent public address.

Dynamic NAT

Dynamic NAT maps an internal address to an available public address from a configured pool.

Example public pool:

  • 203.0.113.10
  • 203.0.113.11
  • 203.0.113.12

The number of available public addresses can limit how many internal devices can be mapped simultaneously, depending on the configuration.

PAT — Port Address Translation

PAT allows multiple internal devices to share one public IP address by distinguishing their translated connections using transport-layer port information.

Example:

  • 192.168.1.10:5000 → 203.0.113.5:61001
  • 192.168.1.11:5000 → 203.0.113.5:61002

The internal devices can use the same source port because their translated mappings are distinct.

PAT is also commonly called NAT overload.

6.5 NAT and Port Numbers

Ports help distinguish application endpoints and transport connections.

A mapping may depend on the transport protocol, IP addresses and port numbers. The exact mapping behavior depends on the NAT implementation.

PAT does not mean every packet gets an entirely new arbitrary port. The router maintains mapping state so response traffic can be associated with the correct internal connection.

6.6 NAT vs Firewall

These are different functions.

NAT Firewall
Translates selected address information Filters traffic according to security rules
Can maintain translation mappings Can allow or deny traffic based on configured policy
Does not inherently provide complete security Provides traffic-control and security functionality

NAT may make some unsolicited inbound connections harder when no suitable mapping exists, but NAT is not a substitute for a properly configured firewall.

Explicit port forwarding or static mappings can allow inbound traffic to internal services.

6.7 Carrier-Grade NAT

Some ISPs place many customers behind another layer of NAT.

A typical path may be:

  1. Laptop with private IP
  2. Home router performing NAT
  3. ISP performing CGNAT
  4. Public Internet

This creates two translation layers.

CGNAT can make hosting services at home or accepting direct inbound connections difficult because the customer may not control the ISP's translation layer.

6.8 NAT Placement Traps

  • NAT is not the same as routing.
  • PAT commonly enables many devices to share one public IP.
  • Static NAT and dynamic NAT are not the same as PAT.
  • A firewall and NAT perform different functions.
  • NAT is not inherently required for all private-network communication.
  • A website normally sees the translated public source IP in a typical home NAT setup.
  • A NAT router must maintain suitable mappings for response traffic to reach the correct internal connection.

7. Important Comparisons

7.1 IP Address vs MAC Address

IP address MAC address
Network-layer logical address Link-layer address
Used for IP packet delivery across networks Used for local-link frame delivery
Routers use destination IP and routing information Ethernet switches use destination MAC information
Destination IP normally remains the same across routed hops unless translated Source and destination MAC addresses change across routed Ethernet hops

7.2 Routing vs Switching

Routing Switching
Primarily uses IP destination and routing information A Layer 2 switch uses destination MAC addresses
Connects IP networks Forwards frames within a Layer 2 network
Selects a next hop or outgoing interface Selects output port(s) using the MAC table

7.3 Static vs Dynamic Routing

Static routing Dynamic routing
Manually configured Learned and updated using routing protocols
Predictable and simple Can adapt to topology changes
Manual maintenance may be needed Requires protocol operation and convergence
Useful for stable/small networks Useful for larger/changing networks

7.4 RIP vs OSPF vs BGP

RIP OSPF BGP
Distance vector Link state Path vector
Hop count Cost Attributes and policies
Maximum usable hop count 15 SPF calculation AS-PATH and policy-driven selection
Small/legacy networks Common internal routing protocol Inter-AS routing; also iBGP internally

7.5 ARP vs RARP vs DHCP

Protocol Main purpose
ARP Resolve an IPv4 address to a MAC address on the local link
RARP Historically discover an IP address using a known MAC address
DHCP Obtain IP configuration, including an IP address and potentially gateway/DNS information

7.6 Static NAT vs Dynamic NAT vs PAT

Type Main behavior
Static NAT Fixed one-to-one address mapping
Dynamic NAT Maps through an available public-address pool
PAT Shares public address space using translated ports and connection mappings

8. Common Placement Traps

  1. A /24 does not mean 24 hosts. It means 24 network-prefix bits.
  2. A /16 contains more addresses than a /24. It has fewer network bits and more host bits.
  3. The network address is not normally assigned to an ordinary host.
  4. The broadcast address is the last address of a conventional IPv4 subnet.
  5. The next subnet's network address is not part of the previous subnet.
  6. A /26 has 64 total addresses and normally 62 usable hosts.
  7. A /27 has 32 total addresses and normally 30 usable hosts.
  8. A /29 has 8 total addresses and normally 6 usable hosts.
  9. Longest Prefix Match selects the most specific matching prefix.
  10. A default route is 0.0.0.0/0.
  11. Destination IP and next-hop IP are different concepts.
  12. Routing protocols are not consulted from scratch for every forwarded packet.
  13. RIP uses hop count, OSPF uses cost, and BGP uses path attributes and policies.
  14. RIP's maximum usable hop count is 15; 16 represents unreachable.
  15. OSPF can prefer a route with more hops if its total cost is lower.
  16. BGP does not always choose the route with the shortest AS-PATH.
  17. ARP resolves local-link IPv4-to-MAC mappings; it does not resolve domain names.
  18. A remote destination's MAC address is not used directly by the source laptop.
  19. RARP is historical; DHCP is the modern configuration mechanism to know.
  20. NAT translates address information; routing determines forwarding.
  21. PAT allows many internal connections to share a public IP using mapped ports.
  22. NAT does not provide the same functionality as a firewall.
  23. Private addressing does not inherently require NAT for communication between networks.
  24. Subnetting's conventional minus-two host rule has exceptions for /31 and /32.

9. Quick Revision Sheet

IP Addressing and Subnetting

  • \(\text{Host bits} = 32 - \text{prefix}\)
  • \(\text{Total addresses} = 2^{\text{host bits}}\)
  • \(\text{Usable hosts} = 2^{\text{host bits}} - 2\)

For conventional subnets, remember:

  • /24 → 256 total, 254 usable
  • /25 → 128 total, 126 usable
  • /26 → 64 total, 62 usable
  • /27 → 32 total, 30 usable
  • /28 → 16 total, 14 usable
  • /29 → 8 total, 6 usable
  • /30 → 4 total, 2 usable

Routing

  • Router → forwards IP packets between networks.
  • Layer 2 switch → forwards Ethernet frames using MAC addresses.
  • Longest Prefix Match → most specific matching route.
  • Default route → 0.0.0.0/0.
  • Static routing → manually configured.
  • Dynamic routing → uses routing protocols.
  • ECMP → multiple eligible equal-cost paths.

Routing Protocols

  • RIP → distance vector, hop count, maximum usable 15 hops.
  • OSPF → link state, cost, Shortest Path First, areas.
  • BGP → path vector, AS-PATH, route attributes, policies.
  • eBGP → between different autonomous systems.
  • iBGP → within the same autonomous system.

ARP and RARP

  • ARP → known IPv4 address to MAC address.
  • ARP request → normally Layer 2 broadcast.
  • ARP reply → typically unicast.
  • Remote destination → resolve the gateway's MAC, not the remote server's MAC.
  • RARP → historical MAC-to-IP discovery.
  • DHCP → modern IP configuration mechanism.

NAT

  • NAT → translates address information.
  • Static NAT → fixed one-to-one mapping.
  • Dynamic NAT → public address pool.
  • PAT → multiple devices share a public IP using port mappings.
  • Firewall → filters traffic according to security policy.
  • CGNAT → ISP performs another layer of NAT.

10. Final Level 3 Takeaway

The Network Layer is about delivering packets across IP networks.

  • IP addressing identifies interfaces and network prefixes.
  • Subnetting divides address space into smaller networks.
  • Routing determines the next hop for a destination.
  • RIP, OSPF and BGP provide different approaches to learning and selecting routes.
  • ARP resolves local-link MAC addresses needed to send frames.
  • NAT translates address information when required by the network design.

These concepts work together. A laptop identifies whether a destination is local, resolves the appropriate local MAC address using ARP when necessary, sends a frame to the destination or gateway, and relies on routers and their forwarding information to move the IP packet toward its destination.

Practice plan — later

We will handle the practice phase separately, as requested. That can include:

  • Subnetting numericals and address-range questions
  • Longest Prefix Match and routing-table problems
  • RIP/OSPF/BGP comparison MCQs
  • ARP and NAT packet-flow scenarios
  • Mixed placement questions and conceptual traps

For now, these are your consolidated Level 3 notes. We can move to Level 4 only when you explicitly say "nxt."