Explainer: The arithmetic of snapshot size

Snapshots, the storage space they occupy, and backup sizes aren’t easy to understand. This article tries to explain why what appears to be simple arithmetic rapidly becomes more complicated in reality, and how free space can come and go seemingly by magic.

Snapshots consist of a copy of the file system metadata, all the information required to be able to roll back to the state of that APFS volume at the time the snapshot was made. To make that work, though, they also need to retain the data of files which are subsequently changed or deleted. It’s that retained data which gives the snapshot its effective size, not the file system metadata which are small by comparison.

For the purpose of this demonstration, I’ll consider a really simply situation: a disk with just two folders, one containing some Important Documents that you can see directly, the other a hidden system folder with a single large database file that’s normally invisible to the user. At the start, when we make the first snapshot, each contains just 10 GB, giving a total space used of 20 GB, with no snapshots at all. When that storage is backed up for the first time, Time Machine requires a full 20 GB for that backup.

snapshotsSize1

When the first snapshot is made, its size is only that of the file system metadata, but shortly after that, File 1 is deleted and File 2 created. At that moment, the snapshot size increases to 10 GB to retain all the data from the deleted File 1.

snapshotsSize2

When Snapshot 2 is made, 1 GB of the hidden system data has changed, increasing the size of Snapshot 1 to 11 GB. A Time Machine backup therefore has to copy File 2 at 10 GB, and the 1 GB of changed data in File X, for a total backup size of 11 GB.

snapshotsSize3

The only change when Snapshot 3 is made is further change in 2 GB of the hidden system data, so Snapshot 2 becomes 2 GB in size, the same size as the backup made at that point.

snapshotsSize4

For the fourth and final snapshot, File 2 is deleted, so its data has to be retained by Snapshot 3, and a further 2 GB in system data change again, making Snapshot 3 a total of 12 GB in size, although at the time the size of Snapshot 4 remains that of the file system metadata alone. Total backup size is also 12 GB, consisting of File 3 and the changed data in File X.

At the end of this, with that fourth snapshot, sizes in addition to the file system metadata are now:

  • Snapshot 1 – 11 GB
  • Snapshot 2 – 2 GB
  • Snapshot 3 – 12 GB
  • Snapshot 4 – 0 GB

and a total of 45 GB in backups to APFS storage. It’s perhaps worth noting that backing up to HFS+ instead would have required a total of 70 GB, as the whole of File X would have had to be copied in each backup.

At the time that Snapshot 4 is made, space taken on disk by the files is still only 20 GB, but a total of 25 GB is retained by its snapshots.

snapshotsSize5

The effect of deleting intermediate snapshots can be complicated. If Snapshots 2 and 3 are deleted, or had never been made, then the total space required by Snapshot 1 would be only 12 GB, 10 GB retained for the data of File 1, and 2 GB for the changed data in File X. Thus the increase in free space achieved by deleting snapshots currently taking a total of 14 GB would only be 13 GB.

In this simple workthrough, I have considered changes in just two files. To see how complex this becomes in real life, multiply that by the tens of thousands of files that change between snapshots and their matching backups. Estimating the size of snapshots and the amount of free space that would be returned if they were to be deleted is inevitably complex, and simple arithmetic may not apply.

What of the effect on disk free space? Measurements that include snapshots and their retained data would change thus, for storage with a total size of 100 GB:

  • at the time of Snapshot 1 – 80 GB
  • at the time of Snapshot 2 – 69 GB
  • at the time of Snapshot 3 – 67 GB
  • at the time of Snapshot 4 – 55 GB

but at any moment, only 20 GB is actually used to store active files, of which you can only see 10 GB. Delete all the snapshots and 25 GB will return apparently from nowhere.

Snapshots are a great boon, but their unintended effects can appear shocking.