# Bytes and endianness

Bitcoin stores most numbers least-significant byte first (little-endian), which is why txids and block hashes look reversed in raw data. Learn why.

Canonical page: https://mybitcoinexplorer.com/learn/bytes-and-endianness
Topic: Cryptography
Published: 2026-10-29
Updated: 2026-10-30


## Which end first?
A number bigger than 255 needs several bytes. **Big-endian** puts the biggest byte first, the way we write numbers. **Little-endian** puts the smallest byte first.

> Diagram: The block height 305,175 (0x0004a817) as written and as stored little-endian — 0004a817

## Where Bitcoin uses little-endian
- Version, locktime, sequence and amounts in transactions.
- Header fields: version, time, bits, nonce.
- Hashes: the bytes produced by SHA-256 are treated as a little-endian number.

## The reversed hash
Because hashes are little-endian internally, explorers **reverse** them for display. The txid you see in a wallet is the reverse of the raw hash bytes. When you use a txid inside a raw transaction input, you reverse it back.

> Interactive exercise: [open the lesson](https://mybitcoinexplorer.com/learn/bytes-and-endianness).

### Worked example: Reading an amount
The 8 bytes `00e1f50500000000` in an output are little-endian. Reversed: `0000000005f5e100` = 100,000,000 sats = 1 BTC.



## The most common mistake
Developers often search for a txid inside raw block data and can't find it, because the raw data holds the bytes in reverse order. Reverse the 32 bytes (not the characters) and it appears.

### Worked example: Reversing correctly
Hash as displayed: `a1b2c3d4…`. Reverse byte by byte: `…d4c3b2a1`. Reversing character by character (`…4d3c2b1a`) would be wrong.



## Key takeaways

- Little-endian stores the least significant byte first.
- Most numbers inside Bitcoin data are little-endian.
- Displayed txids and block hashes are byte-reversed.

## Common questions

### Why did Bitcoin use little-endian?

Most computers (x86) work natively in little-endian, and Satoshi's code wrote numbers directly from memory.

### Are scripts little-endian too?

Numbers pushed in scripts are little-endian, yes.

### Which Bitcoin values are big-endian?

Mostly data pushed in scripts such as public keys, and Bech32 address data. Numbers in transaction and header fields are little-endian.

### Do I need to reverse a txid to look it up?

No. Explorers and wallets expect the normal displayed form.

## Related lessons

- [Hexadecimal](https://mybitcoinexplorer.com/learn/hexadecimal)
- [Transaction IDs (txid)](https://mybitcoinexplorer.com/learn/transaction-id-txid)
- [Anatomy of a raw transaction](https://mybitcoinexplorer.com/learn/anatomy-of-a-raw-transaction)
- [The block header](https://mybitcoinexplorer.com/learn/block-header)
