In an OS, virtual memory is used to allow programs to access more memory than is physically available. When a program needs to access data that is not currently in RAM, the OS temporarily transfers some data from RAM to a hard disk, freeing up space in RAM. This is known as paging or swapping. When the program needs the data again, the OS retrieves it from the hard disk and puts it back into RAM.