While sending the data ,To separate two frames we use flags,a flag may be any sequence of characters which indicates start and end of the frame.The problem may occur if the flag byte occurs in the data of the frame,to resolve the problem we stuff "ESC" string before each flag byte in the data.
If the "ESC" occurs in middle of the data then another "ESC" byte is inserted before "ESC" byte in the data.
At reciver side if the two esc sequences are seen then it removes one esc,if esc is followed with some data then it removes esc sequence and considers the remaining data.
In byte stuffing (or character stuffing), a special byte is added to the data section of the frame when there is a character with the same pattern as the flag. The data section is stuffed with an extra byte. This byte is usually called the escape character (ESC), which has a predefined bit pattern.