The Network Layer and IP, Explained

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

← 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 →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

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.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
A /24 network has 254 usable host addresses. The prefix leaves 8 bits for hosts, which gives 256 combinations, but the first address names the network itself and the last is the broadcast address. In 192.168.10.0/24, usable hosts run from 192.168.10.1 to 192.168.10.254. Splitting it into four /26 subnets gives 62 usable hosts in each.
What is longest prefix match in routing?
Longest prefix match is the rule that a router forwards a packet using the most specific routing table entry that fits its destination. If a table holds 10.0.0.0/8 and 10.1.0.0/16, a packet for 10.1.7.9 matches both but follows the /16 row, since 16 bits match rather than 8. The default route, 0.0.0.0/0, is used when nothing more specific fits.
What does TTL mean in an IP packet?
TTL, or time to live, is a counter in every IP packet that each router lowers by one. When it reaches zero, that router discards the packet and sends back an ICMP time exceeded message. TTL keeps a packet from looping forever when routing tables disagree. Traceroute uses it on purpose, sending packets with TTL 1, 2, 3 and so on to reveal each router along the path.
How do IP addresses and MAC addresses work together when a packet crosses routers?
The IP address names the final destination and normally stays the same for the whole trip, while the MAC address names only the next hop and changes at every router. Think of the IP address as the address on a parcel and the MAC address as the driver for one leg of the journey. Each router wraps the packet in a new frame for the next link.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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

Introduction to Operating Systems
3 credits · NCCRS
Enroll →