You can check the architecture of most executable files by reading their header: the file command on Linux and macOS, dumpbin /headers for Windows PE files, and objdump -f, readelf -h, or Python's struct module all report the target machine and bitness directly. The key condition is bitness versus CPU family: an x86-64 binary differs from an ARM64 one, and 32-bit versus 64-bit matters just as much as Intel versus ARM. A file can also be architecture-independent, as with shell scripts, Java class files, source code, or Python bytecode, in which case the honest answer is that no compiled architecture exists.

People ask this question for practical reasons. A downloaded tool won't launch and throws "exec format error" or "bad CPU type in executable." A CI pipeline must route artifacts to the right runners. A security analyst wants to confirm that a suspicious binary labeled as a JPEG really is a Windows executable. Or a systems administrator has to confirm that a vendor's "universal" binary actually contains both slices for Apple silicon and Intel Macs.

The good news is that the formats are well documented and the checks are fast. The main pitfalls are picking the wrong tool for the format, forgetting fat and universal binaries that hold more than one architecture, and treating a file extension as evidence. Below is a worked approach, from the fast glance to the format-specific deep check, with real command output behavior you can match against.

Start With the Fastest Signal: The file Command

file is installed by default on macOS and nearly all Linux distributions, and it's the shortest path to a first answer. It inspects the leading bytes of a file (the "magic number") plus a small amount of the header and prints a human-readable summary.

Typical outputs you might see:

someprogram: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, ... — a Linux ELF binary for 64-bit Intel/AMD. someprogram: ELF 32-bit LSB executable, ARM, EABI5 ... — a 32-bit ARM Linux binary. someprogram: Mach-O 64-bit executable arm64 — an Apple-silicon macOS binary. someprogram: Mach-O universal binary with 2 architectures: [x86_64 ...] [arm64 ...] — a fat binary containing both slices. someprogram: PE32+ executable (console) x86-64, for MS Windows — a 64-bit Windows executable. someprogram: Java class data, version 65.0 — a JVM class file, which runs on any Java-capable architecture. someprogram: ASCII text — not compiled at all.

For a quick check, file gives you the format family, bitness, and target CPU in one line. Two limits matter. First, file depends on a magic database that may be stale on older systems, and its wording for newer architectures (for example, RISC-V) can lag. Second, and more importantly, on a universal or fat binary file will list all slices but not tell you which one the loader will pick at runtime — that depends on the machine executing it. If you need the loader's choice on macOS, lipo -archs file lists every architecture contained, and arch reports the host's preferred architecture.

Reading the Header Manually: Magic Numbers and Bitness

If no tool is available, or you want to verify what file is telling you, the first handful of bytes is enough. This is also the cleanest way to explain the concept of architecture checking.

Read the first 4 to 20 bytes with a hex dump:

Match the leading bytes:

Bytes (offset 0) Format What to read next
7f 45 4c 46 (\x7fELF) Linux/Unix ELF e_ident[EI_CLASS]: 01 = 32-bit, 02 = 64-bit. Then the e_machine field (2 bytes at offset 18) identifies the CPU.
4d 5a (MZ) DOS/Windows A pointer at offset 0x3C (4 bytes) points to PE\0\0. Follow it to reach the PE signature, then Machine (2 bytes) says the target.
ca fe ba be or fe ed fa ce Mach-O The first 4 bytes as a big- or little-endian integer say the magic; the CPU type and subtype follow in the next 8 bytes.
ca fe ba be (also fat) Mach-O universal/fat Ambiguity exists with Java; checked by following bytes and the actual cputype field. The file tool disambiguates.
50 4b 03 04 ZIP archive Not an architecture; contents may hold a .jar (JVM), a .whl, or an Android .apk containing native libs per ABI.

For ELF, the CPU identifier field e_machine uses documented constants: 0x3E is x86-64, 0xB7 is AArch64 (64-bit ARM), 0x28 is 32-bit ARM, 0xF3 is RISC-V, 0x08 covers MIPS-ish variants, and 0x15 is PowerPC 64-bit. Bitness comes from byte 4 of the identification block: 01 for 32-bit, 02 for 64-bit. That single byte explains the classic mismatch where a 32-bit binary fails to load on a 64-bit-only userland, or vice versa when a 64-bit binary is invoked on a 32-bit kernel.

For PE, the Machine field is a 2-byte value after the PE\0\0 signature: 0x8664 for x86-64, 0x014c for x86, 0xAA64 for ARM64, 0x01c4 for ARMv7 (Thumb-2). The optional header also has a Magic of 0x10b (PE32) or 0x20b (PE32+), which is what file calls PE32 or PE32+.

