There is no single number of lines of code “in computer science”: lines of code (LOC) is a measurement applied to a specific program, project, or codebase at a specific version, not a property of the discipline itself, and even for one codebase the count depends entirely on what you decide to count. The question is ambiguous in a way that matters, because “computer science” names an academic field, while “lines of code” measures software artifacts — and there is no authoritative census of all software ever written or currently in use.
This answer explains what LOC actually measures, why credible totals for large systems vary by orders of magnitude depending on counting rules, what kinds of published figures exist and what they do and do not mean, and how to reason about the question if what you really want is a concrete number for a particular context.
What “lines of code” measures — and what it does not
A line of code is a physical or logical unit of source text. The simplest count is physical lines: every line in every source file, including blanks and comments. A stricter count is source lines of code (SLOC), which typically excludes blank lines and sometimes comments. A third approach counts logical statements — for example, one if block counts as one regardless of how it is formatted across several lines.
These conventions produce very different totals for the same file. Consider a short Python function:
As physical lines, that is four. As SLOC excluding blanks and the comment, it is three. As logical statements (a definition plus a return), it is two. None of these is wrong; they answer slightly different questions. Any figure quoted without its counting rule is therefore only loosely interpretable.
LOC also says nothing about difficulty, quality, or capability. A 50-line regular expression can encode more complexity than 5,000 lines of boilerplate configuration. This is why LOC is treated in software engineering as a rough size proxy, useful mainly for comparing similar code in similar languages under the same counting rule — not as a measure of “how much computer science” something contains.
Why “computer science” has no LOC total
Computer science as a field includes algorithms, theory, proofs, hardware design, and specifications — much of which is not expressed as lines of source code at all. A proof of a theorem, a circuit diagram, or a protocol specification has no meaningful LOC count. Even restricting the question to software, there is no registry that counts all programs. Code exists in proprietary products, embedded firmware, abandoned repositories, and one-off scripts that were never published or measured. Any global figure would be an estimate built from sampling and assumptions, not a count.
What does exist are published measurements of specific systems: operating-system kernels, large applications, and open-source repositories. These are the useful reference points, provided their scope and counting method are stated.
Published figures and what they actually cover
Landmark size estimates illustrate both the scale and the fragility of the numbers. The Linux kernel is commonly described as tens of millions of lines; widely cited figures in recent years have been in the roughly 25–30 million range, but the exact number changes with every release and with whether you count comments, headers, architecture-specific code, and generated files. The figure is a snapshot of one tree at one version under one tool.
Historically influential operating systems were smaller by orders of magnitude. Early Unix was on the order of tens of thousands of lines, and MS-DOS in its early versions was likewise small by modern standards. Windows and other large commercial systems are estimated in the tens to hundreds of millions of lines, but these are typically company or press estimates rather than audited counts, and they rarely specify counting rules.
Open-source hosting gives another kind of number. Repositories on platforms like GitHub are individually measurable, and platform-wide statistics have been published, but they count only what is hosted there, only what is public, and only under whatever tool the platform uses. They are not a census of software.
The pattern is consistent: every credible figure is scoped (which system), versioned (which release), and methodological (which counting tool and rules). Strip away any of those three and the number becomes decorative.
Why counts vary so much for the same project
Three forces drive the spread.
Language and style. A language with terse syntax can express the same behavior in fewer physical lines than a verbose one. Generated code — parsers, protocol bindings, UI scaffolding — can inflate a repository enormously while representing little hand-written logic. A project that vendors third-party libraries will show a huge LOC total that mostly belongs to other projects.
Counting tool and rules. Tools differ on whether to include blank lines, comments, headers, test code, documentation files, configuration, and generated artifacts. Two tools run on the same repository can differ by a large factor. This is not a bug; it reflects a decision about what “code” means for the purpose at hand.
Boundaries. Is a kernel’s LOC the core only, or core plus all architecture ports plus drivers? Is a web application’s LOC the server code, or server plus client plus build scripts? The boundary choice can change the answer by multiples.
A concrete illustration: a project with 100,000 physical lines might contain 60,000 SLOC excluding comments and blanks, of which 15,000 are auto-generated and 20,000 are tests. Depending on what you report, “the project” is 100,000, 60,000, 45,000, or 25,000 lines. All four can be defended if labeled.
If you need a number, define the question first
The productive move is to convert the vague question into a measurable one. Useful framings include:
For a specific codebase: state the repository or release, the languages included, whether tests and generated files count, and the tool or rule used. Then the number is reproducible. For a language ecosystem or platform: use the platform’s published statistics, but label them as covering only hosted public repositories under that platform’s counting method. For “all software in the world”: treat any figure as an order-of-magnitude estimate derived from assumptions, and expect enormous uncertainty.
A simple reproducible procedure for a local codebase, expressed as a principle rather than a specific tool: choose a counter, fix its inclusion rules, run it at a tagged version, and record the version and rules alongside the result. That record is what makes the number meaningful later.
Common confusions to avoid
“Lines of code” is not “lines written by humans.” Generated and vendored code dominate many repositories.
A bigger number is not a better or harder project. Size correlates weakly with complexity and not at all with quality.
Historical figures drift. A kernel LOC quoted from one year will not match the current release; both may be correct for their snapshots. Always attach a date or version.
Anecdotes are not measurements. “This app is a million lines” is often a rounded impression. Without scope and method, treat it as a story, not data.
The field is larger than its code. Computer science includes theory and design that LOC cannot capture, so asking for the field’s LOC total is a category slip rather than a missing statistic.
Bottom line
There is no answer to “how many lines of code are there in computer science” in the way there is an answer to “how many lines are in this file.” LOC is a scoped, versioned, method-dependent measurement of software, and computer science is broader than software. The honest response is to name the system, the version, and the counting rule — and to recognize that global totals are estimates, not counts. If you have a particular codebase in mind, the question becomes tractable immediately; without one, the only defensible answer is that the quantity is undefined until you specify what is being measured.