Back

Blog details

How Does IPFS Work? Merkle DAGs, Chunking, and Routing

AIOZ Network
6 min readAugust 20, 2026
aioz-pin
AIOZ Pin header image reading How Does IPFS Work? Merkle DAGs, Chunking, and Routing

IPFS works by splitting a file into blocks, hashing each block, and linking them into a Merkle DAG whose root hash becomes the file's CID. A DHT tells other nodes who holds those blocks, Bitswap moves them, and every block is checked against its hash on arrival.

TL;DR:

  • Every file on IPFS becomes a Merkle DAG: blocks named by their hashes, with parent blocks listing the CIDs of their children.
  • Kubo splits files into 256 KiB blocks by default. Other chunkers exist, and the choice changes the CID.
  • The CID of the root block names the whole file. Change one byte and the root CID changes.
  • Finding who has a CID (the DHT) and moving the blocks (Bitswap) are two separate protocols.
  • Pinning keeps a node holding the blocks, so the network always has a provider to find. That is the job AIOZ Pin does for you.

Updated Nov 30, 2026: carried one 10 MiB video through every step, added a common-mistakes section, moved links onto nouns, tightened the ending.

IPFS in Seven Steps

Here is the full path a file takes, from your disk to someone else's screen, with one 10 MiB video as the example throughout. Each step links to its own post in this series.

Seven-step diagram of how IPFS works: split your file into blocks, hash each block, link them into a DAG, get the root CID, provide records to the DHT, another node finds the CID in the DHT, then fetches blocks with Bitswap and checks each hash
Steps 1 to 4 happen on your machine. Steps 5 to 7 happen on the network.

What Is a Merkle DAG in IPFS?

A Merkle DAG is a directed acyclic graph where each node is named by a hash of its contents. In IPFS, a parent node's contents include the CIDs of its children, so a parent's hash depends on its children's hashes and the root hash depends on everything below it.

That chain is what makes the structure useful. Change one byte in the video and one leaf block gets a new CID, which changes its parent's list of links, and so on up to the root, while every other leaf keeps its CID. Two identical blocks always get the same CID, so a DAG can point at one stored copy from many places. Git uses the same idea for commits; IPFS applies it to any file or folder, and the Mutable File System rebuilds that chain on each edit.

The data model underneath is IPLD, which defines the codecs and the link format that every DAG node uses.

From File to Blocks: Why Chunking Happens First

Before a file becomes a DAG, IPFS splits it into blocks, and Kubo's default chunker cuts fixed-size blocks of 262,144 bytes, which is 256 KiB. A small file fits in one block, while the 10 MiB video (10,485,760 bytes) becomes 10,485,760 / 262,144 = 40 leaf blocks, plus one parent that links them: 41 blocks in all.

Blocks give you two things: transfers can run in parallel and resume where they stopped, because each block is fetched and checked on its own. Storage can also be shared, because identical blocks in different files have the same CID and only need to be stored once.

How the split points are chosen matters when files get edited. Fixed-size chunks shift after an insert, while content-defined chunking keeps more blocks stable. Very large folders get one more structure, a HAMT, explained in how IPFS shards large directories.

What Does a CID Look Like?

A CID is a self-describing name for one block. It packs a version, a codec that says how to read the block, and a multihash: the hash function, the digest length, and the digest. Version 1 CIDs are usually shown in base32, which is why they start with b.

You can compute a CID for a single raw block with the Python standard library. We ran this on our machine, and the multiformats JavaScript library (9.9.0) gives the same CID for the same bytes:

$ python3 -c 'import base64,hashlib; d=hashlib.sha256(b"hello from aioz pin\n").digest(); print("b"+base64.b32encode(bytes([1,0x55,0x12,0x20])+d).decode().lower().rstrip("="))'
bafkreiciuqus57wedvnzisfyydrze2ffnymhsgqafkwqx7kfh7cz72izbq

The bafkrei prefix comes from the fixed header bytes: version 1, the raw codec, and sha2-256. A file larger than one block gets a dag-pb root instead, which starts with bafybei as a version 1 CID. Kubo still defaults to version 0 CIDs, which start with Qm.

How Does IPFS Find Content?

Once your blocks exist, other nodes need a way to find you, and IPFS uses a Kademlia DHT for this. Peers and content share one address space built from SHA-256 hashes. A node that holds a block publishes a provider record on the 20 peers closest to that block's position. A node looking for the block walks toward the same position and reads the records.

Provider records expire, so Kubo re-announces content every 22 hours by default, the cycle explained in why provider records get renewed.

Moving Content: Bitswap