These are stable, documented format facts rather than tool-specific behavior, which makes manual inspection reliable even on an air-gapped machine with nothing but od or xxd. If you only remember one thing: for an unknown binary, the first four bytes decide which parser to use, and the bitness is often the fifth byte.

Platform-Specific Checks: Linux, macOS, and Windows

Each operating system ships tools that read the header with more structure than file.

Linux (ELF)

readelf -h someprogram prints the entire ELF header in labeled fields, including Class (ELF32/ELF64) and Machine (e.g., "Advanced Micro Devices X86-64"). It's the most readable choice and part of binutils, present on most distributions. objdump -f someprogram prints a short "file format" and "architecture" line, useful inside build scripts because the output is compact. file -b someprogram suppresses the filename prefix when you're parsing output programmatically.

macOS (Mach-O)

lipo -info someprogram and lipo -archs someprogram list the architectures in a universal binary — the single best check for the "does this app support Apple silicon and Intel?" question. file reports a single non-fat Mach-O's cputype as arm64 or x86_64, with the 64-bit bit in the flag. otool -h someprogram shows the Mach header including cputype and cpusubtype. Subtypes matter: arm64e binaries use pointer authentication and will not run on older arm64-only hardware under some conditions, so a plain "arm64" match is not always sufficient.

Windows (PE)

dumpbin /headers program.exe is shipped with Visual Studio tools and prints the "machine (x64)" line and optional-header magic, which tells you PE32 or PE32+. Get-Content program.exe -Encoding Byte alone is unwieldy; instead, in PowerShell you can read bytes 0..1 and check for MZ, then read offset 0x3C to find the PE header. Practical scripts exist for this, but the small header map in the previous section is enough to write your own. PowerShell's Get-Item and Get-AuthenticodeSignature tell you about signing, not architecture; do not conflate them.

The rule of thumb: on each platform use the native tooling when it's present. Where it isn't, file and a hex dump cover nearly every case.

Fat Binaries, Universal Stubs, and Multiple Architectures in One File

A common trap is assuming one file means one architecture. Apple's universal binaries pack several Mach-O slices into one "fat" container so one app runs natively on both Intel and Apple silicon. file will report "universal binary with 2 architectures," but if a slice is missing, the app will fail with a "bad CPU type" error on that hardware even though file looked reassuring.

The right check is to list every architecture with lipo -archs, confirm the one you need appears in the list, and confirm the slice you'll actually use is not a thin stub that just redirects. Apple's developer transition kit and some installer stubs are thin in the literal sense: one architecture only, with a runtime download for the other.

On Linux, fat binaries are rare but possible through custom ELF layouts or tools like patchelf; the honest check is to inspect readelf -h and confirm it reports one machine, then use file on the actual runtime output, not the launcher script. Scripts that exec a hidden payload are a frequent source of "wrong architecture" confusion when the wrapper is a shell script and the payload is binary.

A subtle edge case is a file that contains both a PE and an ELF header — some polyglot installers are built this way. file reports the first one it finds; if a user reports the wrong result, check both magic offsets manually. Bare metal or VM images (.iso, disk images) are another case where "architecture" is not a single property: an ISO contains multiple filesystems and sometimes multiple bootloader architectures, so file will only describe the image container.

Interpreted and Container Formats: When There's No Architecture

Not every file has a compiled architecture, and the cleanest check is to first confirm the format family.

