When a file is deleted, it's only marked as deleted - and the corresponding areas on the disk are marked as free. At that moment, it's usually possible to restore the file.
However, if you (or another tool, or the operating system) saves another file on the disk, it may re-use this "free" area and overwrite the content for real. At that moment, it's not possible to restore the file anymore.