# Framing
## What is Framing
Framing is the function performed at the Data Link layer that divides the stream of bits received from the Physical layer into discrete, manageable units called frames. Each frame has a clearly defined beginning and end, allowing the receiver to identify where one frame ends and the next begins. Without framing, the continuous stream of bits would be meaningless because the receiver would have no way to know how to group bits into meaningful data units.
## Why Framing is Necessary
The Physical layer simply transmits bits as electrical signals, light pulses, or radio waves. It has no concept of the structure or meaning of the data. Framing provides structure by organizing bits into frames that contain the actual data payload along with control information such as source and destination addresses and error detection values. Frames also allow the network to handle errors at the frame level by retransmitting individual damaged frames rather than the entire data stream.
## Methods of Framing
Character count framing places the frame length in a field at the beginning of the frame. The receiver reads this count to determine where the frame ends. The problem is that if the count field is corrupted, the receiver cannot find the end of the frame.
Character stuffing, also called byte stuffing, uses special flag bytes to mark the beginning and end of frames. If the data portion of the frame happens to contain the same byte value as the flag, the sender inserts an escape byte before it. The receiver removes the escape bytes and correctly interprets the data. This method is used in protocols like PPP.
Bit stuffing is similar to character stuffing but works at the bit level. A special bit pattern marks the beginning and end of frames. If the same pattern appears in the data, extra bits are inserted to break up the pattern. HDLC uses a flag pattern of 01111110 and inserts a 0 after every five consecutive 1 bits in the data.
Physical layer coding violations use signal transitions or patterns that are not valid in normal data encoding to indicate frame boundaries. This method relies on the encoding scheme used at the Physical layer.
## Frame Structure
A typical frame consists of a preamble or start delimiter that signals the beginning of the frame, a destination address, a source address, a type or length field, the data payload, and a frame check sequence for error detection. The exact fields and their sizes vary depending on the protocol. An Ethernet frame, for example, has a 7-byte preamble, a 1-byte start frame delimiter, 6-byte destination and source MAC addresses, a 2-byte type or length field, between 46 and 1500 bytes of data, and a 4-byte CRC.Back to Subject