The Data Link Layer, Explained

UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 7.3 Free with a free account

The Data Link Layer

Introduction to Operating Systems · Chapter 7: Computer Networks: Architecture, Layers, and ProtocolsSection 7.3 · lesson 58 of 838 min · free with a free account

← The Seven-Layer OSI ModelNext lesson: The Network Layer and IP →

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 frames, MAC addresses, switches and CRCs move data one hop.

  • Describe the parts of an Ethernet frame and the role of MAC addresses
  • Explain how a switch learns MAC addresses and forwards frames
  • Compute even parity and a simple checksum, and explain where each fails
  • Explain why a CRC catches errors that parity and checksums miss, and how correction differs from detection

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,173 words). Read along, or search it.

Opening Puzzle

A Print Job Finds Its Printer

Sam, who runs a small online bakery, sends a print job from the laptop to the shop printer. A second later, a sheet slides out. But the shop network also holds a phone, a tablet, and the till. How does the job reach the printer, and nobody else? And what if electrical noise flips a 0 into a 1 on the way? The data link layer solves both problems, one hop at a time.

Scope

One Link at a Time

The data link layer, layer 2, moves data across one single link: from a laptop to a switch, or from one router to the next. It doesn't care where the data finally ends up. That's the network layer's job, in lesson 7.4. Think of a relay race. Each runner carries the baton only as far as the next runner.

Frame Structure

Header, Payload and Trailer

To do this, the layer packs the data into frames. A frame is a header, a payload, and a trailer. The header says who the frame is for, and who it's from: the destination and source hardware addresses, six bytes each. Then a two-byte type field. The payload is the packet from layer 3: on Ethernet, from forty-six to fifteen hundred bytes. And the trailer carries a four-byte check value, so the receiver can tell whether the frame arrived intact.

MAC Addresses

Hardware Names Versus IP Locations

Those hardware addresses are MAC addresses, short for Media Access Control. Most network cards get one at the factory. A MAC address is 48 bits, written as six bytes in hexadecimal, like this one, which the standards set aside for examples. The first three bytes name the maker of the card. The last three pick out the individual card. Software can change it, though, and many phones and laptops now give each Wi-Fi network a random, private one. Now compare an IP address, coming in lesson 7.4. The MAC names the card. The IP address says where the computer sits right now. Think of a person's name, versus their current mailing address.

How Switches Work

Learning Which Port Leads Where

Early shared networks sent every frame to every computer, and each card quietly ignored the frames meant for others. A switch does better. It has many ports, one for each device, and it keeps a table. It watches the source address of every frame that arrives, so it learns which MAC address sits behind which port. When a frame comes in, it reads the destination MAC, and sends the frame out of that one port only. If the destination isn't in its table yet, it sends the frame out of all the other ports, once. When that device sends something back, the switch learns where it sits. A switch reads only the frame header, so it's called a layer 2 device.

Quick Check

A Reply After a Switch Restart

Quick check. The shop's switch has just restarted, so its table is empty. A, on port 1, sends a frame to C, on port 3. Then C replies to A. Which ports does that reply go out of: ports 1, 2 and 4; only port 1; or all four ports? Pause, and decide. Only port 1. When A's frame came in on port 1, the switch read its source address, and learned that A sits behind port 1. So the reply has a known destination, and goes out of that port alone. Ports 1, 2 and 4 would be right only if the switch had never learned A.

Error Detection

Even Parity Catches One Flipped Bit

Now the second problem. Wires pick up noise, and radio is noisier still. Now and then, a bit flips. So the data link layer adds error detection: extra bits computed from the data, which the receiver computes again and compares. The simplest is a parity bit. With even parity, the sender adds one bit so the total number of 1s is even. The letter C is 1000011: three 1s. So the parity bit is 1, making four. If one bit flips on the way, the count turns odd, and the receiver knows something's wrong. But if two bits flip, the count is even again, and parity is fooled.

Stronger Checks

From Checksums to CRCs

