An emulator is hardware or software which simulates something else. For instance, a Gameboy emulator would be something which emulates a Gameboy. A computer emulator can execute programs written for the emulated computer - from the software's perspective, an adequately implemented emulator is indistinguishable from the actual computer. The original Compaq personal computer was an IBM PC emulator - it appeared as a genuine IBM PC to all software running on it and any expansion cards plugged into it. Likewise, AMD CPUs emulate the Intel iAPX CPUs. Although software may be able to query some hardware and determine if it is the original or an emulator, distinguishing between the two is otherwise impossible in an accurate emulation.
In the 1970s and 1980s, the term "emulator" was almost exclusively used to refer to hardware and the term "simulator" was used to refer to software. A simulator was typically used for the benefit of a person rather than other hardware or software. As a consequence, simulations tended to be less accurate than emulations at some level. In modern usage, the terms are largely interchangeable. However, they still can carry the original connotations. For instance, one would not refer to a weather simulation as an emulation.
A related term is "virtual machine", which indicates the emulation of one machine on another machine. This can be done in hardware, such as the virtual 8086 mode of modern Intel iAPX processors. It can also be done via software emulators. Originally, the term was used to refer to a conceptual machine that might not even have ever had an implementation in hardware or software. Donald Knuth's MIX computer was an example of this, although someone eventually wrote a software emulator for it.
Hardware emulators are used to develop and test software for CPUs which are under development. As mentioned above, they are also developed by companies wishing to compete with the original hardware design yet maintain compatibility. Software emulators are used to run software written for one computer on another computer. A major use of software emulators is to run software from obsolete systems, or to test possible future CPU designs. Note that hardware emulation runs much faster than software emulation, but is more expensive. Software emulation runs slower than hardware in most cases. Even a well-designed software emulator requires about ten instructions on the host CPU (the computer running the software emulator) for every one instruction on the emulated CPU. However, a software emulator on modern hardware can often run software within the emulator at the same speed of, or faster than, the older hardware that is being emulated. When software timing loops exist in the code running on the emulated CPU, the emulator may need to purposely slow execution speed to provide an accurate emulation.