Back

Blog details

UnixFS: How IPFS Represents Files and Directories

AIOZ Network
7 min readAugust 27, 2026
aioz-pin
AIOZ Pin cover titled "How IPFS Stores Files and Directories" over a close-up of a glowing iridescent circuit board

UnixFS is the data format IPFS uses to represent files and directories. The raw Merkle DAG only knows hash-linked blocks of bytes. UnixFS adds filenames, folders, symlinks and file sizes on top, so a CID can stand for a whole file or folder.

TL;DR:

  • The Merkle DAG is a generic hash-linked graph of blocks; on its own it has no idea of files, directories, or filenames
  • UnixFS is a protobuf format, encoded with the dag-pb codec, that adds file, directory and symlink meaning to DAG nodes
  • The DataType field has six values: Raw, Directory, File, Metadata, Symlink and HAMTShard, although the spec now marks Raw as deprecated and Metadata as reserved
  • Large files are split into chunks (256 KiB by default in Kubo) and stitched back together through a File node's filesize and blocksizes fields
  • Large directories switch to a HAMTShard layout once they pass a size threshold (256 KiB in Kubo), with a fanout of 256

Updated Nov 30, 2026: added importer runs on one 12-byte notes.txt, a common-mistakes list and in-sentence links; cut a docs-gap line and repeated FAQs.

Diagram of a UnixFS tree: a Directory node with named links beach.jpg and notes.txt; beach.jpg is a File node with filesize and blocksizes fields pointing to raw leaf chunks of up to 256 KiB; notes.txt fits in one block; a very large directory becomes a HAMTShard with fanout 256 past a 256 KiB threshold
How UnixFS turns a folder into DAG nodes. Defaults shown are Kubo's.

Why Does IPFS Need UnixFS?

The Merkle DAG that underlies all of IPFS is generic on purpose. It has nodes, links and hashes, and it makes no assumption about what the data inside a node means. That is why IPFS can carry many data formats on the same graph, not only files.

The cost of that generality is that the DAG can't answer the questions a filesystem needs. Is this node a file or a folder, what is it called, and how big is it? And if it is split across blocks, in what order do they go back together? UnixFS is the layer that answers them for you, every time you add a file or folder.

What Is UnixFS?

UnixFS is a protocol-buffers format for describing files, directories and symlinks on IPFS. Each UnixFS node is a dag-pb block whose Data field holds a small protobuf message. That message has a required Type field, plus optional fields for raw bytes, file size, block sizes and directory settings such as fanout.

To be precise, UnixFS is one way of reading the Merkle DAG, not a different storage system. The blocks and hashes are the same; a UnixFS-aware tool just knows how to read the extra structure. A tool that doesn't understand UnixFS can still fetch and verify every block, but it can't show you files and folders.

The Six UnixFS Node Types

The DataType enum in the UnixFS spec lists six values. Here is what each one does today:

  • Raw (0): bare data inside a dag-pb node. The spec now marks it deprecated and says to use blocks with the separate raw codec instead.
  • Directory (1): a folder whose links are named entries, which is how myfolder/photo.png resolves by name.
  • File (2): a file, either holding its bytes directly or linking to chunk blocks.
  • Metadata (3): reserved for future use.
  • Symlink (4): a symbolic link, preserved the way a Unix filesystem would keep it.
  • HAMTShard (5): one node of a sharded directory, used when a folder grows too large.

Day to day, you mostly meet File, Directory and HAMTShard nodes, plus raw leaf blocks if you add files with CIDv1. The spec also defines two optional fields from UnixFS 1.5, mode and mtime, for Unix permissions and modification times, and implementations only set them when you opt in.

How a Large File Becomes Many Blocks

Blocks have a practical size ceiling, so any big file you add has to be split. Kubo's default chunker cuts files into fixed 256 KiB pieces, and content-defined chunking is the alternative that picks cut points from the data itself.

The File node then links to those chunks, in order, and records two fields. filesize is the total length of the file, and blocksizes lists the size of each child. A UnixFS reader uses blocksizes to rebuild the file in the right order, whichever peers the blocks come from. The same list shows which blocks hold a byte range, so a reader can serve an HTTP Range request without fetching the whole file.

Very large files need more than one level, because Kubo caps a File node at 174 links by default, so beyond that it builds a tree of File nodes above the leaves. The leaves themselves are often not UnixFS nodes at all. With CIDv1, Kubo turns on raw leaves by default, so each chunk is stored as a plain raw block.

Take notes.txt from the diagram and give it the 12 bytes hello world\n. It fits in one chunk, so with raw leaves the whole file is one raw block, and Python's standard library can compute its CID. The recipe is the bytes 01 55 12 20 (CIDv1, raw codec, sha2-256, 32-byte length), then the SHA-256 digest, encoded as lowercase base32 with a b prefix:

# Run here with Python's standard library (no IPFS binary)
import hashlib, base64
data = b"hello world\n"
cid = bytes([0x01, 0x55, 0x12, 0x20]) + hashlib.sha256(data).digest()
print("b" + base64.b32encode(cid).decode().lower().rstrip("="))
# bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4

