Line Endings Explained: LF, CRLF and Why They Matter
Why text files from different systems sometimes look wrong, what line endings are, and how to keep your files tidy.
Every time you press Enter in a text file, an invisible character or two is stored to mark the end of the line. Different systems use different ones, and that can cause small annoyances.
The two styles
| Name | Characters | Used by |
|---|---|---|
| LF (line feed) | one character | Linux, macOS, Android |
| CRLF (carriage return + line feed) | two characters | Windows |
The names come from typewriters: the carriage return moved the carriage back to the start of the line, and the line feed moved the paper up.
When it causes problems
- One long line: an old file may show all its text on one line if the editor doesn't understand the line endings.
- Odd symbols: some tools show CR as a visible character such as ^M.
- Scripts that won't run: a script saved with Windows endings may fail on Linux.
- Messy comparisons: tools that compare files may show every line as changed.
How to avoid it
- Be consistent within a project or set of files.
- Use a modern editor that handles both.
- Choose one style and stick with it, LF being the most widely compatible choice for code.
- Check before sharing code or scripts with people on other systems.
Editing on Android
Android uses LF. When you edit files on your phone that came from a Windows computer, they may use CRLF. A good editor opens them correctly. For code files, it's worth checking the endings.
Everyday notes
For normal notes, you rarely need to think about this. The problem mostly appears when files move between systems or are used by programs.
A quick test
If a file appears as a single long line, or you see odd symbols at the end of lines, line endings are a likely cause.
Keep it simple
A lightweight editor that opens files quickly and shows text clearly is often enough for handling everyday plain-text files, including those from other systems.
Notepad+ Text Editor
A fast, advanced text editor for notes and code, with emoji support
More about Notepad+ Text Editor
Drafting Emails in a Text Editor First
Why drafting important emails in a separate text editor prevents accidental sends, improves clarity and helps you write calmer messages.
Read article →Keeping a CV in Plain Text for Easy Updates
Maintain a master CV in a plain-text file so you can update it anywhere, tailor it quickly and paste it cleanly into online application forms.
Read article →Keeping a Work Diary for Performance Reviews
Record your achievements, feedback and challenges throughout the year in a simple text file, so performance reviews and promotions are easier to prepare.
Read article →Outlining a Novel in a Text Editor
Use a plain-text outline to plan characters, chapters and plot for a novel — flexible, searchable and easy to rearrange.
Read article →