In this article
  1. Before you start
  2. Why interviewers ask this
  3. Little-endian from first principles
  4. Worked example
  5. Trade-offs and edge cases
  6. How to answer it in an interview
  7. Common mistakes
  8. Follow-up questions
  9. Sources

Before you start

This page is one step of the coding interviews learning path.

Why interviewers ask this

Byte order is the reason the same file or network message can read as two different numbers on two machines, and a candidate who cannot say why is usually someone who has never debugged a binary format. Interviewers raise it in systems, embedded, networking and low-level coding rounds, and in "parse this binary header" exercises. It also comes up when a Python interview turns to the struct module, and in parallel processing questions where separate machines exchange binary data.

A weak answer says "little-endian means the bytes are reversed." A strong answer says what is reversed relative to what, names the address where each byte lands, says when it matters (only when bytes cross a boundary between machines, files or programs), and gives the standard fix: agree on one order for the wire and convert at the edges. The worked example below uses one number so you can check every byte by hand.

Little-endian from first principles

Byte order
Byte order is the rule that decides which byte of a multi-byte number is stored at the lowest memory address; it is also called endianness.
Little-endian
Little-endian is a byte order that stores the least significant byte of a multi-byte number at the lowest address, so the small end of the number comes first in memory.
Big-endian
Big-endian is a byte order that stores the most significant byte of a multi-byte number at the lowest address, so the big end of the number comes first, as when a number is written on paper.

In plain words

Think of writing a date. Day, month, year puts the smallest unit first. Year, month, day puts the biggest first. Both name the same day. Little-endian is the "smallest unit first" style for the bytes of a number; big-endian is the "biggest unit first" style. The analogy breaks in one place: people can see which style a date uses. A computer sees only byte values, so something outside the bytes must say which order was used.

In precise terms, take a number stored in several bytes. Little-endian puts the byte worth the least at the lowest address. It puts the byte worth the most at the highest address.

Step 1: A number is a row of bytes

A single byte holds 0 to 255, so any larger number needs several bytes. The 32-bit number 0x12345678 needs four, and hexadecimal makes the split easy to see: each pair of hex digits is one byte. The four bytes are 0x12, 0x34, 0x56 and 0x78. Their weights differ: 0x12 is the most significant byte and 0x78 the least significant. Each position is worth 256 times the one to its right, because a byte has 256 values, as a decimal position is worth ten times the next.1

For four bytes the place values are 256 cubed = 16,777,216, 256 squared = 65,536, 256 and 1. In decimal, 0x12 is 18, 0x34 is 52, 0x56 is 86 and 0x78 is 120, so the whole value is 18 x 16,777,216 + 52 x 65,536 + 86 x 256 + 120 = 301,989,888 + 3,407,872 + 22,016 + 120 = 305,419,896.1

Input: one number. Output: four bytes, each with a weight. Byte order decides how to place them in memory.

Step 2: Memory gives every byte an address

Memory is a row of byte-sized boxes numbered 0, 1, 2, 3 and upward. To store a four-byte number the computer needs four neighbouring boxes, say addresses 0 to 3, and it must decide which of the four bytes goes in which box. The program refers to the number by its first address, the lowest of the four. This is why the phrase "lowest address" appears in every definition: the first box is where code starts reading, and it is the box that either holds the big end or the small end of the number.

There are two main choices, big end first or small end first, and both are used; a few older machines mixed them, as noted under trade-offs below. Each gives the same number when it is read back with the same rule, which is why a program that reads whole numbers back with the same rule never notices.

Step 3: Big-endian puts the big end first

Big-endian stores 0x12345678 as 12 34 56 78 at addresses 0, 1, 2 and 3.1 Reading memory upward from address 0 gives the digits in the order of the written hexadecimal literal. The Internet Protocol specification fixes this order for data on the wire: Request for Comments (RFC) 791, Appendix B (September 1981) says multi-byte numbers are transmitted with the most significant octet first, where an octet is a byte. That wire order is called network byte order.

The Python standard library names the same thing. In a struct format string, the character > means big-endian and ! means network order, which is always big-endian (Python documentation, as of October 2026).

Step 4: Little-endian puts the small end first

Little-endian stores the same number as 78 56 34 12.1 The first box, address 0, holds 0x78, the least significant byte. The reason hardware designers like it is practical: a program that reads only the low byte of a number, or widens a 16-bit value to 32 bits, can use the same starting address, because the low byte is always first. The Python documentation lists Intel x86, AMD64 (x86-64) and Apple M1 as little-endian and IBM z as big-endian; sys.byteorder reports the host's order (Python documentation, as of October 2026).

The danger is on the reading side. If the bytes 78 56 34 12 are read as little-endian they give 305,419,896; read as big-endian they give 2,018,915,346.1 Both are valid 32-bit numbers, so no error is raised. The big-endian reading puts the weights the other way round: 120 x 16,777,216 + 86 x 65,536 + 52 x 256 + 18 = 2,013,265,920 + 5,636,096 + 13,312 + 18 = 2,018,915,346.1

