ByteByte CityCity
All lessons
OSI Model

Can Print, But No Websites? The Network Layer Explained | OSI Layer 3

7:17 Watch on YouTube

She can print. She can open files on the server down the hall. But no website loads, and the other office might as well be on the moon. Layer 1 is fine, Layer 2 is fine — so what gets data off the street and across the city? In this episode Professor Flows explains the Network layer using Byte City: the lawn sign is the IP address, the intersection is a router, the road atlas is its routing table, and the mail bag is the packet.

You'll learn

Chapters

  1. 0:00Everything down the hall works
  2. 0:31The lawn sign: IP addresses, street and house
  3. 1:41"Is it on my street?" and the default gateway
  4. 2:11The rule with no exceptions: the gateway MUST be on the same network
  5. 2:48Routers and the road atlas: the routing table
  6. 3:53The expiry stamp: TTL and routing loops
  7. 4:46The real names, and IPv6 in 40 seconds
  8. 5:27The real thing: ipconfig, the typo, tracert
  9. 6:14Exam corner
  10. 6:37Recap and next time

The written lesson

The problem: everything down the hall works

A user can print. She can open files on the server down the hall. But no website loads, and the other office might as well be on the moon.

The link light is green, so Layer 1 is fine. She can reach her neighbours, so Layer 2 is fine. Everything on her street works. Nothing beyond it does. So the problem is whatever gets data off the street and across the city. That is Layer 3 of the OSI model: the Network layer.

The lawn sign: IP addresses

A Byte City house with a lawn sign reading 192.168.1.10. A card above splits the address in two: 192.168.1 labelled The street and .10 labelled The house
An IP address is two addresses in one: part street, part house.

On a single street, houses are known by the brass plaque bolted to the wall: the MAC address. That can't work across a city, because a plaque tells you who a house is, not where it is.

So every house also has a lawn sign out front. That is its IP address: four numbers, each from 0 to 255.

An IP address is really two addresses in one. The first part names the street. The last part names the house on that street. The street sign on the corner tells you where the split is. A sign reading 192.168.1.0/24 means the first 24 bits, here the first three numbers, are the street. Whatever is left is the house. The street is the network, or subnet. Subnetting has lessons of its own; this is all you need for now.

One more difference. The plaque is stamped at the factory. The lawn sign is paint. Move the house to another street and you repaint the sign: new street, new number. That is why engineers call the MAC address a physical address and the IP address a logical one.

"Is it on my street?"

A diagram titled Is it on my street? comparing my address 192.168.1.10 with the destination 10.0.5.20 at the /24 split. The street parts differ, so the result reads Different street: crate it to the gate, the default gateway 192.168.1.1
Before it sends anything, a host compares the street part of the destination with its own.

Before a house sends anything, it asks one question: is this going to my street, or somewhere else?

It checks the street part of the destination against its own. If they match, the neighbour is local. The house rings the doorbells to learn the neighbour's plaque (that is ARP) and crates the data straight to that house.

If they don't match, the house doesn't even try. It crates the data to the gate at the end of the street. In a real network, that is the default gateway.

Remember what is inside that crate: the mail bag, with the real destination's lawn-sign number still on it. The crate says "to the gate". The bag says where the data is really going.

The rule with no exceptions

A diagram titled The gateway must be on the same network. The house 192.168.1.10 and the gate 192.168.1.1 share the same street part, so the result reads Same network, reachable
The default gateway MUST be on the same network as the host.

The default gateway MUST be on the same network as the house. Same street. No exceptions.

Here is why. The only way to hand over a crate is to ring the doorbells for a plaque, and doorbells only ring on your own street. A house at 192.168.1.10 can reach a gate at 192.168.1.1. It can never reach a gate at 192.168.2.1. A gateway on a different network is a gateway that doesn't exist.

Routers and the road atlas

A table titled The road atlas = the routing table. A mail bag addressed to 10.0.5.20 matches two rows, and the 10.0.5.0/24 row is lit in green beside a note reading Most specific row wins
The routing table lists streets, not houses. When two rows match, the more specific one wins.

At the gate, and at every intersection after it, the same thing happens. The crate is opened and thrown away. The mail bag comes out. And someone looks up the bag's destination in a road atlas.

The intersection is a router. The atlas is its routing table. The atlas is surprisingly small, because it doesn't list houses. It lists streets. For each street it says one thing: which exit to take, and who to hand the bag to next.

Street (destination)Send the bag...
192.168.1.0/24this street: exit A
192.168.2.0/24this street: exit B
10.0.5.0/24to the next intersection, 192.168.2.2
10.0.0.0/8the whole 10 district: to 192.168.2.9
everything else (0.0.0.0/0)that way: 192.168.2.254

If two rows both match, the more specific one wins. A bag for 10.0.5.20 matches the row for the exact street and the row for the whole district, and the exact street wins. Engineers call that longest prefix match.

At the bottom is the most important row of all: everything else goes that way. That is the default route. No router knows the whole city. Each one knows its own streets, and which neighbour to ask about the rest.

The rows get there in one of two ways. Somebody writes them by hand, which is static routing. Or the intersections tell each other what they can reach, which is dynamic routing.

Then the bag goes into a new crate with new plaques and leaves by the chosen exit.

The expiry stamp: TTL

A canvas mail bag at the gate with a large tag reading FROM 192.168.1.10, TO 10.0.5.20 and EXPIRES IN hops, with a round red stamp reading 64
The mail bag's tag: where it came from, where it is going, and an expiry stamp.

