minimum space is required on disk to restore a backup in SQl Server? Suppose I am going to restore a backup (2 GB) in my sql server, I have sufficient space (20 GB) in my disk, but is there any algorithm that SQL server follows to calculate the minimum disk space required or just randomly checks the disk space and the backup to do a successful restore.

As I want to know the internal working of SQL Server.

Thanks in Advance.
The backup file maintains metadata about the database and files that SQL Server uses during the restore process. Part of that metadata is a listing of data and log files that are in the database, and their respective sizes (as well as other information).

If you run RESTORE FILELISTONLY you can see the minimum size required for each data and log file in the database that will be restored. When SQL Server performs a normal restore it first checks these values and validates that the disk where each file is to be restore has sufficient space. If not, SQL Server throws an error indicating how much space is required and how much is available on the disk.