How do condoms work?

So I'm a virgin and I just don't understand the function of condoms. Can someone please explain?