Menu
Coddy logo textTech

What Is an Interpreter?

An interpreter is a program that executes source code directly, carrying out its instructions as it goes, instead of first translating the whole program into a separate machine-code file. The standard Python and Ruby implementations are interpreters.

By Kevin Spektor, Co-founder & CTO

Updated September 24, 2026

Source code
  1. 1print("Hello")
  2. 2total = 2 + 3
  3. 3print(total)
  4. 4print("Done")
Output
Lines translated0
Runs0

Every run translates the lines again. Turn on the typo and the interpreter still prints "Hello" before it reaches line 3 and stops.

Type python3 hello.py and the output appears, but look in the folder afterwards: no new program file was created. The program that actually ran was python3 itself, the Python interpreter. It read hello.py, worked out what each statement means and did it. Run the script again tomorrow and the interpreter reads the source again from the start.

How an interpreter works

An interpreter repeats one cycle until the program ends: take the next instruction, work out what it means, carry it out, move on. It keeps the program's variables in its own memory while it works, which is why total = price * 3 can use a price set a few lines earlier.

The clearest way to see this is the interactive mode, called a REPL (read, evaluate, print, loop). Type python3 with no file name and every line runs the moment you press Enter:

>>> price = 4
>>> price * 3
12

Real interpreters add a preparation step. CPython, the standard Python interpreter, first compiles your whole file into bytecode, a compact list of simple instructions, and then runs a loop that executes that bytecode one instruction at a time. You can print the bytecode for one line:

Python 3.12 prints the following (other versions differ in the details):

  0           0 RESUME                   0

  1           2 LOAD_NAME                0 (price)
              4 LOAD_CONST               0 (3)
              6 BINARY_OP                5 (*)
             10 STORE_NAME               1 (total)
             12 RETURN_CONST             1 (None)

Each of those lines is one step of the interpreter's loop: fetch the value of price, fetch the constant 3, multiply them, store the result in total. None of it is machine code; the interpreter, which is itself a compiled C program, carries out each step.

Errors show up when the line runs

Because an interpreter executes as it goes, a program can do real work before it hits a mistake. Run this and the first two lines print before the crash:

Step 1: starting
Step 2: still fine
Traceback (most recent call last):
  ...
ZeroDivisionError: division by zero

A syntax mistake behaves differently, because CPython compiles the whole file to bytecode before running any of it. Change line 3 to print("Step 3:" 10) (the comma is missing) and nothing prints at all, not even Step 1:

SyntaxError: invalid syntax. Perhaps you forgot a comma?

So "an interpreter runs code line by line" is only half true. Grammar is checked for the whole file first; everything else, such as dividing by zero or using a name that does not exist, is found only when that line executes. See syntax error for the first kind.

Compiler vs interpreter

A compiler translates the whole program into a separate file before it runs. An interpreter runs the program itself, every time. The practical differences follow from that:

CompilerInterpreter
When the work happensOnce, before the program runsEvery time the program runs
OutputA separate file (executable or bytecode)No separate program file
What you give usersThe compiled programThe source code, plus the interpreter installed on their machine
Error checkingSyntax and, in typed languages, type errors for the whole program before it runsSyntax is usually checked first; other errors appear when the faulty line runs
Edit and runRecompile after every changeSave and run again
SpeedFaster, the CPU runs machine code directlySlower, every instruction is decoded while the program runs
PortabilityRecompile for each CPU and operating systemThe same source runs anywhere the interpreter exists
Typical languagesC, C++, Rust, GoPython, Ruby, PHP, Bash

The speed gap is real for tight loops of arithmetic: the same loop can run many times faster as compiled C than in CPython. For programs that mostly wait on the network, disk or the user, the difference is often too small to notice.

Compiled or interpreted is not a property of the language

A language is a set of rules; the compiler or interpreter is a program that implements them. The same language can be run both ways, and most popular ones mix the two:

  • Python. CPython compiles to bytecode and interprets it. PyPy, another implementation, adds a just-in-time (JIT) compiler that turns frequently run code into machine code while the program runs.
  • Java. javac compiles source to bytecode ahead of time. The Java Virtual Machine then interprets that bytecode and JIT-compiles the busiest methods to machine code. Since Java 11, java Main.java runs a single source file directly by compiling it in memory first.
  • JavaScript. Browsers and Node.js use engines such as V8, which start by interpreting the code and compile the hot parts to machine code as the program runs.
  • C and C++. Almost always compiled ahead of time with GCC, Clang or MSVC.
python3 app.py            # Python: interpreter, bytecode behind the scenes
node app.js               # JavaScript: V8 interprets, then JIT-compiles
javac Main.java           # Java step 1: compile to Main.class
java Main                 # Java step 2: the JVM runs the bytecode

Whichever it is, the interpreter or virtual machine is part of the program's runtime environment: it must be installed wherever the program runs.

Common misconceptions

  • "An interpreter translates each line into machine code." A classic interpreter never produces machine code for your program. It reads an instruction and performs it using code that was already compiled into the interpreter. Producing machine code at run time is what a JIT compiler does.
  • "Interpreted languages have no compile step." CPython, Ruby's YARV and PHP all compile to bytecode first. The step is automatic and invisible, so it is easy to miss.
  • "Interpreted means slow." JIT compilation closed much of the gap. V8 runs JavaScript fast enough for large applications such as VS Code, which is built on Electron.
  • "Python is the interpreter." Python is the language. CPython, PyPy and MicroPython are different interpreters for it, and they can differ in speed and in which libraries they support.

Where to go next

For the other half of the comparison, read what a compiler is and how it turns source code into machine code. The runtime environment page explains what else the interpreter brings with it. To try an interpreter yourself, run a Python script or open the Python playground.

Frequently Asked Questions

Is Python a compiler or an interpreter?
Python is a language; the program that runs it is usually CPython, which is an interpreter. CPython first compiles your code to bytecode automatically and then interprets that bytecode. Other implementations exist, such as PyPy, which adds a JIT compiler.
Is C++ an interpreter or a compiler?
C++ is a language, and it is almost always compiled ahead of time with a compiler such as GCC, Clang or MSVC. The result is a native executable for one CPU and operating system. Interactive tools for C++ exist, but they compile each piece of code behind the scenes.
Which is faster, an interpreter or a compiler?
A compiled program usually runs faster, because the CPU executes machine code directly instead of an interpreter decoding each step. An interpreter starts faster, since there is no separate build. JIT compilers, used by the JVM and V8, narrow the gap by compiling the busiest code while the program runs.
What is a REPL?
A REPL (read, evaluate, print, loop) is an interactive prompt where an interpreter runs each line as soon as you type it and shows the result. Typing python3 or node with no file name opens one. It is useful for testing a small idea without creating a file.
Can a language be both compiled and interpreted?
Yes. Compiled or interpreted describes an implementation, not the language. Java is compiled to bytecode by javac and then interpreted and JIT-compiled by the JVM, and there are both interpreters and compilers for languages such as Python and JavaScript.
Coddy programming languages illustration

Learn to code with Coddy

GET STARTED