A checksum is a bit smarter. Add up all the bytes, and keep the remainder after dividing by 256. The bytes of CAKE add up to 276, which leaves 20. Change one letter, to CAKF, and the sum becomes 21. The damage is caught. But changes can cancel out. In CBKD, one letter went up by one, and another went down by one. The sum is still 20, and the damage is missed. Real frames use a stronger check: a CRC, a cyclic redundancy check. It treats the data as one huge number, and divides it by a fixed value. The remainder depends on every bit, and on their order. Ethernet puts a 32-bit CRC in its 4-byte trailer. Worked out with Python's zlib on this Mac, all three words give completely different CRCs.

Quick Check

Catching Two Swapped Letters

Quick check. A frame carries the word BREAD. On the way, two letters swap places, and BRAED arrives. Which check notices: parity on each byte, the add-up checksum, or the CRC in the trailer? Pause, and decide. The CRC. A swap keeps every byte, so each byte's parity is unchanged, and so is the sum. Only the order differs. And the CRC depends on the order of the bits. BREAD and BRAED give completely different values, so the frame is thrown away.

Error Correction

Resending or Repairing Damaged Data

Detecting damage is half the story. A receiver that sees a bad CRC usually throws the frame away. A higher layer, transport, then gets the data sent again. Where resending is slow, like talking to a space probe, the sender adds enough extra bits to correct errors on the spot. The simplest correcting code sends each bit three times, and the receiver takes a vote. The message 1011 goes out as twelve bits. Noise flips one bit, so one group of three arrives as 010. The vote in that group still says 0, and the message is repaired. But that's twelve bits for four. Cleverer codes, like the well-known Hamming code, repair a single flipped bit with far fewer extra bits. And none of these checks stop someone who changes data on purpose. That takes cryptography, in lessons 7.5 and 8.7.

Real Example

A Noisy Link Near the Microwave

Back to Sam's shop. Later, the old Wi-Fi stick kept dropping the printer. So Sam called Ivy, who looks after the computers at a school. She checked the interface counters, and saw many frames discarded for bad checks. The link was noisy: every damaged frame failed its CRC. She moved the stick, on a USB extension cable, away from the microwave oven, and the discards stopped. So, both questions answered. MAC addresses and the switch steer each frame to the printer alone, and the CRC catches the noise.

Key Takeaways

Frames, Switches and Error Checks

To recap. The data link layer moves frames across one link at a time. A frame has a header with two MAC addresses, the packet, and a CRC trailer. A switch learns which MAC sits behind each port, and sends each frame out of one port. Parity and checksums catch some damage. A CRC catches far more, and a bad frame is dropped and sent again.

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 Data Link Layer

What is a MAC address?
A MAC address is a 48-bit hardware address that names a network card, written as six bytes in hexadecimal. The first three bytes identify the card's maker, and the last three pick out the individual card. Software can change it, and many phones and laptops now use a random private address for each Wi-Fi network. Unlike an IP address, it does not describe where a computer sits.
How does a network switch know where to send a frame?
A switch learns by reading the source MAC address of every frame that arrives and recording which port it came in on. When a frame arrives, the switch looks up the destination address and sends the frame out of that one port. If the destination is not in its table yet, it sends the frame out of every other port once, then learns from the reply.
What is the difference between parity, a checksum and a CRC?
All three detect transmission errors, but they differ in strength. Even parity adds one bit so the count of ones is even, which misses two flipped bits. A simple checksum adds the bytes and keeps the remainder after dividing by 256, which misses changes that cancel out. A CRC treats the data as a large number divided by a fixed value, so its remainder depends on every bit and their order.
How does error correction differ from error detection?
Error detection reveals that data was damaged, while error correction adds enough extra bits to repair it on the spot. Detection suits links where resending is cheap, since a bad frame is dropped and sent again. Correction suits links where resending is slow, such as talking to a space probe. The simplest correcting code sends each bit three times and takes a majority vote.

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 →