How can a file's size on disk be 0 bytes when there's data in it?

106

23

I have a file in Windows 10 with 362 bytes of data, but the "size on disk" is just 0 bytes. It's a simple "Hello world" program written in assembly, and saved in Notepad++.

How is it possible that the size on disk is zero when the size of the file is 362 bytes?

I have an SSD, not a normal hard disk.

Screenshot of the Properties dialog:

Screenshot of the Properties dialog

Coder88

Posted 2016-01-24T23:00:08.673

Reputation: 921

4Short answer: If no additional space on disk is needed to store its contents. – David Schwartz – 2016-01-25T01:52:43.200

11@Thomas Not a duplicate. The name sounds similar, but that question is asking why Windows declares a zero-byte file to be zero-size despite requiring registration somewhere. This question asks why the size on disk can be zero even if there is data in the file. – Ben N – 2016-01-25T16:41:13.010

3

Related: How can an large file have a zero “Size on disk” value?

– BlueRaja - Danny Pflughoeft – 2016-01-26T00:36:45.200

@BenN Is flagging it inappropriate because you are right it is certainly not a duplicate. – William – 2016-01-29T06:44:30.967

Hi Coder88, I believe the person who flagged your post as a duplicate was mistaken - the other question was asking something different; you really did ask a good question. If you meant to indicate that your question is solved, you can click the check mark next to an answer here. – Ben N – 2016-01-29T19:31:32.490

Answers

156

This happens if the file is so small that its contents and the filesystem bookkeeping fit in 1KB. To save disk space, NTFS keeps small files "resident", storing their contents right in the file record, so no cluster has to be allocated for it. Therefore, the size on disk is zero because there's nothing beyond the file record. Once the file gets sufficiently large, NTFS makes it "nonresident", allocates one or more clusters for it (creating a nonzero "size on disk"), and creates a "mapping pair" in the file record in the place of the data to point to the cluster.

SSD hard drives or Windows 10 don't affect this; it's simply an NTFS feature. Further reading: The Four Stages of NTFS File Growth.

Note that the "size on disk" metric isn't exactly right. For instance, it never includes the constant 1KB that the NTFS file record takes up. The metric was introduced in Windows 95, which didn't use NTFS and therefore couldn't have accounted for this phenomenon; it just showed the file size rounded up to the next multiple of the cluster size. That estimation algorithm was carried through to Windows 7, even though many Windows versions between them used NTFS and resident storage. It was finally updated in Windows 8 to count files with only resident data as zero-size on disk. Further reading: Just What Is 'Size on Disk'?

Ben N

Posted 2016-01-24T23:00:08.673

Reputation: 32 973

1

For a moment I thought we were looking at the effects of Data Deduplication (http://blog.fosketts.net/2012/01/03/microsoft-adds-data-deduplication-ntfs-windows-8/) but I believe that feature works at a level transparent to something like the "size on disk" metric.

– misha256 – 2016-01-24T23:24:34.463

8But wait... I am unable to replicate the OPs behavior on my NTFS volume (Windows 7). Regardless of how I create tiny files (some just one-byte long), they each occupy 4KB "disk space" according to the File Properties dialog. Hmm... – misha256 – 2016-01-24T23:29:33.117

@misha256 There's no standard for how to report the size on disk of a file. You won't always be able to make sense of it. – David Schwartz – 2016-01-25T00:01:18.413

8

@misha256 Huh, I can reproduce it with a file under ~700 bytes on Windows 8.1. My guess is that the algorithm became smarter somewhere between Windows 7 and 8.1, since originally, it didn't know about any fancy NTFS stuff (source). Note that once a file goes over into the second stage, it never shrinks back down.

– Ben N – 2016-01-25T00:33:11.460

1Isn't that still a misrepresentation of storage use? Shouldn't the "size on disk" in the file property dialog also count the size of the NTFS file record entry for every file? – Philipp – 2016-01-25T10:15:35.947

6@Philipp I guess one could argue either way. Traditionally, the "file on disk" was "the size of allocated clusters" (so, for instance, you could see the effects of choosing too large a cluster size). It has never, to my knowledge, included the "catalogue" space needed by the file system (e.g. the size of the "directory entry" or "the length of the chain of FAT entries"). – TripeHound – 2016-01-25T12:25:54.650

3@Philipp: Anyway, including the bookkeeping in the file-size gets hairy fast: How would you describe a 1-cluster file with 3 names? – Deduplicator – 2016-01-25T13:29:18.443

1I can reproduce it with files around 500-600 bytes on Windows 10, there seems to be no fixed size limit. – Vlastimil Ovčáčík – 2016-01-25T14:17:35.690

@VlastimilOvčáčík: Well...presumably 1k or a bit under? :-) – T.J. Crowder – 2016-01-26T08:07:07.957

1@VlastimilOvčáčík Right, it depends on how big the other bookkeeping is. (Bookkeeping here can include the security descriptor and ADS notes.) If the data size plus the size of the other business is less than 1KB, no new cluster gets allocated; if the data would make the record too large, a cluster is allocated. – Ben N – 2016-01-26T19:14:43.690