If you are a citizen of the EU/EEA and have a European Health Insurance Card (EHIC) certifying you contribute in your home country, you will be covered in the same way as a Swedish citizen.
If you are from outside the EU/EEA you should purchase private travel/health insurance for the duration of your stay in the country as you will have to cover all healthcare costs for treatment and medication. Some countries outside the EU/EEA have reciprocal healthcare agreements with Sweden (for example Australia). To find out whether your country has an agreement with Sweden consult your national health insurance organisation or Swedish consulate.
If you are a permanent Swedish resident, are inscribed at your local tax (Lokala skattemyndigheten) office and have a personnummer (literally person number) you will be covered in the same way as a Swedish citizen. For more information about residency see the Visas & Permits section.
Private health insurance is not particularly common in Sweden, with only around 1 in 10 Swedes covered. This is a reflection of the high level of care available within the universal state healthcare system. Recently though, more and more companies are starting to offer private insurance to their employees. Private hospitals exist but are but are often contracted by the local councils and form part of the national healthcare system.