Inside a virtual reality headset, 2 slightly different 2D images are presented to the wearer, one for each eye. Your brain then combines these images to create the perception of 3D space. It's the same principle behind how normal eyesight works – you're just "seeing" spaceships and fantasy realms instead of the real world.
But that's not all a VR headset does. Not only do you need to see a 3D digital world, but you also need to be able to manipulate it. To achieve this, gyroscopic sensors, accelerometers and magnetometers track and relay your head's movement and orientation back to the device powering the experience (be it a PC, console or phone). To increase the accuracy of positional data, cameras pointed at the wearer track LEDs on the headset and the controllers in your hands. The goal of all this is a 1:1 re-creation of your movements inside the virtual world.