Shell scripts, Python source, JavaScript, and configuration files are text. Their "architecture" is the interpreter, not the file. file reports "ASCII text" or "Unicode text," and the shebang line (#!/usr/bin/env python3) tells you the interpreter if you need it. Python bytecode (.pyc) is tied to the Python version and implementation, not the CPU. Its header magic encodes the Python version, so a .pyc built for CPython 3.13 fails on CPython 3.11 with a magic-number mismatch even on the same architecture. Java class files and .jar archives are bytecode for the JVM. file reports "Java class data, version N," where N maps to a class-file version (65 corresponds to Java 21). Running them requires a compatible JVM, not a matching CPU. WebAssembly .wasm files declare their target features in the module header but are portable to any engine that supports those features. The architecture question becomes "does this engine support reference types, SIMD, etc.?" rather than CPU bitness. Container images are layered tarballs; the architecture is a property of the manifest (e.g., an OCI platform.architecture field) or the binaries inside, so inspect the payload, not the .tar.

For these formats, the practical check is to confirm the interpreter or runtime version encoded in the file, then verify the host has it. The "architecture mismatch" symptom shifts from "exec format error" to messages like "object file was built for ABI version X" (GHC Haskell, for instance), "class file version not supported," or "magic number mismatch." The diagnostic habit is the same: read the file's declared target, then compare to the host.

Common Failure Symptoms and What They Tell You

The error message usually narrows the bug, and starting with reversible checks saves time.

cannot execute binary file: Exec format error on Linux means the kernel rejected the binary — usually the wrong e_machine or the wrong bitness, sometimes a missing interpreter in a shebang. Check readelf -h first, then uname -m for the host. bad CPU type in executable on macOS means a Mach-O slice missing for the current CPU. Fix by reinstalling the universal or native version, then verify with lipo -archs. not a valid Win32 application or a silent double-click failure on Windows often means a PE bitness mismatch (64-bit program run through a 32-bit-only subsystem) or a corrupted PE header. dumpbin /headers disambiguates. The program starts but crashes immediately with library errors. That's usually a dynamic-linker mismatch, not architecture. Verify the loader with readelf -l and ldd, and confirm the library's own architecture with file before suspecting the loader logic. No such file or directory for a file that exists, when you run an ELF binary, often means its shebang interpreter path (/lib/ld-linux...) does not exist on the host. This is a dynamic-linker environment mismatch even though the file's architecture might match.

A useful reversible check: run uname -m (or arch) on the host, run file on the target, and compare a few fields at a time. If those agree, move to the loader and libraries. If they don't, stop—fixing execution flags or chasing missing packages won't help a genuine CPU mismatch.

When to escalate: if you've matched architecture and bitness, checked the dynamic loader and its configured search paths, and the binary still refuses to run, it's worth involving whoever built the artifact or a platform engineer familiar with the deployment target. On production hosts, don't install additional toolchains or modify the loader configuration to force a suspect binary to run — those are changes that need proper ownership, and they can alter system behavior beyond the one program you're troubleshooting.

Worked Example: Diagnosing a Mismatch in a CI Pipeline

Suppose an artifact uploads and the deployment step fails on the runner. Walk it deliberately.

1: Identify the run context: does the failing command run on the same OS family the binary was built for? A mac binary on a Linux runner, or an arm64 slice on an amd64 runner, will fail regardless of tooling. The runner's architecture comes from uname -m in the job logs or the runner install manifest. 2: Run file on the artifact from a shell where you have access. Say it returns ELF 64-bit LSB executable, ARM aarch64, .... 3: Run uname -m on the failing runner. Say it prints x86_64. There's the mismatch: the artifact targets ARM64 and the runner is amd64. The artifact is fine; the runner is wrong for it. 4: If the runner is intended to be an ARM runner, check the runner binary's own architecture too, because mislabeled runners are common. Then rerun the job on an ARM runner. 5: If the runner is correct but the artifact is wrong, the build job is the culprit. Inspect the build job's image and base OS for its architecture (CI images vary between multi-arch and single-arch), then rebuild with the intended target triple. readelf -h on the new artifact confirms the e_machine matches. 6: Record the comparison in the pipeline: add a step that fails fast if file output does not contain the expected architecture token. This converts a downstream mystery into an immediate, readable error.

The arithmetic here is binomial and decidable: each artifact has a target, each runner has an architecture, and the two must be a compatible pair. No percentage estimates are needed or appropriate.

A second useful case: a developer reports that a shared object loads on their laptop but not on a test server. Compare file output on both machines. If one says x86-64 and the other aarch64, the laptop and server differ in CPU, so the shared object must be rebuilt for the server (or the server must run an emulator). If both match but the server has an older glibc, the failure is a version mismatch in the symbol table, not the CPU — diagnose it with readelf -V on the undefined symbols.

Reference Notes and What Each Tool Can and Can't Tell You

A short, consistent summary helps you pick the right tool once and avoid layering checks unnecessarily:

file is the universal first look: format family, bitness, and CPU family for ELF, PE, Mach-O, and common containers. It cannot tell you whether a runtime loader will choose a slice or whether a dynamically linked binary's dependencies match. readelf -h (ELF), dumpbin /headers (PE), lipo -archs and otool -h (Mach-O) are the format-native confirmations. They show declared targets, not deployment fitness. uname -m tells you the host architecture; compare, don't assume. On macOS, arch reports the current executable's preferred architecture, which can differ from hardware if Rosetta 2 is in play. The architecture check never proves that a binary will run. It only rules out one class of incompatibility. Library versions, kernel ABI, sandbox restrictions, and runtime configuration remain independent failure sources. On 32-bit and 64-bit mixed systems, bitness is the fifth ELF byte and the PE optional-magic. On macOS, cpusubtype values like arm64e can matter in addition to cputype.

None of these tools need network access, and none can substitute for live execution on the intended host. When a confirmed-matching binary still misbehaves, the file's architecture is no longer the explanation, and the investigation should move to libraries, environment, and the deployment target.

If your situation involves a regulated system, a vendor's signed component, or a firmware update for safety-relevant equipment, a local administrator or platform engineer should approve the execution path. That's general guidance rather than specific engineering or security advice, and it's the right escalation when production availability or safety is at stake.