Here's how public key cryptography works. I send you a box with an open padlock in it, and only I have a key to that padlock. You put your message in the box and lock it and send it to me, and only I can open it.
The padlock is the public key, which is a kind of filter that an algorithm uses to uniquely scramble a message such that it can only be unscrambled using the private key. So when you connect to a website using the https protocol, your browser receives the public key and scrambles everything it sends back to that address, including things like your credit card number.