The Linux kernel alone contains tens of millions of lines, each contributing to its role as the core of the operating system. If you’ve ever wondered exactly how many lines of code is the linux kernel, the answer is both impressive and constantly changing. As of the latest stable release, the kernel hovers around 28 to 30 million lines of source code, depending on the version and configuration. This massive codebase powers everything from smartphones to supercomputers, making it one of the largest open-source projects in history.
But that number isn’t fixed. Every new release adds thousands of lines for drivers, security patches, and new features. Understanding the scale helps you appreciate the engineering behind Linux. In this article, we’ll break down the exact counts, why they matter, and how you can check the numbers yourself.
How Many Lines Of Code Is The Linux Kernel
To give you a precise answer, let’s look at the most recent stable kernel version. As of Linux 6.7, released in early 2024, the kernel contains approximately 29.5 million lines of code. This includes all source files, headers, and build scripts. The count comes from the official Git repository, where developers track every change.
Here’s a quick breakdown of what makes up that total:
- Architecture-specific code: about 4 million lines for different CPU families (x86, ARM, RISC-V, etc.)
- Device drivers: roughly 15 million lines, the largest chunk
- File systems: around 2.5 million lines
- Network stack: about 1.5 million lines
- Core kernel: around 6 million lines for scheduling, memory management, and IPC
These numbers shift with every release. For example, Linux 6.6 had about 29 million lines, while 5.10 had around 28 million. The growth is steady but not explosive—typically 200,000 to 500,000 new lines per release.
How To Check The Line Count Yourself
You don’t have to trust online sources. You can verify the count directly from the source code. Here’s a step-by-step guide:
- Clone the Linux kernel repository:
git clone https://github.com/torvalds/linux.git - Navigate into the directory:
cd linux - Run the
cloctool (count lines of code):cloc . - Or use a simple shell command:
find . -name "*.c" -o -name "*.h" | xargs wc -l
This gives you a raw count. Note that cloc is more accurate because it ignores blank lines and comments. The raw wc -l command counts everything, including whitespace.
For a quick reference, here’s a table of recent kernel versions and their line counts:
| Kernel Version | Release Date | Lines of Code (approx.) |
|---|---|---|
| 6.7 | Jan 2024 | 29.5 million |
| 6.6 | Oct 2023 | 29.0 million |
| 6.1 | Dec 2022 | 28.5 million |
| 5.15 | Oct 2021 | 27.8 million |
| 5.10 | Dec 2020 | 27.2 million |
Notice the trend: roughly 0.5 million new lines per year. That’s a lot of code, but it’s well-organized.
Why The Line Count Matters
You might think a huge codebase is a bad thing. But for the Linux kernel, size is a sign of success. Here’s why the count is important:
- Hardware support: Most of those lines are drivers. Linux runs on almost every device, from old routers to modern GPUs.
- Stability: More code means more testing. The kernel is used in production everywhere, so bugs get found fast.
- Community: Thousands of developers contribute. The line count reflects collaborative effort.
However, size also brings challenges. Maintaining 30 million lines requires strict coding standards and automated testing. The kernel uses a process called “merge windows” to manage changes. Every two months, a new release cycle begins, and developers submit patches.
Comparing The Linux Kernel To Other Projects
To put the number in perspective, let’s compare it to other massive software projects:
- Google Chrome: about 6 million lines (without Blink engine)
- Android OS: roughly 12 million lines (kernel + userspace)
- Windows 10: estimated 50 million lines (proprietary, so exact count unknown)
- Linux kernel: 29 million lines (just the kernel, not the whole OS)
So the kernel is larger than Chrome but smaller than Windows. That’s impressive for a free, open-source project. The kernel’s size is also growing faster than many other projects because of new hardware.
What About Comments And Blank Lines?
When people ask “how many lines of code is the linux kernel,” they often mean source code only. But the repository includes comments and blank lines too. Here’s the breakdown for Linux 6.7:
- Source code: 22 million lines
- Comments: 4 million lines
- Blank lines: 3.5 million lines
So the actual executable code is about 22 million lines. Comments are crucial for maintainability. Blank lines improve readability. The kernel developers follow strict style guidelines, which keeps the code consistent.
How The Kernel Line Count Has Evolved
The kernel started small. Linus Torvalds released version 0.01 in 1991 with about 10,000 lines. By version 1.0 in 1994, it had grown to 176,000 lines. The growth accelerated after that:
- 1995 (v1.2): 310,000 lines
- 1999 (v2.2): 1.8 million lines
- 2003 (v2.6): 5.9 million lines
- 2011 (v3.0): 14.6 million lines
- 2015 (v4.0): 19.5 million lines
- 2020 (v5.10): 27.2 million lines
- 2024 (v6.7): 29.5 million lines
The growth rate has slowed in recent years. That’s because the kernel is maturing. Most hardware is already supported, so new drivers are less common. Instead, developers focus on security, performance, and new features like Rust integration.
What Drives The Line Count Increase?
Several factors contribute to the growing codebase:
- New hardware: Each new CPU, GPU, or network card needs a driver.
- Security patches: Fixes for vulnerabilities often add new code.
- New subsystems: Features like BPF (Berkeley Packet Filter) add thousands of lines.
- Rust support: The kernel now includes Rust code, which adds new files.
But the kernel also removes code. Old drivers for obsolete hardware are deleted. In Linux 6.7, about 200,000 lines were removed while 500,000 were added. So the net growth is positive but controlled.
How To Understand The Kernel’s Structure
The kernel’s code is organized into directories. Each directory handles a specific subsystem. Here’s a map of the major ones:
arch/: Architecture-specific code (x86, ARM, etc.)drivers/: Device drivers (the largest directory)fs/: File systems (ext4, Btrfs, etc.)net/: Networking stackkernel/: Core kernel (scheduling, IPC, etc.)mm/: Memory managementsound/: Audio drivers
If you want to explore the code, start with kernel/. It’s the heart of the operating system. The drivers/ directory is huge—it contains about half the total lines.
Tools For Analyzing The Kernel Code
You don’t need to read all 30 million lines. Use these tools to understand the codebase:
cloc: Counts lines per language and directorygit log: Shows commit history and changescscope: Navigates the code (find functions, variables)LXR(Linux Cross Reference): Online code browser
These tools help you find specific parts without getting lost. For example, to see how many lines are in the scheduler, run cloc kernel/sched/.
Common Misconceptions About Kernel Size
People often misunderstand the line count. Let’s clear up a few myths:
- Myth: The whole OS is 30 million lines. Fact: Only the kernel. The full Linux distribution (like Ubuntu) has hundreds of millions of lines.
- Myth: More lines mean more bugs. Fact: The kernel has fewer bugs per line than most projects because of rigorous review.
- Myth: The kernel is bloated. Fact: You can compile a minimal kernel with just 2 million lines for embedded devices.
The kernel is modular. You don’t need all 30 million lines. Most users run a distribution kernel that includes many drivers, but you can customize it.
How The Kernel Compares To Other OS Kernels
Let’s compare Linux to other kernels:
- FreeBSD kernel: About 8 million lines
- Windows NT kernel: Estimated 10-15 million lines (proprietary)
- XNU (macOS): Around 5 million lines
- Zircon (Fuchsia): About 1 million lines
Linux is the largest open-source kernel. That’s because it supports the most hardware. FreeBSD is smaller but has fewer drivers. Windows is larger but closed-source.
Practical Implications Of The Line Count
For developers, the kernel’s size affects how you work:
- Compilation time: Building the full kernel takes 30-60 minutes on a modern CPU.
- Learning curve: It’s impossible to read all the code. Focus on one subsystem.
- Debugging: Finding a bug requires good tools like
kgdborftrace.
For users, the size means your hardware is likely supported. But it also means kernel updates can be large. A typical update downloads 50-100 MB of source code.
Future Trends In Kernel Size
The kernel’s growth will likely slow down. Here’s why:
- Most hardware is already supported.
- Rust integration may reduce code size in some areas.
- Ongoing cleanup removes old code.
By 2030, the kernel might reach 35 million lines. But it won’t double again like it did in the 2000s. The focus is shifting to quality over quantity.
FAQ: Common Questions About Kernel Line Count
Q: How many lines of code is the linux kernel in 2024?
A: Approximately 29.5 million lines for version 6.7, including comments and blanks.
Q: How many lines of code is the linux kernel compared to Windows?
A: The Linux kernel is about 30 million lines, while Windows 10 is estimated at 50 million lines for the entire OS.
Q: How many lines of code is the linux kernel written in C?
A: About 95% of the kernel is C, with small parts in assembly and Rust.
Q: How many lines of code is the linux kernel for a minimal build?
A: A stripped-down kernel for embedded systems can be as low as 2 million lines.
Q: How many lines of code is the linux kernel added each year?
A: Roughly 500,000 new lines per year, with some removals.
Final Thoughts On The Kernel’s Codebase
The Linux kernel’s 30 million lines are a testament to collaborative engineering. Whether you’re a developer or just curious, understanding the scale helps you appreciate the system. You can check the exact count yourself using Git and cloc. The number will keep growing, but the kernel’s stability and performance remain top-notch.
Remember, the line count isn’t just a statistic—it’s a measure of how much work goes into making Linux run everywhere. From your phone to the cloud, those millions of lines make it all possible. So next time someone asks “how many lines of code is the linux kernel,” you can give them the facts and show them how to verify it.