The Data Link Layer (Layer 2) is responsible for the transfer of data between two nodes on the same physical network segment. While the Network Layer deals with routing packets across the globe, the Data Link layer only cares about getting the data to the next immediate device (like from your laptop to your home router).
To achieve this, it must solve two major problems: how to divide the raw stream of 0s and 1s into meaningful blocks (Framing), and how to ensure those blocks weren't corrupted by electrical noise during transmission (Error Detection).
The Physical layer translates bits into signals and sends them over the wire. However, the receiver just sees a continuous stream of signals. It needs to know exactly where one message starts and where it ends.
The Data Link layer breaks the bit stream into discrete blocks called Frames. A frame consists of a Header (containing MAC addresses), the Payload (the IP Packet), and a Trailer (used for error detection).
01111110) is used to mark the beginning and end of a frame.
01111110 (six consecutive 1s), the sender guarantees that six 1s will never appear in the payload by automatically inserting a 0 after any sequence of five consecutive 1s in the data. The receiver automatically deletes any 0 that follows five 1s.Electrical interference, cosmic rays, or bad cables can easily flip a 0 to a 1 while the data is traveling over the wire. The Data Link layer uses mathematical techniques stored in the Frame Trailer to detect these errors.
The simplest error-detecting code. A single parity bit is added to the end of a block of data.
Used heavily by upper layers (TCP/IP). The data is divided into equal-sized segments (e.g., 16 bits). These segments are added together using one's complement arithmetic, and the sum is inverted to create the Checksum. The receiver performs the same addition; if the result is not all 1s, an error occurred.
The most powerful and widely used technique at the Data Link layer (used in Ethernet and Wi-Fi).