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
Markdown Basics: Formatting Notes Using Only Plain Text
A short introduction to Markdown, a simple way to add headings, lists and emphasis to plain-text notes, with examples you can type on any text editor.
Read article →Quick Lists That Work: Shopping, Packing and Errands
How to write short, practical lists in a text editor so they're quick to make, easy to scan and simple to reuse.
Read article →Text Encoding Explained: Why Files Show Strange Characters
What UTF-8 and other encodings are, why text sometimes turns into odd symbols, and how to avoid the problem.
Read article →Writing a First Draft in Plain Text and Why It Helps
How writing without formatting can speed up drafting, reduce distraction and make editing easier.
Read article →