Byte order decides which byte lands at the lowest addressBoxes in four steps: the number 0x12345678 is four bytes, big-endian fills addresses 0 to 3 with 12 34 56 78, and little-endian fills the same four addresses with 78 56 34 12.0x12345678four bytes 12 34 56 78Addresses 0 to 3four boxesAddress0big: 12Address1big: 34Address2big: 56Address3big: 78Address0little: 78Address1little: 56Address2little: 34Address3little: 12Diagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/little-endian.html

Big-endian and little-endian store the same four bytes in opposite orders, so every address holds a different byte.CC BY 4.0 — source: What is little-endian byte order?
Step-by-step description
  1. A 32-bit number is four bytes.
  2. Memory gives each byte an address.
  3. The big end goes first: 12 34 56 78.
  4. The small end goes first: 78 56 34 12.
  • The number 0x12345678 is made of four bytes.
  • Big-endian stores 12 34 56 78 at addresses 0, 1, 2 and 3.
  • Little-endian stores the same number as 78 56 34 12.

Knowing it is half the job. Saying it is the other half.

Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.

Start Free Trial →

Worked example

The check takes one number and a few lines of Python. Pack 0x12345678 as a 32-bit unsigned integer with each order, print the bytes in hexadecimal, and read the little-endian bytes back both ways:

import struct
v = 0x12345678
print(struct.pack(">I", v).hex(" "))   # 12 34 56 78
print(struct.pack("<I", v).hex(" "))   # 78 56 34 12
print(struct.pack("!I", v).hex(" "))   # 12 34 56 78
b = struct.pack("<I", v)
print(int.from_bytes(b, "little"))     # 305419896
print(int.from_bytes(b, "big"))        # 2018915346

> is big-endian, < is little-endian and ! is network order, the same as big-endian.1 The byte at the lowest address is 18 (0x12) for big-endian and 120 (0x78) for little-endian.1

In every layout the same four bytes appear, but little-endian puts 78 at the lowest address while big-endian and network order put 12 there.
LayoutAddress 0Address 1Address 2Address 3
Big-endian12345678
Little-endian78563412
Network order12345678

The same pattern holds for shorter numbers. The 16-bit number 1023 (0x03FF) packs to 03 ff in big-endian and ff 03 in little-endian, which matches the example in the Python documentation.1 The 16-bit number minus 2 packs to fe ff in little-endian and ff fe in big-endian.1 A common file sample rate, 44,100, is stored in a little-endian 32-bit field as 44 ac 00 00.1

Converting between the orders is a byte swap. Four shifts and masks do it for 32 bits: move the lowest byte to the top, the second byte up one place, the third byte down one place, the top byte to the bottom. In Python the expression is ((x & 0xFF) << 24) | ((x & 0xFF00) << 8) | ((x >> 8) & 0xFF00) | ((x >> 24) & 0xFF). Applying that swap to 0x12345678 gives 0x78563412, which is the big-endian reading of the little-endian bytes.1

A 32-bit byte swap turns 0x12345678 into 0x78563412Six lines of working: the four bytes of 0x12345678, each of the four bytes moved to its mirror position, and the swapped result 0x78563412.x = 0x12345678Bytes 12 34 56 78, high to low.(x & 0xFF) << 24 = 0x78000000The lowest byte moves to the top.(x & 0xFF00) << 8 = 0x00560000The second byte moves up one place.(x >> 8) & 0xFF00 = 0x00003400The third byte moves down one place.(x >> 24) & 0xFF = 0x00000012The top byte moves to the bottom.swap32(x) = 0x78563412The four moved bytes combined.Diagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/little-endian.html
Reversing the four bytes turns one reading of the memory into the other.CC BY 4.0 — source: What is little-endian byte order?
Text description of the diagram
  • Converting between the orders is a byte swap.
  • Applying that swap to 0x12345678 gives 0x78563412.
Reading integer bytes in the wrong order gives a valid wrong numberThree lines: the stored bytes are 78 56 34 12, read as little-endian they give 305,419,896, and read as big-endian they give 2,018,915,346.bytes = 78 56 34 12As stored at addresses 0 to 3.little = 305,419,896Correct reading: 0x12345678.big = 2,018,915,346Wrong reading: 0x78563412.Diagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/little-endian.html
Reading integer bytes in the wrong order gives a valid number that is wrong, not an error.CC BY 4.0 — source: What is little-endian byte order?
Text description of the diagram
  • If the bytes 78 56 34 12 are read as little-endian they give 305,419,896.
  • Read as big-endian they give 2,018,915,346.
  • Both are valid 32-bit numbers, so no error is raised.

Trade-offs and edge cases

