The main task of the data link layer is to transform a raw transmission facility into a line that appears free of undetected transmission errors to the network layer. It accomplishes this task by having the sender break up the input data into data frames (typically a few hundred or a few thousand bytes) and transmit the frames sequentially. If the service is reliable, the receiver confirms correct receipt of each frame by sending back an acknowledgement frame.
Another issue that arises in the data link layer (and most of the higher layers as well) is how to keep a fast transmitter from drowning a slow receiver in data. Some traffic regulation mechanism is often needed to let the transmitter know that how much buffer space the receiver has at .the moment. Frequently, this flow regulation and the error handling are integrated.
Broadcast networks have an additional issue in the data link layer: how to control access to the shared channel. A special sublayer of the data link layer, the medium access control sublayer, deals with this problem.
Headers and trailers are added, containing the physical addresses of the adjacent nodes, and removed upon a successful delivery.
This avoids overwriting on the receiver's buffer by regulating the amount of data that can be sent.
In LANs it decides who can send data, when and how much.
Headers have bits, which tell the receiver when a frame is arriving. It also contains bits to synchronize its timing to know the bit interval to recognize the bit correctly. Trailers mark the end of a frame, apart from containing the error control bits.
It checks the CRC to ensure the correctness of the frame. If incorrect, it asks for retransmission. Again, here there are multiple schemes (positive acknowledgement, negative acknowledgement, go-back-n, sliding window, etc.).
Finally, it is responsible for error free delivery of the entire frame/ packet to the next adjacent node (node to node delivery).