Virtual memory allows a program to use more memory than the physical RAM installed on a computer. It works by storing portions of programs and data that are not actively being used on the hard disk, freeing up RAM for active portions. This gives the illusion to the user and programs that they have access to more memory than is physically present. Virtual memory provides advantages like allowing more programs to run at once and not requiring additional RAM purchases, but can reduce performance due to the need to access the hard disk.