The bafkrei prefix is typical of a CIDv1 raw block with a SHA-256 hash. Import the same notes.txt with Kubo's default settings (CIDv0, dag-pb leaves) and the bytes are wrapped in a UnixFS File node first, so the CID changes. We checked both, and a folder, with the ipfs-unixfs-importer library that Helia uses, run here with Bun on Nov 30, 2026:

import { importer } from 'ipfs-unixfs-importer'
import { MemoryBlockstore } from 'blockstore-core'

const bytes = s => new TextEncoder().encode(s)

async function add (files, opts) {
  const out = []
  for await (const e of importer(files, new MemoryBlockstore(), opts)) {
    out.push(`${e.path || '(root)'}  ${e.cid}`)
  }
  return out.join('\n')
}

// Kubo's defaults: CIDv0, dag-pb leaves
console.log(await add([{ path: 'notes.txt', content: bytes('hello world\n') }],
  { cidVersion: 0, rawLeaves: false }))
// CIDv1 with raw leaves
console.log(await add([{ path: 'notes.txt', content: bytes('hello world\n') }],
  { cidVersion: 1, rawLeaves: true }))
// notes.txt inside a folder, then one byte changed
for (const text of ['hello world\n', 'hello world!']) {
  console.log(await add([{ path: 'docs/notes.txt', content: bytes(text) }],
    { cidVersion: 1, rawLeaves: true }))
}
notes.txt  QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o
notes.txt  bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4
docs/notes.txt  bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4
docs  bafybeia6c3p2byvm3xvcgnca26fbfcyscm2gd6irvdacxf35zacke5kmdu
docs/notes.txt  bafkreidvbhs33ighmljlvr7zbv2ywwzcmp5adtf4kqvlly67cy56bdtmve
docs  bafybeibqe4wdbb4c7pawu54ghinxdo24xtto3uz4ydufedirr4zef4yrje

The first two lines are the same 12 bytes under two settings, which is why the same file can end up with different CIDs. The second matches the stdlib result above. The last four lines put notes.txt in a folder named docs, then change its final byte.

How a Large Directory Becomes a HAMTShard

A plain Directory node stores its entries as one flat list of named links. That works until the folder is so big that the list itself becomes a huge block. Kubo switches a directory to sharding when its estimated size passes 256 KiB by default, and the spec gives 256 KiB to 1 MiB as the common range.

Past that point, the folder becomes a tree of HAMTShard nodes. The fanout field sets how many buckets each level has, and Kubo's default is 256, which uses 8 bits of the name's hash per level. For you, folder/file.txt still resolves the same way. Only the HAMT node structure behind it changes.

What Does This Mean When You Pin a Folder?

When you pin a folder's root CID recursively, you protect the whole UnixFS tree under it. That includes every File node, every chunk, every subdirectory and every HAMT shard, because each one is reachable by links from the root.

It also explains why changing one file in a folder changes the folder's CID. In the run above, turning the newline in notes.txt into ! keeps the file at 12 bytes, yet the docs folder moves from bafybeia6c3p... to bafybeibqe4w.... The file's CID changes, so the link in its parent changes, so every directory up to the root gets a new hash. A static website hosted on IPFS is exactly this: a build folder turned into a UnixFS tree, with one root CID per release. The IPFS Mutable File System (MFS) lets your node recompute those CIDs while you edit files by path.

Common UnixFS Mistakes

  • Comparing CIDs made with different settings. The 12-byte notes.txt is QmT78zSu... as CIDv0 with dag-pb leaves and bafkreif... as CIDv1 with raw leaves. Match CID version, raw leaves and chunker before you call two copies different.
  • Pinning a folder with a direct pin. A direct pin protects only the root block, so the files and chunks under it stay open to garbage collection. Pin folders recursively, the default.
  • Turning on mtime by habit. Including mtime changes the root CID, so identical files with different timestamps stop deduplicating. Leave it off unless you need the timestamps.

How AIOZ Pin Handles It

The takeaway: one root CID names a whole UnixFS tree, and any change inside it produces a new root. AIOZ Pin gives you two ways to pin a whole folder: the Node.js SDK and the pinning CLI. In the quick start, client.pinFolderToIPFS takes the folder path as sourcePath, and the CLI pins a directory when you pass its path to --file.

From the AIOZ Pin quick start, not run here because it needs real keys:

// Not run: from the AIOZ Pin quick start (Node.js SDK)
client.pinFolderToIPFS({ sourcePath: './folder', options }).then((result) => {
  console.log(result);
}).catch((err) => {
  console.log(err);
});

The pin records in the Pinning API include an is_dir flag, so you can tell a folder pin from a file pin when you list your pins. Next step: follow the AIOZ Pin quick start to pin your first folder.

Frequently Asked Questions

What is UnixFS in IPFS? It is the format IPFS uses for files and directories. It adds file, directory and symlink meaning on top of the Merkle DAG, which has none of its own.

What chunk size does IPFS use? Kubo's default chunker is size-262144, which is 256 KiB per chunk. You can change it per add or in the config.

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