Back to Tools

Code Line Counter

Analyze source code to count total lines, empty lines, and comments.

Input Data

Count lines of code, comments and blank lines

Code Line Counter reads a block of source code and splits its lines into four groups: total lines, code lines, comment lines and empty lines. Lines of code is a rough but widely used measure of size, useful when estimating the effort of a review, filling in a report, or checking how much of a file is documentation rather than logic. You paste the code, press one button and get the breakdown in a table.

How to use it

  1. Paste your source code into the Input Data box. The Sample button loads a small script with a block comment, a line comment and a blank line.
  2. Press Process Now. Pressing it with an empty box shows an error asking for code.
  3. Read the result table: Total Lines, Code Lines, Comment Lines and Empty Lines.
  4. Use Copy or Download to save the table text as result.txt, or Clear to start over.

How each line is classified

  • A line that is blank or contains only whitespace counts as empty.
  • A line that begins with /* starts a block comment. That line and every following line up to the one containing */ are counted as comments.
  • A line that begins with //, # or the opening of an HTML comment is a comment line.
  • Everything else is a code line, including lines where code is followed by a trailing comment.

The four numbers always add up to the total, because each line is placed in exactly one group.

Where it helps

  • Reporting the size of a script in a README, ticket or assignment.
  • Checking how heavily a file is commented before a code review.
  • Comparing the size of two implementations of the same function.
  • Trimming a snippet to fit a length limit in a form or exam answer.

Edge cases to watch

The rules are deliberately simple. A line starting with a hash is treated as a comment, which suits shell, Python and Ruby but means C preprocessor lines such as an include and CSS selectors that begin with an id are counted as comments. A multi-line HTML comment only has its first line counted as a comment, and Python docstrings are seen as code. A final newline at the end of your paste adds one extra empty line to the total. For an exact figure across a whole project, use a command-line tool, and use this page for quick checks on a single snippet.

Related Tools




Frequently Asked Questions

What counts as a comment line?
A line that begins, after trimming spaces, with //, #, or an HTML comment opener, and any line inside a block that starts with /* and ends with */. A line that has code followed by a trailing comment is counted as code, not as a comment.
Why are my C include lines or CSS id selectors counted as comments?
The tool treats any line starting with a hash as a comment, which is correct for shell, Python and Ruby but not for preprocessor directives or CSS id selectors. If your code uses those, subtract them from the comment total manually.
Do blank lines inside a comment block count as empty or comment?
Empty. Blank lines are checked first, so a whitespace-only line inside a block comment is counted in the Empty Lines figure, not in Comment Lines. Only lines with visible text inside the block are counted as comments.
Why is my total one higher than I expected?
The text is split on line breaks, so a trailing newline at the end of what you pasted produces one extra empty line. Remove the final blank line from the box, or subtract one, if you need the exact count for a file.
Can it count lines across several files at once?
No. It analyses whatever is in the single input box as one block. To count several files, run them one by one and add the results, or paste them together if a combined total is what you want.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.