Machine code, also called machine language, is the set of binary-encoded instructions that a processor executes directly, without any further translation. Among the software fundamentals, it marks the boundary between software and hardware: every program, whether written in C, Rust, Java or Python, must ultimately become machine code before a CPU can act on it.
Each instruction is a pattern of bits defined by the processor’s instruction set architecture (ISA), such as x86-64, ARM64 or RISC-V. Machine code is therefore specific to a processor family, which is why an executable file built for one architecture does not run natively on another.
How machine code is structured
A machine code instruction is a fixed or variable sequence of bytes that encodes one elementary operation. The instruction typically contains an opcode, which names the operation, and one or more operand fields, which identify registers, memory addresses or immediate constant values.
The processor runs machine code through the fetch-decode-execute cycle. It fetches the bytes at the address held in the program counter, decodes them into control signals, performs the operation and then advances to the next instruction or jumps elsewhere when a branch is taken. Modern CPUs pipeline and reorder this work internally, but the visible result must match strict sequential execution.
The following table lists the main fields found in a typical instruction encoding.
| Field | Purpose | Example content |
|---|---|---|
| Opcode | Selects the operation | Add, load, branch, compare |
| Register specifier | Names a source or destination register | Register x5 or RAX |
| Immediate value | Embeds a constant in the instruction | The number 42 |
| Addressing mode | Defines how a memory address is formed | Base register plus offset |
| Prefix or modifier | Changes operand size or behavior | 64-bit operand override on x86 |
Instruction length depends on the architecture. Fixed-length encodings such as the 32-bit instructions of ARM64 simplify decoding, while variable-length encodings such as x86-64, where an instruction spans from 1 to 15 bytes, achieve denser code at the cost of more complex decoders.
Machine code compared with assembly, bytecode and source code
Machine code sits at the lowest level of the abstraction hierarchy, and nearby representations are often confused with it. Assembly language is a human-readable notation in which each mnemonic usually maps one-to-one to a machine instruction, whereas source code in a high-level language maps to many instructions per statement.
The table below compares machine code with the representations that precede or replace it.
| Representation | Readable by | Executed by | Portability |
|---|---|---|---|
| Source code | Programmers | Compiler or interpreter first | High |
| Assembly language | Specialists | Assembler first | Tied to one ISA |
| Bytecode | Tools and virtual machines | Virtual machine or JIT compiler | High across platforms |
| Machine code | The processor | CPU hardware directly | Tied to one ISA |
Bytecode for the Java Virtual Machine or WebAssembly is sometimes called machine code for a virtual machine, but it is not executed by physical hardware. A runtime either interprets it or uses just-in-time (JIT) compilation to generate real machine code while the program runs.
How programs become machine code
Programs reach machine code through a translation pipeline that differs by language and toolchain. In ahead-of-time compiled languages, a compiler translates source code to object files containing machine code, and a linker combines them with libraries into an executable file.
The next table summarizes the main paths from source code to executed instructions.
| Strategy | When machine code appears | Typical languages | Main trade-off |
|---|---|---|---|
| Ahead-of-time compilation | Before distribution | C, C++, Rust, Go | Fast startup, separate builds per ISA |
| Just-in-time compilation | During execution | Java, C#, JavaScript | Portable, but warm-up cost |
| Interpretation | Never for the program itself | Classic Python, shell scripts | Simple, but slower execution |
| Assembly by hand | At assembly time | Firmware, boot code | Full control, low productivity |
The executable does not contain raw instructions alone. Container formats such as ELF on Linux, PE on Windows and Mach-O on macOS wrap machine code with headers, symbol tables, relocation data and references to shared libraries that the operating system loader resolves at launch.
Instruction set architectures and compatibility
The instruction set architecture defines the contract between machine code and hardware: the available instructions, registers, memory model and encoding rules. Two chips from different vendors can run the same machine code when they implement the same ISA, even though their internal designs differ greatly.
The following table compares widely used instruction set architectures.
| ISA | Design style | Instruction length | Typical use |
|---|---|---|---|
| x86-64 | CISC | 1 to 15 bytes | Desktops, laptops, servers |
| ARM64 (AArch64) | RISC | 4 bytes | Phones, Apple silicon, cloud servers |
| RISC-V | RISC, open standard | 2 or 4 bytes | Microcontrollers, research, embedded |
| Xtensa and similar | Configurable RISC | 2 or 3 bytes | Embedded software in IoT devices |
When software must run on a foreign architecture, systems use binary translation or emulation. Translation layers convert x86-64 machine code to ARM64 either before execution or on the fly, typically with a moderate performance penalty that depends on the workload.
Limitations, risks and common misconceptions
Machine code offers maximum control and minimal overhead, but it is costly to write, read and maintain. A single source change can alter thousands of bytes, and disassembly recovers only instructions, not variable names, comments or the original program structure.
- Machine code is not always faster by definition. Optimizing compilers usually produce better instruction sequences than hand-written code for large programs.
- Binary does not mean secret. Disassemblers and decompilers can reconstruct much of a program’s logic, so machine code offers no real protection for secrets.
- Same operating system is not enough. A Windows executable for ARM64 does not run natively on an x86-64 Windows machine.
- Memory errors become exploitable. Flaws such as buffer overflows let attackers redirect execution, which is why protections like non-executable memory and address space layout randomization exist.
Self-modifying machine code, once common for saving memory, is now discouraged and often blocked by operating systems that separate writable memory from executable memory. JIT compilers handle this carefully by switching page permissions between writing and executing.
In everyday language
Machine code is the only language a computer chip truly understands. It is a long series of numbers, each one telling the processor to do one very small thing, such as adding two values or jumping to another step.
People rarely write it directly. Instead, they write programs in friendlier languages, and tools translate those programs into machine code. A useful comparison is a piano roll: the holes in the paper are meaningless to most people, yet the player piano reads them perfectly. The key point is that every app eventually becomes machine code, and that code fits only one family of chips.
Seen in the real world
A development team maintains a command-line tool written in Go and distributes it to customers on both Intel-based Linux servers and ARM-based cloud instances. The compiler turns the same source code into two different machine code binaries: one for x86-64 and one for ARM64, each packaged as an ELF executable of about 12 MB.
When a customer accidentally deploys the x86-64 build to an ARM64 server, the system refuses to start it with an “exec format error”. The team adds an automated build step that produces both binaries and labels each by architecture. Deployment failures of this kind disappear, and the ARM64 build runs roughly as fast as the x86-64 one on comparable hardware, at a lower hourly cost.