Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A line of code (LOC) is a way to measure source software, but the count depends on the rules used. A physical count follows text line breaks; a logical count aims to count statements or other language-level units. Blank lines, comments, mixed code-and-comment lines, and tool behavior can change the result, so a meaningful LOC figure should state its convention.

Physical LOC and logical LOC are different measures

Physical LOC counts source text by line boundaries: a line runs between applicable line endings or from a file boundary. It is therefore affected by formatting. The same algorithm can have different physical line counts in different implementations. NIST’s measurement glossary describes the terminology and notes that multiple definitions are in use.

Logical LOC attempts to count language-level units, commonly statements. A single statement can continue over several physical lines, while one physical line can contain more than one statement. “Logical LOC” is not a universally consistent label: depending on the convention, it may mean statements, continuation-joined lines, or another noncommented-line measure. Define it before comparing figures.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a LOC count includes depends on the rules

A reported count may include or exclude blank lines and comment-only lines. Some conventions distinguish total lines from noncommented lines. In the NIST glossary’s terminology, a comment line of code (CLOC) contains only comments and whitespace, or is empty; a non-comment line of code (NCLOC) is a LOC that is not a CLOC. Under that relationship, LOC = NCLOC + CLOC. Other frameworks may use the same acronyms differently, so the names alone do not settle what was counted.

  • Blank lines: May be included in physical LOC or excluded from a noncommented count.
  • Comment-only lines: May be reported separately or excluded from the source-code count.
  • Mixed code and comment: A line with both code and a comment is commonly counted as code under CLOC’s convention.
  • Statements: A logical count depends on how the language’s syntax identifies statement boundaries.

Why different tools can report different counts

A counter must decide how to recognize comments and language syntax. CLOC documents that it can misread comment markers inside strings or here-documents as actual comments because it does not parse every target language; it also treats mixed code-and-comment lines as code. These are tool-specific behaviors, not universal rules. CLOC’s documentation describes its approach and limitations.

The loccount manual describes logical LOC as source lines with statement-terminating punctuation, while warning that statement-based counting does not suit every language and works reliably only where the syntax supports it. As a result, counts from different tools may diverge even when they examine the same files.

What LOC is useful for—and what it cannot tell you

LOC is a concrete, statically collectable measure of software size. It is also used as an input in some software cost-estimation methods. NASA discusses LOC in the context of estimating software costs, while the U.S. Government Accountability Office warns that there is no standard definition of what to count. The same functionality can produce different counts depending on programming language and implementation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

LOC by itself does not establish software quality, complexity, developer productivity, or the effort required to build a system. Treat it as a size measure whose meaning depends on the implementation and counting convention—not as a universal score. See NASA’s software cost-estimation discussion and the GAO Cost Estimating and Assessment Guide for that estimation context and comparison caution.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to make an LOC figure interpretable

When reporting or comparing a count, include the rules alongside the number. This is especially important for estimates: COCOMO II’s Model Definition Manual Version 2.1 uses logical source statements as its model-specific LOC input and provides a checklist to make counting definitions consistent. That guidance applies to the model; it does not establish a universal LOC definition. The COCOMO II materials provide the manual and its counting guidance.

  • Say whether the figure is physical LOC, logical LOC, NCLOC, or another defined measure.
  • State whether blank and comment-only lines are included, and how mixed code-and-comment lines are treated.
  • Name the programming language or languages in scope.
  • Identify the counting tool and version, since parsing and comment-recognition behavior differ.
  • For project estimates, explain how generated, copied, and modified code is handled.

Without these details, an LOC number may be precise as a tool output but still be unsuitable for comparison.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.