Explainer
How compilers and interpreters work: from source code to machine code
A compiler translates a program from one language into another, typically from a higher-level language into machine code.[1][2] Some languages instead compile to an intermediate bytecode that a virtual machine runs, as CPython and Java do.[3][4] Runtimes can also mix the two: just-in-time (JIT) compilers, built into the JavaScript engines of all major browsers, typically turn frequently run "hot spots" into machine code while the program runs.[5][6][7]
What a compiler does
Compiling means transforming a program written in one language into a set of instructions in another format or language, and a compiler is the program that does it.[1] Typically, a compiler turns code in a higher-level language such as C++, Rust or Java into executable machine code.[2] Most compilers work either ahead of time (AOT), before the program runs, or just in time (JIT); GNU gcc is a well-known AOT compiler, usually run from the command line or inside an IDE.[8]
Building a C program with GCC happens in steps. The GCC manual lists up to four stages, always in this order: preprocessing, compilation proper, assembly and linking.[9] Each piece becomes an object file, and the linker joins the pieces into one program you can run.[10]
The GCC manual lists up to four stages - preprocessing, compilation proper, assembly and linking - always in that order.[9] Assembling each input produces an object file, and linking combines the newly compiled object files with any supplied as input into an executable.[10]
Shared compiler infrastructure: LLVM
Compilers can be built from reusable parts: the LLVM Project describes itself as a collection of modular and reusable compiler and toolchain technologies.[11] Its core libraries provide a source- and target-independent optimizer and code generation for many CPUs, built around a code representation called the LLVM intermediate representation (LLVM IR).[12] Clang is LLVM’s native C, C++ and Objective-C compiler, and external projects use LLVM components to compile languages including Ruby, Python, Haskell, Rust, Lua and Julia.[13]
Interpreters and bytecode
Python is usually called an interpreted language: source files can be run directly without first creating an executable.[14] Its documentation says the distinction from compiled languages can be blurry, because CPython first compiles source code into bytecode, its internal representation of a program, and caches that bytecode in .pyc files so the same file runs faster the second time.[14][3] The bytecode runs on a virtual machine, and it is not expected to work across different Python virtual machines or stay stable between Python releases.[15]
Java uses a similar split. The javac compiler turns source files into .class files containing bytecode for the Java Virtual Machine rather than code native to the processor.[4] The Python glossary sums up the usual trade-off: interpreted languages typically have a shorter development and debugging cycle, but their programs generally run more slowly.[16]
Just-in-time compilation
Just-in-time compilation translates code from an intermediate representation or a higher-level language into machine code while the program runs, combining benefits of interpretation and ahead-of-time compilation.[5] JIT compilers typically watch code as it runs, find frequently executed hot spots and compile those parts when the speed-up outweighs the cost of compiling.[6] JIT compilers are usually built into runtimes rather than run directly.[7] Some Java virtual machines, such as Java SE HotSpot, find performance bottlenecks at runtime and recompile frequently used code to native code.[17]
Inside a JavaScript engine
All major browsers use JavaScript engines with built-in JIT compilers.[7] Browsers parse scripts into abstract syntax trees, and some engines pass those trees to a compiler that outputs bytecode.[18] Google’s V8 engine introduced a pipeline built on Ignition, an interpreter, and TurboFan, an optimizing compiler, in V8 v5.9, which reached Chrome Stable in version 59.[19] TurboFan generates optimized machine code directly from Ignition’s bytecode instead of re-compiling from source, and because generating bytecode is faster than V8’s earlier baseline compiled code, Ignition improves script start-up.[20] V8’s team says the interpreter was originally built to reduce memory use on mobile devices.[21] For where this fits in loading a page, see how web browsers work.
Read next
How programming languages work: syntax, types, memory and runtimes
How programming languages turn human-readable code into instructions a computer runs, and how they differ on typing, memory management and portability.
Questions readers ask
What is the difference between a compiler and an interpreter?
A compiler translates a program into another form, typically machine code. Python, which its documentation calls an interpreted language, runs source files directly without first creating an executable, though the documentation notes the line is blurry because of Python's bytecode compiler.[1][2][14]
What are the stages of compiling a C program?
The GCC manual lists up to four stages, always in this order - preprocessing, compilation proper, assembly and linking. Linking combines object files into an executable.[9][10]
What is bytecode?
An intermediate form of a program that a virtual machine runs. CPython compiles Python source into bytecode and caches it in .pyc files; Java compiles source into .class files containing bytecode for the Java Virtual Machine.[3][4]
Sources
· 21 claims from 6 publishers
Each numbered claim is a statement we checked against the sources listed with it. Tap a number in the text to see its sources in place.
- [1]
MDN defines compiling as transforming a program written in one language into a set of instructions in another format or language; a compiler is the program that does this. reportedas of 2026-11-14
- Compile · MDN Web Docs (Mozilla) · Secondary source · Glossary: Compile, first paragraph (retrieved 2026-11-14)
- [2]
A compiler typically turns code written in a higher-level language such as C++, Rust or Java into executable binary code, also called machine code. reportedas of 2026-11-14
- Compile · MDN Web Docs (Mozilla) · Secondary source · Glossary: Compile, second paragraph (retrieved 2026-11-14)
- [3]
CPython compiles Python source code into bytecode, its internal representation of a program, and caches the bytecode in .pyc files so the same file runs faster the second time. confirmedas of 2026-11-14
- Glossary (Python documentation) · Python Software Foundation · Primary source · Glossary: bytecode (retrieved 2026-11-14)
- Glossary (Python documentation) · Python Software Foundation · Primary source · Glossary: bytecode (retrieved 2026-11-14)
- [4]
Java source code is written in .java files and compiled by the javac compiler into .class files containing bytecode for the Java Virtual Machine rather than code native to the processor; the java launcher then runs the program on a JVM. confirmedas of 2026-11-14
- About the Java Technology · Oracle (The Java Tutorials) · Primary source · The Java Programming Language (retrieved 2026-11-14)
- About the Java Technology · Oracle (The Java Tutorials) · Primary source · The Java Programming Language (retrieved 2026-11-14)
- About the Java Technology · Oracle (The Java Tutorials) · Primary source · The Java Programming Language (retrieved 2026-11-14)
- [5]
Just-in-time compilation translates code from an intermediate representation or a higher-level language into machine code while the program runs rather than beforehand, combining benefits of interpretation and ahead-of-time compilation. reportedas of 2026-11-14
- Just In Time Compilation (JIT) · MDN Web Docs (Mozilla) · Secondary source · Glossary: Just-In-Time Compilation, first paragraph (retrieved 2026-11-14)
- Just In Time Compilation (JIT) · MDN Web Docs (Mozilla) · Secondary source · Glossary: Just-In-Time Compilation, first paragraph (retrieved 2026-11-14)
- [6]
JIT compilers typically watch code as it runs, find frequently executed "hot spots" and compile those parts to machine code when the speed-up outweighs the cost of compiling. reportedas of 2026-11-14
- Just In Time Compilation (JIT) · MDN Web Docs (Mozilla) · Secondary source · Glossary: Just-In-Time Compilation, second paragraph (retrieved 2026-11-14)
- Just In Time Compilation (JIT) · MDN Web Docs (Mozilla) · Secondary source · Glossary: Just-In-Time Compilation, second paragraph (retrieved 2026-11-14)
- [7]
JIT compilers are usually built into software runtimes to improve performance rather than run directly, and all major browsers use JavaScript engines with built-in JIT compilers. reportedas of 2026-11-14
- Compile · MDN Web Docs (Mozilla) · Secondary source · Glossary: Compile (retrieved 2026-11-14)
- [8]
Most compilers work either ahead of time (AOT) or just in time (JIT); GNU gcc is a well-known AOT compiler, usually run from the command line or an IDE. reportedas of 2026-11-14
- [9]
The GCC manual says compilation can involve up to four stages, always in this order - preprocessing, compilation proper, assembly and linking. confirmedas of 2026-11-14
- Options Controlling the Kind of Output (GCC manual) · GNU Project (Free Software Foundation) · Primary source · 3.2 Options Controlling the Kind of Output, first paragraph (retrieved 2026-11-14)
- [10]
In GCC, assembling each input produces an object file, and linking combines the object files into an executable file. confirmedas of 2026-11-14
- Options Controlling the Kind of Output (GCC manual) · GNU Project (Free Software Foundation) · Primary source · 3.2 Options Controlling the Kind of Output, first paragraph (retrieved 2026-11-14)
- [11]
The LLVM Project describes itself as a collection of modular and reusable compiler and toolchain technologies. confirmedas of 2026-11-14
- The LLVM Compiler Infrastructure · LLVM Project · Primary source · LLVM Overview (retrieved 2026-11-14)
- [12]
LLVM's core libraries provide a source- and target-independent optimizer and code generation for many CPUs, built around a code representation called the LLVM intermediate representation (LLVM IR). confirmedas of 2026-11-14
- The LLVM Compiler Infrastructure · LLVM Project · Primary source · LLVM Overview, LLVM Core (retrieved 2026-11-14)
- The LLVM Compiler Infrastructure · LLVM Project · Primary source · LLVM Overview, LLVM Core (retrieved 2026-11-14)
- [13]
Clang is LLVM's native C, C++ and Objective-C compiler, and external projects use LLVM components to compile languages including Ruby, Python, Haskell, Rust, Lua and Julia. confirmedas of 2026-11-14
- The LLVM Compiler Infrastructure · LLVM Project · Primary source · LLVM Overview, Clang (retrieved 2026-11-14)
- The LLVM Compiler Infrastructure · LLVM Project · Primary source · LLVM Overview, external projects (retrieved 2026-11-14)
- [14]
The Python documentation calls Python an interpreted language but says the distinction from compiled languages can be blurry because of its bytecode compiler; source files can be run directly without first creating an executable. confirmedas of 2026-11-14
- Glossary (Python documentation) · Python Software Foundation · Primary source · Glossary: interpreted (retrieved 2026-11-14)
- Glossary (Python documentation) · Python Software Foundation · Primary source · Glossary: interpreted (retrieved 2026-11-14)
- [15]
Python bytecode runs on a virtual machine that executes the machine code corresponding to each bytecode, and bytecode is not expected to work across different Python virtual machines or stay stable between releases. confirmedas of 2026-11-14
- Glossary (Python documentation) · Python Software Foundation · Primary source · Glossary: bytecode (retrieved 2026-11-14)
- Glossary (Python documentation) · Python Software Foundation · Primary source · Glossary: bytecode (retrieved 2026-11-14)
- [16]
The Python glossary says interpreted languages typically have a shorter development and debugging cycle than compiled ones, though their programs generally run more slowly. confirmedas of 2026-11-14
- Glossary (Python documentation) · Python Software Foundation · Primary source · Glossary: interpreted (retrieved 2026-11-14)
- [17]
Some Java virtual machines, such as Java SE HotSpot, find performance bottlenecks at runtime and recompile frequently used sections of code to native code. confirmedas of 2026-11-14
- About the Java Technology · Oracle (The Java Tutorials) · Primary source · The Java Programming Language (retrieved 2026-11-14)
- [18]
Browsers parse JavaScript into abstract syntax trees, and some engines pass those trees to a compiler that outputs bytecode; most code then runs on the browser's main thread, except code in web workers. reportedas of 2026-11-14
- Populating the page: how browsers work · MDN Web Docs (Mozilla) · Secondary source · JavaScript compilation (retrieved 2026-11-14)
- Populating the page: how browsers work · MDN Web Docs (Mozilla) · Secondary source · JavaScript compilation (retrieved 2026-11-14)
- [19]
Google's V8 JavaScript engine introduced a pipeline built on Ignition, an interpreter, and TurboFan, an optimizing compiler, in V8 v5.9, which reached Chrome Stable in version 59. confirmedas of 2026-11-14
- Launching Ignition and TurboFan · V8 project (Google) · Primary source · 2017-05-15 · Launching Ignition and TurboFan, first paragraph (retrieved 2026-11-14)
- Launching Ignition and TurboFan · V8 project (Google) · Primary source · 2017-05-15 · Launching Ignition and TurboFan, first paragraph (retrieved 2026-11-14)
- [20]
In V8, TurboFan generates optimized machine code directly from Ignition's bytecode instead of re-compiling from source code, and generating bytecode is faster than V8's earlier baseline compiled code, which improves script start-up. confirmedas of 2026-11-14
- Launching Ignition and TurboFan · V8 project (Google) · Primary source · 2017-05-15 · A long journey (retrieved 2026-11-14)
- Launching Ignition and TurboFan · V8 project (Google) · Primary source · 2017-05-15 · A long journey (retrieved 2026-11-14)
- [21]
V8's Ignition interpreter was originally motivated by reducing memory use on mobile devices. confirmedas of 2026-11-14
- Launching Ignition and TurboFan · V8 project (Google) · Primary source · 2017-05-15 · A long journey (retrieved 2026-11-14)
Revision history (1)
- Page created.
Created Nov 14, 2026. Last reviewed by an editor on Nov 14, 2026. Next scheduled review: Aug 14, 2027.
Cite this page
"How compilers and interpreters work: from source code to machine code." ContentLora, updated Nov 14, 2026. https://contentlora.com/explain/how-compilers-and-interpreters-work
Spotted an error? Suggest a correction or emailcorrections@contentlora.com.