How Servers Recognize Devices Sharing Same IP Address

ipmac addressosirouter

You have a router and many devices can connect to it to access the internet. From what I've read, the router assigns private interal ip addresses to the devices that are connect so it knows how to direct the traffic. The router however, is assigned one ip address by the ISP. What the world sees from any request coming from that router, whether from a desktop or a tablet, is that one ip address of the router. So how can a server tell how many users on the other end of that ip address? I know devices have their unique mac addresses, but I read that that information isn't sent to servers.

A more concrete scenario would be for video hosting websites like youtube. How would it know how many users are using the same ip? (for view counts) Also, in places where you expect many users using the same "wifi" such as Starbucks, Burger King, or some university, how are devices connected differentiated on the web?

Best Answer

You should search for the OSI model:

enter image description here

A full explanation of the OSI model is too broad to give here, but applications like browsers and web servers use the transport layer to communicate with each other, not the network layer where IP addresses are.

What you are missing is that HTTP uses TCP as the transport protocol. By default HTTP servers listen on TCP port 80. A host using a browser will use a random, ephemeral, TCP port as its source port. NAT will do something similar for each host for which it translates the IP address, and it keeps track of which port is assigned to which host in a traffic flow. It ends up being a combination of layer-3 address (e.g. IP address), transport protocol (e.g. TCP), and layer-4 address (e.g. TCP port) for what gets used as a unique identifier.