Bitswap does the transfer: your node sends want-have for the video's root CID to peers it is already connected to. Peers with the block answer have, and your node asks them for it with want-block, then repeats the exchange for the 40 leaves the root lists. If no connected peer has a block, Bitswap asks the DHT for providers and tries again with them. How fast this finishes depends on connection setup, routing and block transfer together, as the IPFS retrieval speed breakdown shows.

Every block that arrives is hashed and compared with the CID you asked for, and a bad block is rejected, so you can download from strangers safely. The full retrieval sequence and the hash check each have a post of their own. In JavaScript, you can run this check with the Helia JavaScript implementation and its verified-fetch module.

Common Mistakes When Reasoning About IPFS

  • Expecting one file to have one CID. Chunk size, CID version and raw leaves all change the root CID, so the same video added with two settings gets two CIDs. The anatomy of a CID shows which bytes differ.
  • Expecting an edit to keep the CID. The one changed byte gives the video a new root CID, so links to the old CID still serve the old version.
  • Treating the DHT as storage. It holds provider records, not blocks, so once the last provider of a CID goes offline, the DHT has nobody to point you to.

How AIOZ Pin Handles It

The takeaway: a CID names content and proves it on arrival, but the content stays reachable only while some node keeps the blocks and announces them. What AIOZ Pin adds, without changing the protocol, is a node that keeps holding your blocks: pinned content becomes available on the public IPFS network, and our public and premium gateways serve it over HTTP.

Step 5 is the weak point. A recursive pin on the video's root CID keeps all 41 blocks, and once nothing pins them, they disappear when the last holder runs garbage collection. Filecoin is a separate protocol that adds paid, proven storage on top of content addressing.

A pin moves through three statuses: Pinning, Pinned, and Failed. You can start from a file you have, as in the documented upload below (not run here, no credentials on this machine), or pin a CID that is already on IPFS.

curl --location --request POST 'https://api.aiozpin.network/api/pinning/' \
  --header 'pinning_api_key: KEY' \
  --header 'pinning_secret_key: SECRET' \
  --form 'file=@"/test.png"'

The response includes the cid for your file. To pin your first file step by step, follow the AIOZ Pin quick start.

Frequently Asked Questions

How does IPFS work in one sentence? IPFS splits a file into hashed blocks linked into a Merkle DAG named by a CID, then uses a DHT to find who holds those blocks and Bitswap to move them.

Is IPFS's data structure a B-tree? No. The core structure is a Merkle DAG. Very large directories use a HAMT, which is a hash-based trie, not a B-tree.

Why does IPFS split files into blocks? Blocks can be fetched from several peers in parallel and checked one by one, and identical blocks are stored only once.

What is the default IPFS block size? Kubo's default chunker uses fixed 256 KiB (262,144-byte) blocks. You can choose another chunker when you add a file.

Why does changing one byte change the whole CID? The changed block gets a new hash, so its parent's list of child CIDs changes, and that change carries up to the root.

Does AIOZ Pin change how IPFS works? No. AIOZ Pin uses standard IPFS and keeps your blocks pinned, so the network always has a provider for your CID.

References

We only send updates when meaningful changes ship, and you can unsubscribe anytime

Related Content

blog thumbnail

ENS IPFS Contenthash: Point an .eth Name at a Website

An ENS IPFS contenthash points your .eth name at a site on IPFS. See the byte format, a real encoding, ipfs vs ipns records, gas used, and common mistakes.

7 min readDecember 04, 2026
blog thumbnail

ERC-721 Metadata JSON: Fields, Images and ipfs:// URIs

ERC-721 metadata JSON explained: the three fields EIP-721 defines, OpenSea attributes and animation_url, ipfs:// image links, and folder CIDs for collections.

8 min readDecember 02, 2026
blog thumbnail

Merkle DAG vs Merkle Tree: What IPFS Changes and Why

Merkle DAG vs Merkle tree explained: a tree gives each node one parent and short proofs, while the DAG IPFS uses shares blocks, carries data and links by CID.

8 min readNovember 30, 2026
blog thumbnail

What Is IPNI? How the IPFS Network Indexer Finds Providers

IPNI is the IPFS network indexer behind cid.contact. See how index providers publish signed advertisement chains and how one HTTP query finds providers.

8 min readNovember 27, 2026
blog thumbnail

On-Chain vs Off-Chain NFT Metadata: Where the Data Lives

On-chain vs off-chain NFT metadata: what the contract stores, what lives on IPFS or a web server, what each costs in gas, and how to check any token yourself.

6 min readNovember 25, 2026
blog thumbnail

What Is a Kademlia DHT? The Routing Algorithm Behind IPFS

A Kademlia DHT finds peers by XOR distance. See how k-buckets, k = 20 and iterative lookups let IPFS locate who holds a CID, and how to watch it on Kubo.

6 min readNovember 23, 2026