# Data Link Layer
## What is the Data Link Layer
The Data Link layer is the second layer of the OSI model. It provides reliable transmission of data frames between two directly connected nodes. While the Physical layer handles raw bits, the Data Link layer organizes those bits into structured units called frames and ensures they are delivered correctly between adjacent devices on the same network. The Data Link layer is responsible for error detection, flow control, and access control on the shared physical medium. This layer is divided into two sub-layers: the Logical Link Control sub-layer and the Media Access Control sub-layer.
## Logical Link Control Sub-layer
The Logical Link Control sub-layer is the upper portion of the Data Link layer. It provides an interface between the network layer above and the Media Access Control sub-layer below. The LLC sub-layer is responsible for flow control and error control on the data link. It identifies which network layer protocol is being carried within the frame, allowing multiple network layer protocols to share the same physical network.
## Media Access Control Sub-layer
The Media Access Control sub-layer is the lower portion of the Data Link layer. It controls how devices on a shared network medium determine when they can transmit. This is necessary because if multiple devices transmit simultaneously on a shared medium, their signals will collide and become garbled. The MAC sub-layer defines MAC addresses, which are the physical addresses used to identify devices within a local network. Each network interface card has a globally unique MAC address burned in by the manufacturer.
## Functions of the Data Link Layer
Framing is the process of dividing the stream of bits received from the physical layer into discrete units called frames. Each frame has a defined beginning and end, allowing the receiver to identify where one frame ends and the next begins. The Data Link layer adds header and trailer information to each frame. The header includes source and destination MAC addresses. The trailer typically includes error detection information.
Error detection allows the receiver to check whether a frame was damaged during transmission. The most common method is the Cyclic Redundancy Check, which the sender calculates and appends to the frame, and the receiver recalculates and compares. If the values do not match, the frame was damaged and is discarded.
Flow control prevents a fast sender from overwhelming a slow receiver by sending frames faster than the receiver can process them. The Data Link layer includes mechanisms for the receiver to tell the sender to slow down or pause.
Media access control determines which device is allowed to transmit at any given time when multiple devices share the same physical medium. CSMA/CD is used in Ethernet and CSMA/CA is used in wireless networks.
## Data Link Layer Devices
Switches are the primary devices operating at the Data Link layer. A switch learns the MAC addresses of devices connected to each of its ports by observing the source addresses of incoming frames. When a frame arrives destined for a known MAC address, the switch forwards it only to the correct port. Bridges are older devices that connect two network segments at the Data Link layer.
## MAC Addresses
A MAC address is a 48-bit hardware address written as 12 hexadecimal digits, usually separated by colons. The first 24 bits identify the manufacturer of the network interface card and are called the Organizationally Unique Identifier. The last 24 bits are assigned by the manufacturer to uniquely identify each card they produce. MAC addresses are used within a local network to identify devices. When data is routed between networks, MAC addresses change at each hop but IP addresses remain the same.Back to Subject