There are actually a lot of little things it's doing, but the main space recovery is that Access still has all those records you deleted, all those tables you've created and deleted, all the forms, etc. The compact and repair goes through and says, "This is marked for deleting" and actually deletes it. If you've ever had a table open while a query deleted that table, you will go back to that table and see all the entry marked as #Deleted#. It is those that get actually cleaned up. Another piece that Compact & Repair does is reset your autonumber if it's a sequential autonumber.
As an example, think of when you delete a file out of Windows Explorer. If you don't hold shift down, the file goes to the trashcan. Then you empty the trashcan to actually remove the file. (That's not exactly what happens with emptying the trashcan -- the reality is that the file gets marked by NTFS as deleted and therefore the disk space occupied by that program can be overwritten. However, whatever you deleted is still there until it's overwritten. That's a whole other technical piece.)