The data link layer is Layer 2 of the OSI model. It packages data from the network layer into frames, addresses them with MAC addresses, and delivers them between two devices on the same link or local network. On Ethernet and Wi-Fi, this is where your network card and your switch do their work.
It sits between the physical layer, which turns bits into signals on a cable or radio, and the network layer, which handles IP addresses and routing. The data link layer only cares about the next hop, never the whole trip.
What does the data link layer do?
Four jobs, all limited to one link:
- Framing. It wraps each chunk of data in a header and trailer, so the receiver knows where a unit starts and ends.
- Local addressing. Each frame carries a source and a destination MAC address, which identify network interfaces on that local network.
- Error detection. A checksum in the trailer lets the receiver notice that bits were damaged in transit.
- Access control. When several devices share a medium, rules decide who may send and when. The IEEE 802.3 standard defines the media access control (MAC) sublayer for Ethernet, covering both shared-medium (half-duplex) and full-duplex operation.
For what the address itself is and how to find yours, see What Is a MAC Address?.
What is inside an Ethernet frame?
Ethernet is by far the most common data link technology on wired networks. An Ethernet II frame has these fields, in order:
| Field | Size | Purpose |
|---|---|---|
| Destination MAC | 6 bytes | Interface that should receive the frame |
| Source MAC | 6 bytes | Interface that sent it |
| 802.1Q VLAN tag (optional) | 4 bytes | Marks the frame's VLAN and priority |
| EtherType | 2 bytes | Which protocol is in the payload |
| Payload | 46 to 1500 bytes | The network-layer packet, padded if short |
| Frame check sequence (FCS) | 4 bytes | CRC-32 error check |
On the wire, a 7-byte preamble and a 1-byte start frame delimiter come first so receivers can synchronise. Those belong to the physical layer, and your capture tool normally does not show them. RFC 894 gives the 46-byte minimum payload and the 1500-byte maximum IP datagram. The optional VLAN tag comes from a separate standard, IEEE 802.1Q, and is left out of the example below.
EtherType values
The EtherType tells the receiver what to hand the payload to. RFC 894 requires the value 0x0800 for IP. Two others you will meet constantly: 0x0806 for ARP and 0x86DD for IPv6.
Padding
If the data is shorter than 46 bytes, the sender pads it with zero bytes. RFC 894 says this padding is not part of the IP packet and is not counted in the total length field of the IP header, so the receiving IP layer can strip it off.
The frame check sequence
The FCS is a 32-bit cyclic redundancy check calculated over the addresses, the type field and the payload. The receiver repeats the calculation. If the result differs, the frame is dropped silently. The data link layer on Ethernet does not ask for a resend; TCP, further up, notices the missing data and retransmits it.
Example: reading the first 14 bytes of a frame
The destination, source and EtherType together take 14 bytes. Example bytes from a made-up ARP request:
ff ff ff ff ff ff 02 00 00 00 00 01 08 06
ff ff ff ff ff ffis the broadcast address. Every device on the local network accepts the frame.02 00 00 00 00 01is the sender. The02in the first byte sets the "locally administered" bit, which is typical of addresses that are not factory-assigned.08 06says the payload is an ARP message.
How does ARP connect IP addresses to MAC addresses?
Applications use IP addresses, but frames need MAC addresses. On IPv4, the Address Resolution Protocol (RFC 826) bridges the two. When a host has an IP address but no MAC address for it, it broadcasts a request to all stations on the cable, naming the target IP address. The host that owns that address replies directly to the requester with its MAC address. The sender stores the pair in a table so it does not have to ask again for every packet.
This only works on one local network. To reach an address outside your subnet, your computer sends the frame to the MAC address of the default gateway instead. The subnet mask decides which case applies, as described in Subnet Mask Explained.
How do frames travel across several hops?
A packet crossing the internet changes frames at every router. The IP addresses stay the same from end to end, but the MAC addresses are rewritten at each hop:
- Your computer puts the packet in a frame addressed to the router's MAC address.
- The router receives the frame, discards the Ethernet header and trailer, and reads the IP packet.
- It picks the next hop and builds a new frame, with its own MAC address as source and the next device's MAC address as destination.
That is why MAC addresses are never visible to a website: they do not survive the first router.
Data link layer devices: switches and bridges
A switch operates at this layer. It reads the destination MAC address in each frame and sends the frame out of the port where that address was last seen, instead of copying it to every port. Hubs, which repeat bits to all ports, belong to the physical layer. A router works at Layer 3 because it decides using IP addresses.
Is Wi-Fi a data link layer protocol?
Yes. Wi-Fi (IEEE 802.11) is another Layer 2 and Layer 1 technology, so it has its own frame format and MAC addressing. The details differ from Ethernet, including the number of address fields in a frame, so a Wi-Fi capture does not look like the table above. I did not verify the 802.11 frame layout against the standard, so this article stays with Ethernet.
If you want to see frames yourself
A packet capture tool such as Wireshark shows the destination, source and EtherType of every frame in its packet details. Capture on a wired interface and look for the Ethernet II line.
Frequently asked questions
- Which layer is the data link layer in the OSI model?
- Layer 2, directly above the physical layer (Layer 1) and below the network layer (Layer 3). It moves frames between two devices that share one link or one local network. Routing between networks is the job of Layer 3.
- What is the difference between a frame and a packet?
- A frame is the unit of data at the data link layer, with a header and trailer holding MAC addresses and an error check. A packet is the unit at the network layer, with IP addresses. A packet travels inside the payload of a frame, and each hop on the path wraps it in a new frame.
- Is a switch a Layer 2 device?
- Yes. An Ethernet switch reads the destination MAC address of each frame and forwards it toward that address. A router works at Layer 3 and forwards by IP address, replacing the frame at each hop.
- Does the data link layer fix corrupted frames?
- Ethernet only detects them. The receiver recalculates the 32-bit frame check sequence, and a frame that does not match is discarded. Recovering the lost data is left to higher layers, for example TCP retransmission.