A virtual machine is when software takes on the role of a machine, including executing intermediate code or running an OS within another. The machine being simulated doesn’t have to exist but may be a concept for the design of the software used.
The same virtual machine implemented of many hardware platforms can improve the portability of software, for example Java which executes intermediate code.
Intermediate code is a mix of both compilation and interpretation into intermediate code and executed by a virtual machine. This means that it can be ran on any machine with a virtual machine available.