They are used for taking away a person's freedom, as a punishment for breaking laws. They also keep dangerous people away from the public.
In the UK prisons try to help prisoners get some skills that make it easier for them to fit back into society as law abiding citizens. That means people in prison can get education and training, it might include doing exams and having a job while they serve their sentence.
Until about 200 years ago the main forms of punishment for crimes in England and Wales were execution or being sent to Australia.