Neither order is faster in general, and the choice is a convention, not a quality difference. Danny Cohen's 1980 paper made that point by borrowing the names from Jonathan Swift's Gulliver's Travels, where two camps fight over which end of an egg to break first; he argues that agreeing on one order matters more than which one (Cohen, Internet Experiment Note (IEN) 137, 1 April 1980). The same paper also discusses older machines whose 32-bit values mixed the two orders. The practical consequences are these.

Byte order applies only to numbers wider than one byte. A single byte has no order, and a text encoding such as UTF-8 is defined as a byte sequence, so a UTF-8 string reads the same on every machine. Wider encodings such as UTF-16 do have an order and need a marker or an agreed convention.

The order is a property of the format, not only the machine. A file format or a protocol fixes its own order: the Internet Protocol uses big-endian on the wire, while a file format may choose either order. A portable program reads such a field with an explicit order, as in int.from_bytes(data, "little"), instead of relying on the machine's native order.

Bit order is a different question. Byte order says which byte comes first; it does not say how the bits inside a byte are numbered, and most interview questions mean byte order. Bit-level questions such as Hamming distance are unaffected by byte order as long as both values are read with the same rule.

Machine learning meets it too. A model file that stores tensors as raw bytes needs a byte order for its 16-bit floats, and reading them with the wrong order does not give plausible weights. In a saved test, 200,000 weights drawn from a normal distribution with mean 0 and standard deviation 0.02 were stored as little-endian 16-bit floats and read back as big-endian: about 3% became NaN (not a number) or infinity, and about half of the rest had a magnitude above 1, where the true weights are almost all below 0.1. The value 1.0 read back as 3.6e-6.2

Unlike a wrongly read integer, this failure is usually loud, but only if someone checks the values. A byte swap reverses the bytes of one number the way reversing a string reverses characters, but it never applies to a UTF-8 string, whose bytes have no order to fix.

How to answer it in an interview

Interviewer asks

What is little-endian, and when does it matter?

A strong answer

Little-endian stores the least significant byte of a multi-byte number at the lowest address, so 0x12345678 sits in memory as 78 56 34 12; big-endian stores 12 34 56 78. Within one program you never notice, because reads and writes use the same rule. It matters when bytes cross a boundary: a file, a network message or another machine. Reading an integer with the wrong order gives a valid but wrong number, not an error. I fix it by defining one order for the format, network order on the wire, and converting explicitly at the edges.

The spoken structure: say the definition with a four-byte example, say when it matters, say the failure mode, then say the fix.

Common mistakes

  • "Little-endian means the bits are reversed." (wrong) Byte order is about whole bytes, not the bits inside each byte. (right) "It reverses the order of the bytes, not the bits."
  • "It only matters on old computers." (wrong) x86-64 and Apple M1 machines are little-endian today, while Internet Protocol headers use big-endian, so conversion happens whenever the two meet. (right) "It matters whenever bytes cross a machine, file or protocol boundary."
  • "A text string needs byte swapping like an integer." (wrong) A byte-oriented encoding such as UTF-8 has no byte order. (right) "Only multi-byte numbers, and wider encodings such as UTF-16, have an order."
  • "I will just cast the buffer to an integer." (wrong) The cast uses the machine's order, so the result changes between machines. (right) "I will parse each field with an explicit order."

Follow-up questions

Is x86 little-endian or big-endian?

x86 and x86-64 (AMD64) processors are little-endian, as are Apple M1 machines according to the Python documentation. Big-endian hardware still exists, for example IBM z, and portable code must not assume either.

What is network byte order?

Network byte order is big-endian: multi-byte numbers in internet protocol headers are sent with the most significant byte first, as RFC 791 specifies. A program converts from host order to network order before sending and back after receiving.

How do you check the byte order of a machine?

Store a known multi-byte number, look at the byte at the lowest address, and compare. In Python, sys.byteorder is "little" or "big"; the computed run on this page printed "little".1

Does endianness affect single bytes or text?

A single byte has no order, and UTF-8 text is a byte sequence with no order either. Numbers wider than one byte and encodings with 16-bit or 32-bit units do have an order.

Why do people argue about which order is better?

Neither wins on speed in general; each makes some operations easier. Little-endian lets code read the low byte of a value from its first address, and big-endian makes dumps read like the written number. Cohen's 1980 paper argues the agreement matters more than the choice.

Key takeaways
  • Little-endian stores the least significant byte at the lowest address; big-endian stores the most significant byte there.
  • 0x12345678 is 78 56 34 12 in little-endian and 12 34 56 78 in big-endian.
  • Network byte order is big-endian; convert at the edges of a format.
  • A wrong-order read of an integer gives a valid but wrong number, not an error.
  • Byte order applies only to numbers wider than one byte.

Sources

  1. On Holy Wars and a Plea for Peace (IEN 137) — Danny Cohen, USC/ISI, 1 Apr 1980
  2. RFC 791: Internet Protocol, Appendix B, Data Transmission Order — IETF (RFC Editor), 1 Sep 1981
  3. struct: Interpret bytes as packed binary data (Python documentation) — Python Software Foundation (date = read date), 25 Oct 2026