It's typically done with a telephoto lens above 50mm - one which can zoom in or out without losing focus - on a dollied camera, using the zoom to keep the focal point or character the same size while the dolly’s forward or backward motion flattens or stretches the field of view. This gives the appearance of the foreground or background of the image being stretched out or squashed in. This technique can be used to convey a shocking realisation or threat, or to imply a sudden narrative change, as the character's surroundings alter and they are left centred in this changed world.
For the viewer, the visual distortion creates the same sense of defamiliarization as the on-screen character is experiencing. It is a visceral and unsettling effect. It draws the viewers eye to the main character’s features so that we share their feeling of unreality. The relationship between the character and their world has been changed in our perception.
The depth of field shrinks dramatically, closing in character(s) and audience alike, creating a claustrophobic feeling of being restricted and unable to escape. The two methods are to zoom out with the camera while dollying in or zoom in while dollying out.
You’ve probably seen this in Jaws (1975), in which cinematographer Bill Butler used the shot to great effect in the scene showing the second attack by the shark.
As the water boils red, Chief Martin Brody (Roy Scheider) realises that the shark has struck again.
Created by cinematographer Irmin Roberts for the 1958 film 'Vertig'o, the effect was used to accentuate Scottie Ferguson’s (James Stewart) disorientation and fear when confronted with heights. For this reason, it’s also called the ‘Hitchcock shot’ or ‘Vertigo shot.’ The technique Roberts used was the opposite of the one in Jaws: to zoom in with the lens while dollying out, creating a stark feeling of isolation and powerlessness.
An original poster for Hitchcock's 'Vertigo'
Toying with the depth of field like this, while perhaps overdone in the eyes of some critics, can nonetheless can be an arresting and economical way to make an emotional or psychological point immediately and completely effectively.