ANSI escape codes are sequences of ordinary bytes, embedded in the normal stream of text sent to a terminal, that the terminal interprets as commands rather than printing as characters. Each sequence begins with the ESC control character (decimal 27), which signals that the bytes that follow form a control function. By writing these sequences to standard output a program can position the cursor anywhere on the screen, change foreground and background colors, turn on bold or underline, erase part or all of the display, and define scrolling regions, without any special device driver or graphics API.
The authoritative definition is ECMA-48, titled “Control functions for coded character sets,” published free by Ecma International, whose fifth edition dates from June 1991 and corresponds to ISO/IEC 6429. The same control functions were standardized in the United States as ANSI X3.64. ECMA-48 defines control functions and their coded representations for use in 7-bit and 8-bit codes, intended for embedding in character data interchanged with imaging devices. It specifies the structure of a Control Sequence Introducer (the bytes ESC followed by the left bracket, abbreviated CSI), the parameter bytes that follow, and the final byte that selects the operation.
A few families of these sequences account for most everyday use. Cursor movement functions such as Cursor Up, Cursor Down, and Cursor Position move the active position by a parameterized amount or to an absolute row and column. Erase functions such as Erase in Display and Erase in Line clear regions of the screen. The Select Graphic Rendition function, written as CSI followed by numeric parameters and the letter m, sets text attributes including the standard set of foreground and background colors. Because the parameters are plain decimal digits and the framework is uniform, the whole vocabulary is compact and easy to generate.
The DEC VT100 made these sequences ubiquitous. The VT100 User Guide (EK-VT100-UG-003, Digital Equipment Corporation) documents the VT100’s escape and control sequences, which implemented the ANSI X3.64 / ECMA-48 framework. Because the VT100 became a de facto standard terminal, software was written to emit exactly these sequences, and every terminal emulator since has had to parse them to remain compatible. The result is that ANSI escape codes, defined for serial hardware terminals in the 1970s, remain the lingua franca of text-mode display on every modern system.
These sequences are deliberately in-band: they travel through the same channel as the text, requiring no out-of-band signaling. That design choice is what makes them portable across serial lines, network connections, pseudo-terminals, and pipes, and it is why command-line tools, full-screen editors, and terminal multiplexers all rely on the same standard to color their output and control the screen.