Condoms and lube are the most effective way to protect yourself from HIV and most other STIs, like syphilis and gonorrhoea. Usually made of a thin latex, condoms provide a physical barrier that viruses and bacteria can't pass through.
When used consistently and correctly, condoms are extremely reliable. Make sure you use lots of lube for anal sex – it’s absolutely essential for having a good time!