The mail bag is a packet, and its tag carries three things worth knowing. Where it came from. Where it is going. And an expiry stamp: a number, usually starting at 64 or 128.

Every intersection that handles the bag knocks one off the stamp. If the stamp ever reaches zero, the bag is destroyed on the spot, and a short note goes back to the sender saying so.

Why build in a self-destruct? Because atlases can be wrong. If two intersections each think the other one is the way, a bag would circle between them forever, and so would every bag after it. That is a routing loop. The expiry stamp guarantees that a lost bag eventually dies instead of clogging the city.

The stamp's real name is time to live: TTL. The notes routers send back are ICMP, the same system that ping uses.

The city ran out of lawn signs: IPv6

The city ran out of four-number lawn signs. There are only about four billion of them. The replacement is IP version 6: much longer addresses, written in hexadecimal, enough for every device we will ever build. Same idea, same layer, bigger numbers.

The real thing: ipconfig, the typo, tracert

A Command Prompt window. ipconfig shows IPv4 Address 192.168.1.10, Subnet Mask 255.255.255.0 and Default Gateway 192.168.1.11 highlighted, and ping 8.8.8.8 returns Destination host unreachable
Her gateway is set to .11. The real gateway is .1. One typo, and nothing leaves the street.

On Windows, ipconfig shows all three pieces: your lawn sign, the subnet mask (the street sign's split, written the long way) and your gate.

Back to our user. Her gate is set to 192.168.1.11. The real gate is 192.168.1.1. Somebody made a typo. Everything on her own street never needed the gate, so it all worked. Everything else was being crated to a house that doesn't exist. Fix one number, and the whole city opens up.

To watch Layer 3 work, run tracert. It sends bags with an expiry stamp of 1, then 2, then 3, so each intersection in turn destroys one and sends a note back. Those notes are the list you see: every router on the path, in order.

One for the Network+ exam. A host at 192.168.1.10/24 sends a packet to 10.0.5.20. Which destination MAC address is on the frame as it leaves the host? The default gateway's. The far house's MAC address never appears on her street. The bag carries the far address. The crate only ever carries the next stop.

Quick answers

What is an IP address?

The logical address of a host: four numbers from 0 to 255 in IPv4. Part of it names the network and the rest names the host on that network.

What does /24 mean in an IP address?

The first 24 bits, which is the first three numbers, name the network. The last number names the host. Written as a subnet mask, /24 is 255.255.255.0.

What is a default gateway?

The router a host sends to when the destination is not on its own network. It must have an address on the same network as the host, or the host can never reach it.

What is TTL in networking?

Time to live: a number in every packet that each router lowers by one. At zero the packet is destroyed and an ICMP message goes back to the sender, which stops packets circling forever in a routing loop.

Why can I reach local devices but not the internet?

Local traffic never uses the default gateway, so it keeps working when the gateway setting is wrong. Run `ipconfig` and check that the default gateway is the router's real address.

Key terms

IP address
—
the logical address on the lawn sign: part network, part host.
Subnet
—
one network, one street; the number after the slash says how much of the address names it.
Default gateway
—
the router at the end of the street, where a host sends everything that is not local.
Router
—
the Layer 3 device that reads a packet's destination and picks the next stop.
Routing table
—
the router's list of networks and where to send packets for each.
Default route
—
the last row of the routing table: everything else goes that way.
Packet
—
the Layer 3 wrapper, carrying the source and destination IP addresses.
TTL
—
time to live, lowered by one at every router so that a lost packet eventually dies.
Next: Ping Works, Page Won't Load: Ports, TCP and UDP | OSI Layer 4

Quick quiz

Five questions on this lesson. Pick an answer to see why.

  1. 1. A user reaches printers and servers on her own subnet but nothing remote. ipconfig shows 192.168.1.10, mask 255.255.255.0, gateway 192.168.5.1. What is wrong?
  2. 2. Which device forwards packets between networks using a routing table, and which address does it read to decide?
  3. 3. A router has routes for 10.0.0.0/8, 10.0.5.0/24 and a default route 0.0.0.0/0. A packet arrives for 10.0.5.20. Which route is used?
  4. 4. A router decrements a packet's TTL and the value reaches zero. What does the router do?
  5. 5. A technician runs tracert to a remote server and gets a list of every router on the path. How does tracert discover them?

Keep learning

Previous

Next

Thumbnail for Ping Works, Page Won't Load: Ports, TCP and UDP | OSI Layer 49:32
OSI Model

Ping Works, Page Won't Load: Ports, TCP and UDP | OSI Layer 4

Numbered doors, the truck that calls ahead and the bullhorn that doesn't.

9:32 Watch

Related

Thumbnail for What Happens When You Click a Link: All 7 OSI Layers in One Trip8:28
OSI Model

What Happens When You Click a Link: All 7 OSI Layers in One Trip

One click, seven floors down, across the city, and back. Every layer in one trip.

8:28 Watch

Related

Thumbnail for Slow PC After an Office Move? Physical Layer Explained | OSI Layer 14:59
OSI Model

Slow PC After an Office Move? Physical Layer Explained | OSI Layer 1

The road: copper, glass and radio, and what a dark link light means.

4:59 Watch

Exam objectives: CompTIA Network+ N10-009: 1.1 (OSI model), 1.4 (ICMP), 1.7 (IPv4 addressing, CIDR), 2.1 (routing: static, dynamic, default route), 5.5 (ipconfig, ping, tracert).

Byte City is not affiliated with or endorsed by CompTIA.