Add Line Numbers Tool

Paste your text to add a number to the front of each line.

How it is calculated

The text is split at every line break (Windows, old Mac and Unix breaks all count as one), and each line gets number | line in front of it. The first number is the start value you enter (1 if left empty), each later line adds 1, and a decimal start is cut to its whole part. All numbers are padded with spaces on the left to the width of the widest one (a negative start such as -1 counts with its minus sign), so the vertical bars line up: with 10 lines starting at 1, line 1 is shown as 1 | . The separator is always the vertical bar with a space on each side. Empty lines are numbered too, and the line count result tells you how many lines were found. Nothing happens if the text box is empty.

Worked example

Paste two lines, milk and eggs, and set the start number to 9. The first line becomes 9 and the second 10. The widest number has two digits, so 9 is padded with one space. The result is 9 | milk
10 | eggs
and the line count is 2. With the start left at 1 the same text would give 1 | milk and 2 | eggs, with no padding because both numbers are one digit.

Try this example →

Common mistakes

  • Leaving a trailing line break at the end of the pasted text: the empty last line is counted and numbered, so a 3-line list shows 4 lines.
  • Expecting to choose a different separator such as a dot or a tab: the tool always uses a space, a vertical bar and a space.
  • Using the output as code: the numbers and bars are part of the text, so remove them again before running or compiling a numbered snippet.
  • Leaving the start number empty and expecting numbering from 0: an empty field means 1, so type 0 yourself, and note that decimals are cut, so 1.9 becomes 1, not 2.

About this calculator

This tool splits pasted text at each line break and prefixes every line with a sequential number, right-aligned with space padding so the numbering stays aligned even as line lengths vary, followed by a fixed “ | ” separator. You can set the number to start from (it starts at 1 by default), and it also reports the total line count — a plain-text equivalent of what code editors show in their gutter or what word processors do with automatic line numbering.

Programmers preparing code snippets for documentation or bug reports, teachers numbering worksheet lines, and legal or manuscript editors who need to reference specific lines in a document use it to add numbering without opening a full editor — useful whenever you need to say “see line 42” in a plain-text file that doesn't have built-in line numbers.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    When you only paste part of a long file, set the start number to the first pasted line's real position. If you copy lines 98 to 100 from a log, start at 98 and the output reads 98, 99 and 100, matching the original file, so a reference such as see line 99 still points to the right place. Numbers padded to three digits keep the bars aligned. Which separator would you prefer instead of the vertical bar?

Popular calculators

All Calculators