HIV gets passed from person to person in blood, semen, pre-seminal fluid (pre-cum), fluids from the vagina and rectum, and breast milk. So you're at risk when body fluids from someone who's infected could get into and mix with yours.
Some things you do now can raise your chances of getting HIV, but you can't change things you were born with or happened in the past.
One of the most common ways you can get HIV is by having vaginal or anal sex with someone who has HIV. You could pass HIV during oral sex, too, but that's less common. It's also risky when you don't know whether or not your partner is HIV-positive, because they could be. The more sexual partners you have, the more your odds of catching HIV go up.
Using condoms, barriers, and dental dams will help a lot to keep you safe, but they're not perfect.
Your choice of partner also matters. Having sex with someone who has a higher chance of getting (and therefore having) HIV -- a sex worker or an IV drug user, for example -- raises your chances as well.
The other big risk is reusing needles, syringes, or other equipment an HIV-positive person used to inject drugs, whether they were prescribed by a doctor or illegal. You shouldn't even reuse your own.
You could also get HIV from a needle used for piercing or tattooing if it wasn't sterilized after piercing or tattooing someone with HIV.
An accidental stick from a contaminated needle or medical device could cause HIV, but that's very rare.
Alcohol and Recreational Drugs
Because these can weaken your judgment, you may be more likely to do other risky things, such as having unprotected sex.
A Sexually Transmitted Disease
An STD such as herpes, chlamydia, syphilis, or gonorrhea may cause changes in the tissue of the vagina or penis that make it easier for HIV to pass to you while you're having sex.
From Mother to Child
Mothers infected with HIV can give their baby the virus before or during birth, or by breastfeeding. This is one reason why pregnant women should get tested for HIV.
It's possible if you had a blood transfusion or were given blood products before 1985. Since then, all blood in the United States and Western Europe gets tested for HIV.
Some people have fewer copies of a gene that helps to fight HIV. We might someday have a test that can tell you if you're more likely to get HIV and develop AIDS, but there isn't one yet.