Sobes.tech
Junior — Middle

How does a browser determine the port number for a connection?

sobes.tech AI

Answer from AI

The browser determines the port number for outgoing connections as follows:

  • If the URL contains an explicit port number (e.g., http://example.com:8080), the browser uses it.
  • If no port is specified, the browser uses the default port for the protocol (e.g., 80 for HTTP, 443 for HTTPS).
  • For outgoing TCP connections, the operating system allocates a temporary (ephemeral) port on the client side, which is used for communication.

Thus, the browser uses either the explicitly specified port or the default protocol port, and the OS automatically allocates a free port for the local end of the connection.