Allocated versus Actual Disk Space

Allocated versus Actual Disk Space

What's the difference between file size and allocated space?

For Your Interest Disk Space Management
23.03.2022

When you are scanning your hard disk with TreeSize, you might have come across the two different values TreeSize reports for file size: size and allocated space.

Both values can be viewed with the properties dialog in Windows itself:

Those two sizes often are not equal. But what exactly is the difference between those two values?

 

Allocation of hard disk blocks to files

Especially if you want to save disk space, it is useful to understand the difference between size and occupied space. For this purpose, we would first like to explain how a hard disk works under the Windows file system "NTFS".

Hard disks are divided into blocks - under NTFS these are 4 096 bytes (4KB) in size. A block is always assigned to exactly one file, whereby the last block is often not completely filled.

For example, if a text file has a size of 4100 bytes, it occupies 2 blocks, i.e. 8,192 bytes or 8KB. The remaining space in the last block (4,092 bytes) cannot be used by another file and is therefore lost. This also means that the occupied space must always be a multiple of the block size of the file system.

 

File compression makes the difference

So how can the occupied space still be reduced without damaging the file? A simple and quick way is to use NTFS compression: A file is stored in compressed form.

When the file is read and saved in the corresponding application, decompression is then performed automatically and transparently by the file system driver. Transparent means here that the application itself does not have to know anything about it - the file does not have to be unpacked first, as is the case with ZIPs. Other factors such as performance are only minimally affected by this.

After enabling file compression, we now have a more noticeable difference:

Our storage managers TreeSize and SpaceObServer can even apply NTFS compression to multiple files at once or entire directory branches. This is a quick and easy way to gain disk space.

 

Used space on a hard disk

If you sum up the used space of all files, as TreeSize does, you will notice that this sum is smaller than the used space Windows reports for the hard disk. Why is this sum smaller and what is occupying the remaining space?

To understand this, we need to look again at how the file system works. The file system itself requires additional space for administrative information. This includes above all for the list of contained files together with their metadata. This is called Master File Table (MFT) in the Windows file system.

Typically, one block is occupied here for each file. The MFT is automatically enlarged if necessary, but never reduced in size. The space for this management information cannot be easily freed - not even by deleting the files, so it is not included in the occupied space calculated by our products.

 

Resident files without own block

Now, one could conclude: If a file is only a few bytes in size, does it therefore always occupy at least one block? That would be quite a waste of space. But this is not true, because the developers of the NTFS file system have come up with something exciting.

The content of very small files with a limit of about 900 bytes is simply stored in the MFT entry belonging to the file, in the so-called descriptor. This means that such very small files, called resident files, do not occupy their own space on the hard disk. This can also be seen in the Windows Properties dialog:

Is this fair calculation?

The question may be asked, if Windows and TreeSize calculate fair and right here?

For TreeSize, we have answered the question like this: We show how much space you can reclaim on your hard disk if you delete the file. In the described case, this is 0 bytes.

 

In a nutshell: The difference between file size and used space

So let's summarize our findings again. You have to distinguish between the file size and the space actually taken up by the file on the hard disk.

However, since the Windows file system assigns a block to exactly one file at a time, the amount of space used may sometimes be minimally larger than the file size. The used space can be reduced by NTFS compression without affecting the file size.

Very small files are not allocated their own block as resident files - instead, their file contents are stored in the MFT. Thus, these do not occupy any disk space at all.

 

 

Want to always stay up to date?

Do you like what you've just read, have new ideas or feedback? Visit our contact form and let us know your thoughts!

Blog author Joey

Joey

File & Disk Space Management, Banking Software