stories-matter Why ‘carriage return’ and ‘line feed’?

Explore a bit of history to learn why we still use these terms to refer to the end of a line in a text file.

Have you ever looked at how computers end the lines in a text file? Some computers, like Linux and Mac systems, use a "line feed" character to end a line. Older Mac computers used a "carriage return" character. Windows systems and the DOS operating system that came before it used both: "carriage return" and "line feed" as a pair.

If you've ever wondered what a "carriage return" is, and the origin of the term, let's take a brief step back in history.

Mechanical typewriters

Think back to a time when the typewriter was a new invention. The first typewriters were huge, the size of grand pianos, and weren't as fast as writing by hand. But in the late 1800s, the first recognizable typewriter appeared.

This new device incorporated features that became standard in mechanical typewriters. The operator wound a piece of paper around a hard drum called a platen. To add characters to the page, a typist would press keys on a simple keyboard, which caused a lever to swing up and strike the paper over a strip of ribbon embedded with ink. The end of each lever held a character, such as a letter or number, and the strike would cause the inked ribbon to make a mark on the page. That was the origin of typing on a mechanical typewriter.

Typewriters used a monospace font, so every character was the same width. Every time a character was added to the page, the typewriter needed to advance to the next letter position. It was far easier to move the paper, so the paper and drum assembly sat in a carriage and the typewriter advanced the carriage by one character for every letter typed on the page.

When the carriage moved as far as possible along the page, the operator would then need to advance the drum to move to the next line on the page, and reset the carriage to the "home" position so typing could start from the left side of the page. Mechanical typewriters had a lever that did both at the same time; pushing the lever activated a ratchet within the assembly to move to a new line while returning the carriage to the start of the line.

Photo of a mechanical typewriter

Remington Standard mechanical typewriter, showing the carriage centered on the page (photo by Pixabay, CC0)

Line feed and carriage return

These terms persisted throughout the industry. A "carriage return" moves the carriage assembly back to the "home" position to the left side of the page, and a "line feed" advances the drum so typing can start one line "down" the page.

During the computer revolution, early computers did not have keyboards and displays like we think of them today. Instead, computer operators interacted with systems using a terminal. The first terminals were essentially automated typewriters: they typed letters on a continuous roll of paper wrapped around a drum,  in the same way as traditional typewriters. As an operator typed commands, the system would "echo" the typed characters back, to print on paper. Output was similarly printed on this paper roll.

The technology of early terminals like the TeleType Model 33 used the same terminology, except that instead of moving the carriage the terminals used a print head that moved left and right on the page. Returning the terminal's print head to the "home" position was called a "carriage return" despite the absence of a literal "carriage" on the system. Advancing the page by one line was still a "line feed."

TeleType Model 33

Photo of the TeleType Model 3310 terminal, showing where paper is loaded

Tracking the ends of lines

Operating systems use files. The Unix operating system treated everything as a file. So it was important to know where one line ends and another line begins. To do that, the system needs to have a marker to indicate the end of a line.

Computers have used the American Standard Code for Information Interchange (ASCII) standard to map computer codes to letters since 1963, and was first implemented in the TeleType Model 33 and Model 35. While ASCII saw a few minor changes in the next few years , ASCII has remained stable since 1967. ASCII is 7-bit binary, and defines values as characters: the binary values from 000 0000 to 001 1111 are control codes of some sort; values above 001 1111 are printable characters, such as 010 0000 (32) for a space or 100 0001 (65) for the capital letter A.

Unix (1969) borrowed from the terminology on the TeleType, and adopted the "line feed" (binary 000 1010, or the value 10) character to mean "start a new line here." Many printers that followed could be configured to recognize a single "line feed" character to both return the carriage to the "start" position and advance the paper to the next line.

Meanwhile, DOS (1981) decided to use a pair of characters, "carriage return" (binary 000 1101, or value 13) plus "line feed," to start a new line. This standard dates back to earlier operating systems such as CP/M and QDOS, from which MS-DOS borrowed parts of its design. Windows inherited the "carriage return" and "line feed" pair from its origins in MS-DOS.

Adding to the confusion, early Mac computers (1984) used just "carriage return" to indicate the end of a line. However, Apple adopted the single "line feed" character ever since it adopted Unix as the base technology for MacOS X (2001).

History lives on

It's interesting that the terminology for how to end a line maintains that history from mechanical typewriters. The "carriage return" and "line feed" names persist to this day, even though modern computers with digital displays do not have a "carriage" to return or a physical concept of a drum or platen that requires a "line feed."

The only time you are likely to come across these strange control characters is when you transfer a file from a Windows system to a Mac or Linux computer. Windows uses both "carriage return" and "line feed" to indicate the end of a line, while Mac and Linux only use "line feed." If you edit a file from Windows under Mac or Linux, you will likely see ^M characters or some other placeholder that indicates a control code. This is the extra "carriage return" code.