Understanding FAT16
Learn the mechanics of the most prolific filesystem family in computer history.
Computer software evolves quickly - there is a constant flux of new ideas coming to life and old ones dying out. But some pieces of software have incredible sticking power, persisting long after the factors that shaped their design are gone. They have adapted a bit over time, but have basically the same bones as they did when they were invented.
Let's take a close look at the inner workings of FAT16, part of a long lineage of filesystems which was invented in the 70s and is still widely used in 2026.
Along the way we'll get our hands dirty and poke at the machinery while it's running, from formatting to defragmentation.
§0 Where did FAT16 sit historically?
The filesystem, in its omnipresence, is mostly invisible. "What the hell is water?", as the fish asks. The short answer is that it's a subtle, understated jewel.
Computer storage hardware has no concept of files or folders - there are only (billions and billions of) bytes. The filesystem is a set of algorithms that track and manage which bytes belong to which files, like a table of contents that maps out which pages belong to which chapters of a book.
A filesystem normally takes over most or all of the disk and gatekeeps all access. In day-to-day use, we are happy to let that happen, because in return we get to have files and folders1 Yay! Files and folders! We love organizing our files hierarchically! without having to worry at all about the Tetris problem of how files should be arranged on disk.
The original version of FAT was created in 1977, and followed by FAT12 in 1980 as part of 86-DOS, which would later be acquired by Microsoft. This was an era where most personal computers didn't have internal storage, and most software ran from floppy disks which had capacities in the hundreds of kilobytes. The filesystem and its own data structures needed to be simple and compact to make the most of that limited space.
For software that booted from a floppy, the tiny, 448-byte bootloader program would need to contain enough logic to navigate the filesystem and load the rest of the program. So it's safe to say that the FAT filesystem was originally designed to be so simple that a 448-byte program can at least read it2 In general, this is not a good heuristic for whether something seems simple to a human layperson..
As hard drives became more common and grew to be tens of megabytes in size, the design of FAT12 hit its limits and so FAT16 was introduced in 1984 as a conceptually similar but extended version. It would later be succeeded by FAT32 in 1996 as hard drives kept getting bigger3 Just keep making the FAT bigger! Another decade can't hurt us!.
By this time, even competing operating systems like Mac OS, Linux, BeOS, Amiga and Acorn had some level of FAT support, making it possible to transfer files back and forth over floppy4 From what I'm told, this was still a risky process, and putting a DOS-formatted floppy into a Mac or vice versa always carried the possibility of losing all your data. Floppies in particular had a deeper level of possible incompatibility: how the binary data itself was encoded into magnetic fluxes. So having a filesystem driver isn't enough - you also need to have a mutually compatible disk controller. This is why tools like Greaseweazle are so useful for archival.. In their dominance, Microsoft never bothered to support the filesystems of their competitors.
With the introduction of Windows XP in 2001, most PCs adopted NTFS, a different Microsoft filesystem with a much more modern and sophisticated design. But FAT32 stuck around in various memory cards, USB sticks, and whatever other drives needed cross-OS write support5 When Apple adopted Intel CPUs, it became possible to dual boot Windows and Mac on the same computer. To make it easier to pass files back and forth between the two OSes, one strategy was to keep the Windows partition formatted as FAT32, or else to carve out a shared FAT32 partition that both OSes would access.. If you were writing digital camera firmware in the early 2000s, FAT32 was the easy, definitely correct choice. Filesystems are high stakes - if there's a bug in your implementation, you corrupt people's data. So if you find yourself implementing one from scratch (and without an AI assistant or even Stack Overflow), you will reach for the simple, high-capacity and ubiquitous option.
Although FAT32 supported large total volume sizes even by the standards of the era, typically up to 2 TB, any individual file couldn't be more than 4 GB, a ceiling that remained unchanged from FAT16. So there is one final successor version, exFAT, released in 2006, which bumps all the limits one last time. Still, FAT32 is both so old and so close to good enough that it probably remains the most ubiquitous.
But let's rewind to that transitional period between floppies and hard drives, and get comfortable with FAT16.
As a historical note, there were several patches and updates to FAT16 over the years. We'll focus on the version known as FAT16B from 1987, which became the standard, along with a few minor additions.
§1 Basic anatomy of FAT16
Before getting into the details, let's look at a high-level overview of how a FAT16 filesystem is organized. When you format a disk and create a FAT16 partition, it carves it up into a few regions that are specialized for different purposes.
The largest is the data area, which lives at the end of the disk and stores all the contents of every file. By itself, it's not very usable since all the files are broken into units called clusters and scattered across the disk, so any file might have its clusters appear out of order and be interleaved with clusters of other files or even fragments of deleted data. The data area largely doesn't label which clusters belong to which file or even where clusters start or end - it's just data soup.
Returning to the start of the disk, the first 512 bytes are dedicated to the boot sector. This records key parameters about the filesystem, mostly sizing-related, like defining how big a cluster is. But most of the boot sector - 448 bytes of it - is reserved for the bootloader - executable code which tries to locate and load the operating system. In the case of DOS and Windows, this means partial logic for reading the filesystem itself6 In practice, some simplifying assumptions are made, such as only reading files in the root directory, and assuming they are contiguous. This is sufficient for a bootloader but allows omission of any logic to do with the FAT itself.. So in a way, the filesystem can ship with its own driver, albeit a very limited one - the raw text in this paragraph alone already blows past 448 bytes. This extreme constraint is a carryover from the floppy disk origins of the filesystem, but is completely unnecessary on a bigger hard drive. In any case, it's how FAT16 works.
After the boot sector comes the File Allocation Table, after which FAT16 is named! It is a scale map of the data area7 The scale varies from 1:256 to 1:16k depending on how the disk is formatted. that lays out the ordering of clusters that make up each file. It also tracks free space. It has a fixed size that is baked in when the disk is formatted, of up to 128 KB. Since it plays such a crucial role, there are usually two copies of the FAT in case one gets corrupted.
The last major region is the root directory. It has filenames, sizes and other metadata on files in the root directory. It has a fixed number of slots, so there's a strict limit to how many files can exist in the root directory. Note that this only applies to the root directory though - subdirectories work differently! Special treatment for the root directory is a carryover from FAT12, which originally did not have subdirectories at all. On FAT16, the limit is almost always set to 512 slots, resulting in 16 KB on disk dedicated to this metadata.
§2 Formatting a disk ✓
Formatting the disk effectively wipes it and initializes the boot sector, FAT and root directory the way that FAT16 expects. During a quick format, the data area isn't touched, to save time and wear and tear on the disk8 There could be some leftover deleted data there, but according to the filesystem it's empty 👌.
Most filesystem parameters are baked into the boot sector at formatting time and don't change afterwards. A lot of them are size-related, like the number of bytes per sector or the number of sectors per cluster.
A cluster is FAT16's smallest unit of data. The number of sectors per cluster is a tradeoff - a smaller number means more granular bookkeeping - more to keep track of when reading and writing - and a larger number means more wasted space, since even an empty file will take up at least one cluster.
Each cluster is numbered in the FAT, which uses 16-bit entries in FAT16. This means that FAT16 can't manage more than 65,536 clusters9 In practice, the cap is slightly less than 65,536 due to some values being reserved., and together with 512 bytes per sector and sectors per cluster, which caps out at 6410 Confusingly, this field is 1 byte, which could hypothetically go up to 255, but (1) the spec insists that the value be a power of 2, which brings it down to 128, and (2) DOS-era implementations would multiply in bytes per sector to calculate bytes per cluster - at 128, this hits 65,536 bytes and would overflow the 16-bit CPU registers of the day, so down we go to 64., the largest FAT16 partition that can exist is 2 GB.
Below is an interactive disk formatting demo. As you vary disk and cluster size, you can see how the contents of the boot sector change accordingly. Each field is visualized in a human-friendly way but the underlying bytes are rendered in hexadecimal. You can click any field to see more details.
For the rest of this page, we will be using a disk with some non-traditional choices of parameters - this is less rigidly realistic, but it will make it easier to explore the disk and filesystem without getting bogged down.
Here are the most significant liberties I'm taking:
- 1 FAT instead of 2, so that there is less bookkeeping when writing files.
- 16 root directory slots instead of 512, to fit the root directory in one sector.
- 1 sector per cluster, so sectors = clusters.
- 16 clusters total11 Most FAT driver implementations would automatically treat such a small disk as FAT12. But FAT12 uses 1.5-byte entries for the FAT, which are hard to visualize nicely, so we will pretend we're working with FAT16. - this is a tiny 9.5 KB disk, and the whole thing can be visualized on one screen.
- I'm not going to talk about the partition table, as if the entire disk was just the FAT16 partition12 Floppy disks and other removable media like CDs generally work like this, having a single filesystem with no wrapper..
With that, let's try reading some files!
§3 The root directory ✓
To read a file, we need to know which clusters it occupies as well as its size, since most files will not be an exact multiple of the cluster size.
Directory listings are the fundamental entry point - they contain file names, sizes and the number of the first cluster in the file. For files which fit in a single cluster, that's the complete set of information needed. For bigger files, the FAT must be consulted.
But let's start with something simple. Below is an interactive display of the root directory of a disk. It highlights the key pieces of information but you can expand each row to show all fields and their underlying representation in individual bytes. Take a look at the directory listing for ALICE.TXT and then try reading its contents from the data area - it's below the cluster size of 512 bytes so there's no need to consult the FAT.
You can explore the root directory and data area freely, but here are some points of interest to verify for yourself:
- File names are a maximum of 8 characters, with an extension of up to 3 - the so-called 8.3 filename. There is no such thing as a .HTML file, because it caps out at .HTM.
- Shorter filenames are padded with spaces up to 8 characters, and the dot is never stored at all.
- Also, the names are all kept in uppercase even though the binary encoding has enough room for lowercase. DOS handles and stores all filenames in uppercase so that filenames are effectively case-insensitive.
- File size is stored in a 32-bit field, so individual files can't be bigger than 4 GB. Luckily FAT16 partitions themselves can't be bigger than 2 GB as we saw, so this limit doesn't matter.
- All the timestamp fields - created/read/modified - have different time resolutions! Created/read were added in Windows 95, which squeezed them into the available space.
- When reading the cluster, there's some extra data that comes at the end from a previously overwritten file - knowing the file size, you can ignore everything that comes after, but it's still there.
§4 Following a chain ✓
Reading larger files requires looking at the FAT, since directory listings only identify the first cluster belonging to the file. The FAT maps out each sequence of clusters belonging to the same file, regardless of how scattered and out-of-order they might be on disk.
Each cluster in the data area gets a 2-byte entry in the FAT, plus 2 reserved entries at the start. Each entry either contains a special marker for free space (i.e. an unused cluster), the index of the next cluster in the chain, or else a special end-of-chain marker13 Yes, this is just a linked list..
Try it out in the next interactive exercise, by reading the entirety of DIRENT.INC - fittingly, it's the MS-DOS 4.0 source's own description of a directory entry. Start by checking its entry in the root directory, then move to the FAT and figure out the sequence of clusters to read from the data area.
This system is very basic but flexible. Flipping back and forth between the FAT and the data area is annoying, but for small numbers of clusters you can just memorize the sequences (so can the computer!) and it's fairly efficient.
Things to notice:
- This wouldn't feel very efficient if the disks and files were very large. When things are many thousands of clusters, there's a lot more bookkeeping to be done.
- With the FAT being so compact14 The toy disk in these interactive portions, having only 16 clusters, has an unrealistically small FAT, but even on a 2 GB disk it would be on the scale of 128 KB - a minuscule fraction of the total size!, it's easy to cache large parts of it, or even the whole thing in memory, and there's no need to keep jumping back and forth between the FAT and the data area when reading files.
§5 Deleting a file ✓
To delete a file, you need to free up its entries in the FAT, and remove the directory listing so that nothing points to it. Nothing needs to happen in the data area itself - as long as the space is marked as free, it will eventually be overwritten by other files. But immediately after deletion, the contents of the file are still floating around on disk.
Actually, even the directory listing remains mostly intact - in FAT16, the convention is to substitute 0xE5 as the first byte of the filename to mark it as deleted15 0xE5 can be used in valid filenames - it means σ (lower-case sigma) in MS-DOS's CP437 character encoding, as well as coming up frequently in Japanese kanji in Shift JIS encoding. In this case, the filesystem driver stores 0x05 in its place on disk and swaps it back when reading the name., after which the computer starts hiding that file from the user, but not to touch anything else.
Why leave the directory listing intact? When the filesystem driver sees a truly empty directory entry - all zeroes - it assumes that all the remaining entries are also empty, and stops reading early. This is handy in the root directory, which could have hundreds of empty entries, and this saves some time. If you delete a file in the middle though, it needs to mark it as deleted, but not as the final entry, so it uses that 0xE5 marker instead to signify that there may be additional file entries afterward.
As a happy side effect, if you delete a file accidentally, you may be able to recover it easily, especially if it fits in one cluster.
Try it out for yourself below by deleting ALICE.TXT.
Since this is a multi-step operation, it's interesting to consider what would happen in the case of a power outage.
If you free up the clusters in the FAT first and then lose power, then you have a directory entry that doesn't point to anything. However, if you delete the directory entry and lose power before you can update the FAT, then the result is "lost clusters" that eat up free space but can't be used by any file, at least until CHKDSK.EXE is run to scan and repair the filesystem.
§6 Writing a file
Writing a file is much like deleting a file in reverse, with the additional step that the data actually needs to get written to the data area. This usually happens before the FAT is updated so that even during a crash, the FAT doesn't end up pointing at corrupted or stale data.
Before writing the data though, the FAT is consulted to find free space to use. Depending on how big the file is, more free clusters need to be found. Microsoft's FAT16 driver will just take the first free clusters it finds after whatever cluster was last allocated. This can lead to fragmentation if there are little free pockets of space that are too small to contain the new file.
Fragmentation is not ideal since it means the drive physically needs to jump to different locations to perform a read or write of that file. Each seek takes tens to hundreds of milliseconds, which may sound quick but is actually a big bottleneck on disk I/O speeds16 The infamous Latency Numbers Everyone Should Know table illustrates it well. A disk seek is on a glacial timescale compared to most other things a computer does..
Unfortunately, normal use of the filesystem - creating files, deleting them, editing them to be slightly larger and smaller - generates tons of these little pockets of free space scattered across the disk. Combined with FAT16's simplistic algorithm for allocating space, it's an extremely fragmentation-prone filesystem and the performance suffers because of it.
§7 Defragmentation
Since fragmentation is such a problem on FAT-based filesystems, MS-DOS and Windows included a defragmentation utility that users could run as needed to optimize their disks. Actually, it was originally a third-party paid utility - Norton Speed Disk17 Paying $150 in 1987 dollars to Mr. Norton himself for the ability to optimize some floppies is both incredibly quaint and incredibly hardcore. - that was so badly needed that Microsoft licensed a version of it for distribution with every copy of MS-DOS 6.0 and later.
Defragmentation rearranges the clusters on disk so that each file's clusters are packed together in order instead of being mixed up with clusters from other files. If you were trying to repack a suitcase, you might take everything out and start over. Unfortunately, when repacking a disk, there is no comparable move of "take everything out" - everything has to be rearranged in place. If the disk is nearly full, it takes a lot more moves to complete the process.
Similar to writing or deleting files, there is a careful order of operations so that corruption is minimized in the case of a crash or power outage. Defragmentation touches every file on disk, so it's critically important for it to be safe and reliable.
As filesystems modernized, fragmentation suddenly ceased to be such a scourge on performance. And with solid state storage, additional seeks from fragmented files are not a bottleneck in the same way. Windows still does it, but it's a quiet background thing now. If you grew up diligently running DEFRAG.EXE overnight every weekend, it almost feels melancholic!
So, as a final toast to the defrag utility18 and a final test of your esteemed abilities, I have prepared a tiny game where you can defragment a disk by hand. The goal is just to reach a fully defragmented state, but you can challenge yourself to do it in as few moves or as little time as possible.
How to play
During play, you switch back and forth between two modes - a directory listing mode where you see the first cluster for each distinct file, and a FAT mode where you see all the clusters for a given file. Try to memorize what you see to avoid wasting time.
You can rearrange clusters by selecting them in FAT mode and then clicking on a free cluster to move them. It's not allowed to swap two clusters that are both occupied - that's unsafe during a crash!
Try it out in easy mode first and move on to hard mode if you get the idea. Enjoy!
§8 Parting thoughts
This article could keep going. How do long filenames work? How are subdirectories represented? What architectural choices were kept vs. revised for each FAT iteration? What were the technical challenges during the transition to NTFS? Reality has a surprising amount of detail, but even in the ephemeral world of software, so do filesystems that have stuck around for decades.
I hope this satisfies some curiosity in you19 if it hasn't thoroughly destroyed your capacity for wonder and inspires a bit of appreciation for the mundane.