UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 7.4 Free with a free account
The Network Layer and IP
Introduction to Operating Systems · Chapter 7: Computer Networks: Architecture, Layers, and ProtocolsSection 7.4 · lesson 59 of 838 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: The Presentation Layer →← The Data Link LayerNext lesson: The Presentation Layer →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
How IP addresses, prefixes and routers move packets hop by hop.
- Split an IPv4 address into network and host parts using its prefix
- Count usable host addresses in a subnet and check whether an address belongs to it
- Explain how routers choose a path using the longest matching prefix and the default route
- Describe how TTL and ICMP support ping and traceroute
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,026 words). Read along, or search it.
Opening Scene
No Post Office Knows the Whole Route
Sam, who runs a small online bakery, mails a box of cupcakes to a customer in another state. No single post office knows the whole route. Each one reads the address, picks a direction that gets closer, and hands the box on. The network layer works the same way. So how does a packet reach a machine across the world, when no router knows the whole map?
IPv4 Addresses
Four Bytes Separated by Dots
The network layer, layer 3, gets a packet from one machine to another, possibly across many networks. For that, every machine needs an address that says where it sits. That's the IP address. In IPv4, the older and still very common version, it's 32 bits long. People write it as four numbers from 0 to 255, separated by dots. Each number is one byte. Take 192.168.10.25. Here's each of its bytes as eight bits.
Network and Host
What a Prefix Like /24 Means
An address has two parts. The network part is the same for every device on one network, like a street name. The host part picks out one device on that network, like a house number. A prefix, like slash 24, says how many of the 32 bits belong to the network part. Here, 24 bits name the network. That leaves 8 bits for hosts: 2 to the 8th, or 256 combinations.
Worked Example
Inside the 192.168.10.0/24 Network
This address sits on the network 192.168.10.0/24: a private range, kept for use inside homes, shops and schools, never on the public Internet. Its netmask, 255.255.255.0, is just 24 ones, then 8 zeros. The first address, dot 0, names the network itself. The last, dot 255, is the broadcast address: a message to everyone on it. That leaves 254 usable host addresses, from dot 1 to dot 254. And a neighbor-looking address can be a stranger. 192.168.11.25 is on a different network, so reaching it takes a router. A network can also be split. Borrow two host bits, and one slash 24 becomes four slash 26 subnets, with 62 usable hosts each. By the way, IPv4 has only about 4.3 billion addresses in all. Its successor, IPv6, uses 128-bit addresses.
Quick Check
Which Address Is on the Cafe Network
Quick check. A cafe's guest Wi-Fi uses the network 10.20.30.0/24. Which of these addresses is inside it: 10.20.31.30, 10.2.30.30, or 10.20.30.250? Pause, and decide. 10.20.30.250. With slash 24, the first three numbers must match: 10, 20, 30. And 250 is a valid host, between 1 and 254. 10.20.31.30 looks close, but its third number differs, so it sits on another network. And 10.2.30.30 differs in the second number.
Routing
Routing Tables and the Default Route
To reach another network, a packet goes through a router: a machine that joins two or more networks, and forwards packets between them. Ivy, who looks after the computers at a school, runs two networks there: one for the office, and one for the computer lab. The office is 192.168.10 dot anything. The lab is 192.168.20 dot anything. One router joins them, and also leads out to the Internet. For each packet, the router reads the destination IP address, looks it up in its routing table, and sends the packet out of the matching port. When several rows match, it picks the most specific one: the longest prefix. The row 0.0.0.0/0 matches everything. It's the default route: if you know nothing better, send it to the next router. Every router decides with its own table, one hop at a time. None of them needs to know the whole Internet.
Quick Check
The Longest Prefix Wins
Quick check. A router's table has three rows. 10.0.0.0/8 goes out of port A. 10.1.0.0/16 goes out of port B. And there's a default route. A packet arrives for 10.1.7.9. Where does it go: port B, port A, or the default route? Pause, and decide. Port B. The address matches all three rows, but slash 16 is the longest prefix: sixteen bits match, not just eight. Port A is tempting, since its row matches too. But a router always takes the most specific match, and uses the default route only when nothing else fits.
Two Addresses
IP for the Destination, MAC for the Hop
On a trip across many networks, every packet carries two kinds of address. The IP address names the final destination, and it stays the same all the way. The MAC address, from lesson 7.3, names only the next hop, so it changes at every router. IP is the address on the parcel. MAC is the truck driver for this one leg.
Time to Live
TTL Stops Packets Going in Circles
What if tables disagree, and a packet goes round in a circle? To stop that, every packet carries a TTL: a time to live. It's a counter, and every router lowers it by one. When it reaches zero, that router throws the packet away. Say a packet leaves with TTL 4. Router 1 makes it 3, router 2 makes it 2, router 3 makes it 1, and router 4 makes it 0, and drops it. The router that drops it sends back a short report, using ICMP, the Internet Control Message Protocol: time exceeded. ICMP carries the network layer's other problem reports too, like destination unreachable.
Diagnostic Tools
Ping and Traceroute Use ICMP
You can use ICMP on purpose. Ping sends an echo request and waits for the echo reply: is that machine reachable, and how long is the round trip? Traceroute sends packets with TTL 1, then 2, then 3. Each router that drops one answers time exceeded, so the replies list the routers on the path, in order.
Real Example
A Laptop With No Default Route
Back to Sam's box of cupcakes. No post office knew the whole route, and no router does either. Each one reads the destination address, picks the best row in its own table, and passes the packet one hop closer. That's why one setting matters so much. Last week, a laptop in Ivy's lab could reach the lab printer, but nothing outside the lab. It had no default route, so it had nowhere to send packets for other networks. Ivy set the router as its gateway, and everything came back.
Key Takeaways
Addresses, Prefixes, Routers and TTL
To recap. An IPv4 address is 32 bits: a network part and a host part, split by the prefix. A slash 24 network has 254 usable hosts, between the network address and the broadcast. Routers forward packets hop by hop, using the longest matching prefix, or the default route. And TTL stops wandering packets, while ICMP reports the problems back.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About The Network Layer and IP
How many usable hosts are in a /24 network?
What is longest prefix match in routing?
What does TTL mean in an IP packet?
How do IP addresses and MAC addresses work together when a packet crosses routers?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →