In computer science, a sparse file is a type of computer file that attempts to use file system space more efficiently when the file itself is mostly empty. This is achieved by writing brief information (metadata) representing the empty blocks to disk instead of the actual "empty" space which makes up the block, using less disk space. The full block size is written to disk as the actual size only when the block contains "real" (non-empty) data.
When reading sparse files, the file system transparently converts metadata representing empty blocks into "real" blocks filled with zero bytes at runtime. The application is unaware of this conversion.
Most modern file systems support sparse files, including most Unix variants and NTFS. Apple's HFS+ does not provide for sparse files, but in OS X, the virtual file system layer supports storing them in any supported file system, including HFS+. Apple File System (APFS), announced in June 2016 at WWDC, also supports them. Sparse files are commonly used for disk images, database snapshots, log files and in scientific applications.
The advantage of sparse files is that storage is only allocated when actually needed: disk space is saved, and large files can be created even if there is insufficient free space on the file system. This also reduces the time of the first write as the system doesn't have to allocate blocks for the "skipped" space. If the initial allocation requires writing all zeros to the space, it also keeps the system from having to write over the "skipped" space twice.
For example, a virtual machine image with max size of 100GB that has 2GB of files actually written would require full 100GB when backed by pre-allocated storage, yet only 2GB on a sparse file. If the file system supports hole punching and the guest operating system issues TRIM commands, deleting files on the guest will accordingly reduce space needed.