If two PCs share a public IP, then there is a router between them and the Internet, and that router implements Network Address Translation (NAT).
Within the local network, controlled by the router, the two PCs have different IPs (like 192.168.0.something). The NAT translator in the router sends the messages from each LAN IP address with a different port so that when the data comes back it can figure our which LAN IP to sent the packets to.
There are many more details of NAT, and it’s a rather complex topic, and this is only the ELI5 simplification of the facts.
Latest Answers