Why developers count lines of code
Lines of code, or LOC, is one of the oldest software metrics. It offers a rough sense of how big a file or project is, how complex it might be, and how much effort it took. Developers use it in code reviews, for simple dashboards, and to spot files that have grown too large. For a single file or snippet, our free Line Counter gives an instant count.
- Spotting bloated files that need refactoring.
- Estimating relative effort across modules.
- Feeding simple project dashboards.
- Comparing the size of two implementations.
- Reviewing the scope of a pull request.
Physical versus logical lines
The most important distinction in counting code is physical versus logical lines. A physical line is any line in the file, including blanks and comments. A logical line is a single statement, which may span several physical lines or share one. Naive counters report physical lines; specialized tools can report logical lines.
| Type | What it counts | Includes blanks and comments |
|---|---|---|
| Physical LOC | Every line in the file | Yes |
| Logical LOC | Actual statements | No |
| Source LOC | Lines with code, no blanks or comments | No |
A browser Line Counter reports physical lines, which is perfect for a quick check. For a statement-level count, developers use language-aware tools.
Counting a single file in the browser
- Open the source file in your editor.
- Select all with Ctrl+A and copy with Ctrl+C.
- Paste into the Line Counter.
- Read the physical line count instantly.
- Exclude blank lines if the tool offers the option.
Counting a diff or a single function is quick in the browser. Copy just the block you care about, paste it in, and get the size without loading a whole project into a heavy tool.
Counting whole projects on the command line
For entire codebases, the command line and dedicated counters scale far better than pasting into a browser. The wc command counts physical lines across many files at once, while tools like cloc break counts down by language and separate code from comments.
| Tool | What it does | Best for |
|---|---|---|
| wc -l | Counts physical lines | Quick totals |
| cloc | Splits code, comments, blanks by language | Project reports |
| find + wc | Counts across many files | Custom queries |
Counting node_modules, build output, or vendored libraries will wildly inflate your totals. Always exclude generated and third-party directories before counting a project.
What LOC does and does not tell you
LOC is useful, but it is a blunt instrument. A shorter file is not automatically better, and a longer file is not automatically worse. Clever one-liners can hide complexity, while readable code may span more lines. Treat LOC as one signal among many, never as a measure of quality or productivity on its own.
- LOC roughly indicates size and scope.
- LOC does not measure code quality.
- LOC is a poor measure of developer productivity.
- Comment and blank lines can distort naive counts.
- Two languages solving the same problem differ greatly in LOC.
Practical developer use cases
Reviewing a pull request
Before reviewing, a developer counts the lines changed to gauge review effort. A 20-line change is quick; a 2,000-line change needs a plan. Pair the count with a text diff checker to see exactly what changed.
Cleaning generated lists
When counting lines in a generated file such as a list of imports or config entries, remove accidental duplicates first with remove duplicate lines, then count for an accurate figure.
Common mistakes when counting code
- Counting generated or third-party code by accident.
- Treating physical LOC as if it were logical LOC.
- Using LOC as a productivity target, which encourages bloat.
- Ignoring blank and comment lines in a naive count.
- Comparing LOC across languages without context.
For quick counts of individual files, the browser tool is ideal. See our guide on counting lines in large text files when a single file grows huge.
Best practices for counting LOC
- Decide whether you need physical, logical, or source lines.
- Exclude generated and vendored directories from project counts.
- Use the browser Line Counter for single files and diffs.
- Use cloc or wc for whole codebases.
- Treat LOC as one signal, never the only one.
For a fast reviewer estimate, paste a diff into the browser counter to see how many lines changed. Combine that with the diff checker to understand both size and substance at a glance.
