Data Link Layer
Data Link Layer
Before data reaches its destination on a network, it passes through several layers of processing. The Data Link Layer is the layer responsible for moving data reliably between two devices that share the same physical link — for example, your laptop and the Wi-Fi router next to it, or two switches connected by a cable.
Whether you're browsing a website, sending an email, streaming a video, or printing a document over a shared network, the Data Link Layer is working in the background to make sure the bits sent by one device actually arrive at the next device correctly and in order.
What Is the Data Link Layer?
The Data Link Layer is the second layer (Layer 2) of the OSI (Open Systems Interconnection) model. It sits between:
- The Network Layer (Layer 3) above it, which is concerned with getting data from a source to a destination across multiple networks (routing).
- The Physical Layer (Layer 1) below it, which is concerned with actually pushing raw bits onto a wire, fiber, or radio signal.
The Data Link Layer's job is narrower than the Network Layer's: it only handles the hop-by-hop transfer of data between two directly connected devices on the same physical link — not the entire end-to-end journey across the internet. A router forwarding a packet across five networks relies on five separate Data Link Layer "hops" to get it there, one link at a time.
Why Do We Need the Data Link Layer?
Think of shipping a package with a courier service:
- The Network Layer decides the overall route the package should take across cities.
- The Physical Layer is the literal road the delivery truck drives on.
- The Data Link Layer is the courier who properly packs the item, labels it, checks it isn't damaged, and hands it to the correct house on a specific street.
Without a Data Link Layer, several problems would occur on every network:
- Data could arrive corrupted, with no way to detect it.
- Frames could arrive out of order or get lost with no mechanism to notice.
- Two devices could transmit onto a shared medium at the same time and collide.
- A fast sender could overwhelm a slow receiver's buffer.
The Data Link Layer exists specifically to solve these local, link-level problems so that the layers above it can assume the link is reasonably trustworthy.
Frames: The Basic Unit of Layer 2
The Network Layer hands the Data Link Layer a packet. The Data Link Layer wraps that packet with additional control information to create a frame — the fundamental unit of data at Layer 2.
A typical frame has three parts:
| Part | Contains | Purpose |
|---|---|---|
| Header | Source MAC address, destination MAC address, control information | Identifies who sent the frame and who it's for |
| Payload | The actual packet from the Network Layer | The data being delivered |
| Trailer | Error-detection information (commonly a CRC value) | Lets the receiver check whether the frame arrived intact |
The process of wrapping a packet with a header and trailer to produce a frame is called framing, and it is the first of several services the Data Link Layer provides.
Sublayers of the Data Link Layer
The IEEE splits the Data Link Layer into two sublayers, each with a distinct responsibility:
1. Logical Link Control (LLC)
The LLC sublayer sits closer to the Network Layer and handles:
- Error notification
- Flow control
- Acknowledgments
- Link management
Because LLC is independent of the underlying hardware, it allows several different network-layer protocols to share the same physical medium without conflict.
2. Media Access Control (MAC)
The MAC sublayer sits closer to the Physical Layer and controls who gets to use the shared medium and when. Its responsibilities include:
- Physical (MAC) addressing
- Collision handling
- Channel access control
For example, when several computers share the same Ethernet segment or Wi-Fi channel, it is the MAC sublayer's job to decide which device transmits first and to handle the situation if two devices transmit at once.
Key Services of the Data Link Layer
1. Framing
As described above, framing divides a stream of data into manageable units. Suppose an application needs to send a 10 MB file. Rather than pushing it onto the wire as one uninterrupted 10 MB block, the Data Link Layer breaks it into many smaller frames. This has three practical benefits:
- Easier error detection — a corrupted frame only affects a small piece of data, not the whole transfer.
- Better data management — the receiver can process and acknowledge frames individually.
- Efficient transmission — the link can be shared more fairly among multiple senders.
2. Reliable Delivery
Some Data Link Layer protocols guarantee that a frame either arrives correctly or is retransmitted, using acknowledgments (ACKs) and retransmission logic. For example:
- The sender transmits a frame.
- The receiver does not send back an acknowledgment (perhaps the frame was lost).
- After a timeout, the sender retransmits the frame.
This basic ACK-and-retransmit pattern is the foundation of the Automatic Repeat reQuest (ARQ) techniques covered in more detail in the Data Link Control lesson.
3. Flow Control
If a fast sender transmits data faster than a slow receiver can process it, the receiver's buffer fills up and incoming frames start getting dropped. Flow control paces the sender so this doesn't happen — similar to pouring water into a bottle slowly enough that it doesn't overflow.
4. Error Detection
Physical media are never perfectly clean. Electrical noise, signal attenuation, and interference can all flip bits in transit. The Data Link Layer detects such changes using techniques including:
- CRC (Cyclic Redundancy Check)
- Parity checking
- Checksums
For example, if the transmitted pattern 10110110 is received as 10100110, one bit has silently flipped. An error-detection code computed by the sender and re-checked by the receiver reveals that something changed, even though the receiver has no way of knowing what the original data was supposed to be from the corrupted bits alone.
5. Error Correction
Detecting an error is not the same as fixing it. Some protocols go a step further and use redundant bits that let the receiver work out exactly which bit(s) were flipped and repair them without asking for a retransmission — for instance, using Forward Error Correction (FEC). This trade-off between simple detection and full correction is explored in depth in the Error Correction lesson.
6. Access (Medium) Control
On a shared medium — such as a wireless channel or a legacy shared Ethernet segment — multiple devices may want to transmit at the same time. The MAC sublayer decides:
- Which device is allowed to send
- When it is allowed to send
- How collisions are avoided or resolved
Wi-Fi devices, for example, follow a specific set of rules (listening before transmitting, waiting random backoff periods) before they put a frame on the air.
7. Duplex Modes
The Data Link Layer also governs whether two connected devices can talk in one direction at a time or both directions simultaneously.
| Mode | Description | Example |
|---|---|---|
| Half-Duplex | Both directions are possible, but only one device transmits at a time | Walkie-talkies: A → B or B → A, never both at once |
| Full-Duplex | Both devices can transmit and receive at the same time | Telephone calls: A ⇄ B simultaneously |
Functions of the Data Link Layer
Putting the services above together, the Data Link Layer's core functions are:
- Framing — packaging Network Layer packets into frames.
- Physical addressing — every device on a local network has a unique MAC address (for example,
00:1A:2B:3C:4D:5E), and the Data Link Layer uses these addresses to deliver a frame to the correct device on the link. - Error detection and recovery — detecting corrupted frames and triggering retransmission when needed.
- Flow control — keeping sender and receiver speeds compatible.
- Medium access control — preventing or resolving collisions on shared channels.
Devices That Operate at the Data Link Layer
Several common networking devices work primarily at Layer 2:
| Device | What It Does |
|---|---|
| Switch | Learns MAC addresses, forwards frames only to the port where the destination device lives, reduces collisions, and improves overall network performance. Commonly connects computers, printers, and servers in an office. |
| Bridge | Connects multiple LAN segments, filters traffic between them, reduces congestion, and improves efficiency — for example, separating a heavy-traffic area of a network from a quieter one. |
| Network Interface Card (NIC) | Gives a device its MAC address and physically sends and receives frames, connecting the device to the network. |
| Wireless Access Point (WAP) | Connects wireless devices to a wired network, manages wireless communication, and supports Wi-Fi standards. |
| Layer 2 Switch | A specialized switch that performs only Data Link Layer operations: maintaining MAC address tables, forwarding frames efficiently, and supporting VLANs. |
Common Data Link Layer Protocols
| Protocol | Description | Typical Use |
|---|---|---|
| Ethernet (IEEE 802.3) | The most widely used LAN protocol; uses MAC addressing and supports high-speed communication | Office and home wired networks |
| Token Ring | A special "token" circulates among devices; only the device holding the token may transmit | Reduces collisions in older LAN designs |
| FDDI (Fiber Distributed Data Interface) | Uses fiber-optic cabling for high-speed, long-distance, fault-tolerant communication | Campus and backbone networks |
| PPP (Point-to-Point Protocol) | Provides direct communication between two devices | Broadband connections, dial-up internet, WAN links |
| HDLC (High-Level Data Link Control) | A bit-oriented protocol offering error control, synchronization, and efficient framing | Point-to-point and multipoint WAN links |
| SDLC (Synchronous Data Link Control) | Developed by IBM as part of its network architecture; provides reliable, structured communication | IBM mainframe networking |
| SLIP (Serial Line Internet Protocol) | One of the earliest protocols for sending IP packets over serial links | Largely obsolete; lacked robust error handling and authentication |
| LCP (Link Control Protocol) | A component of PPP used to establish, configure, maintain, and terminate links | Part of the PPP connection lifecycle |
| LAP (Link Access Procedure) | A family of protocols derived from HDLC | Telecommunication networks |
| NCP (Network Control Protocol) | An early protocol used before TCP/IP became the standard | Historical — used in ARPANET |
Real-World Applications of the Data Link Layer
- Local Area Networks (LANs): Ethernet relies on the Data Link Layer for reliable communication between connected computers.
- Wi-Fi Networks: The Data Link Layer manages wireless communication and collision avoidance over the air.
- Network Switching: Switches use MAC addresses to forward frames to the correct port.
- Point-to-Point Connections: PPP enables direct communication between two devices, such as a router and an ISP.
- Data Centers: High-speed switches depend heavily on Data Link Layer mechanisms to move enormous volumes of frames with minimal delay.
Advantages and Limitations
| Advantages | Limitations |
|---|---|
| Provides reliable link-level communication | Works only between directly connected devices |
| Detects (and sometimes corrects) transmission errors | Cannot determine end-to-end routing across networks |
| Controls data flow between sender and receiver | Limited to local network communication |
| Reduces collisions on shared media | Performance depends heavily on the underlying hardware |
| Uses MAC addressing for accurate local delivery | |
| Supports efficient frame transmission |
Related Concepts
The Data Link Layer's services are implemented by more specific mechanisms covered elsewhere in this series:
- Data Link Control — a closer look at line discipline, flow control, and error control techniques such as ARQ.
- Error Detection — how techniques like parity, checksums, and CRC actually work.
- Error Correction — how techniques like Hamming Code and Forward Error Correction let a receiver fix errors without retransmission.
- Network Addressing — how the Network Layer above builds on Layer 2 addressing to route data across entire networks.