The purpose of a space suit is to keep astronauts alive in outer space, as the extreme temperatures and lack of an atmosphere mean instant death for a human. Astronauts also wear suits inside the spacecraft sometimes in case cabin pressure drops suddenly, and they wear them when they are performing work on the exterior of the space ship.
Astronauts have worn space suits in a variety of contexts, such as walks on the lunar surface, work at the International Space Station, making repairs to such items as the Hubble telescope and returning to the Earth. Soviet astronaut Yuri Gagarin was the first human to wear a space suit in outer space, as he donned the Soviet SK-1 suit for his voyage.
The most modern space suits still feature the pressure garment inside but also contain a set of environmental machinery that keep the astronaut comfortable and make bending the limbs as easy as possible. The pressure suit tends to stiffen in the presence of a vacuum, and modern suits are designed to counteract that. The suits also contain an entire oxygen supply and environmental control mechanism so that the astronaut has wholly independent movement when he is outside the spacecraft.