HIV is transmitted when people exchange blood, semen, or vaginal discharge.
People usually get HIV from having unprotected sex with someone who has it.
However, people can actually get HIV from protected sex too. Condoms offer good STD protection, but they do fail sometimes.
Nurses and other people who are around blood a lot are at a higher risk of getting HIV from contaminated blood. Usually our skin would protect us from things like HIV, but if we have a cut, then the infected blood can get into our body.
People who share needles (usually illegal drug users) may also get HIV due to swapping blood from the needle.
There was a time, before we knew much about HIV and how to test for it, that people could get it from blood transfusions at the hospital, often after injury or surgery. Now that we know more about HIV, we can test blood for HIV before giving the blood to anyone.
For more information, you can look here:
http://www.niaid.nih.gov/factsheets/hivinf
.htm