The browser determines that a website requires HTTPS and initiates a TLS handshake based on the URL scheme specified in the address bar. When you type https://, the browser explicitly requests a secure connection, triggering the TLS negotiation with the server. If the scheme is http://, no TLS handshake occurs, and data is sent in plain text.
The Role of the URL Scheme
The primary mechanism by which a browser knows to start a TLS handshake is the protocol identifier at the beginning of the Uniform Resource Locator (URL). This scheme acts as an instruction set for the browser's networking stack. When a user enters a web address or clicks a hyperlink, the browser parses this string to determine how to establish the underlying transport layer connection. If the URL begins withhttps://, the browser recognizes that the Hypertext Transfer Protocol Secure is required. This signals the browser to open a TCP connection to the default port for HTTPS, which is typically 443. Once the TCP connection is established, the browser immediately initiates the TLS handshake process. This sequence ensures that all subsequent HTTP traffic is encrypted before any data is exchanged.
Conversely, if the URL starts with http://, the browser connects to port 80 and skips the TLS phase entirely. It sends raw HTTP requests over the wire. There is no negotiation for encryption because the client has not requested it via the scheme. This distinction is fundamental to web security architecture. The browser does not guess whether encryption is needed; it relies strictly on the explicit directive provided in the address bar or the link destination.
Automatic Upgrades and HSTS
While the URL scheme is the direct trigger, modern browsers often force HTTPS connections even if the user typeshttp://. This behavior is driven by a mechanism called HTTP Strict Transport Security (HSTS). Websites can send a response header named Strict-Transport-Security that instructs compliant browsers to always use HTTPS for future requests to that domain.
When a browser encounters an HSTS header from a trusted source, it stores this policy in its internal database. Subsequent visits to that domain, even via insecure links or manual entry of http://, are automatically upgraded to https:// before any network request is made. This prevents man-in-the-middle attacks where an attacker might redirect a user to an insecure version of the site. In these cases, the browser still performs a TLS handshake, but the decision was made locally based on stored policy rather than the immediate URL input.
For more details on why certain services fail when port configurations are incorrect during these handshakes, you may refer to our guide on Why I Can't Access My Web Service on Port 80. Understanding port assignments is crucial because the TLS handshake must occur on the correct port agreed upon by the scheme.
The TLS Handshake Process
Once the browser decides a TLS handshake is necessary, it engages in a complex exchange with the web server to establish a secure session. This process happens before any HTTP data is transmitted. The first step involves the client sending a "Client Hello" message. This packet contains the TLS version the browser supports, a list of supported cipher suites, and random bytes used for key generation. The server responds with a "Server Hello," selecting the highest common TLS version and cipher suite from the client's list. It also sends its digital certificate, which contains the public key and identity information verified by a Certificate Authority. The browser validates this certificate against its local store of trusted roots. If the certificate is valid and matches the domain name, the handshake proceeds. Subsequent messages involve the exchange of keys and the verification of integrity. Both parties generate a shared secret without transmitting it directly. This shared secret becomes the symmetric key used to encrypt all further communication. If any step fails, such as an invalid certificate or mismatched cipher support, the browser displays a warning page and aborts the connection. You can find troubleshooting steps for failed handshakes in our article on Client Fails TLS Handshake: Troubleshooting Guide.Security Implications of Plain HTTP
Understanding how the browser identifies HTTPS requirements highlights the risks associated with plain HTTP. Without the TLS handshake, data travels in plaintext across multiple network hops. Any intermediate device, such as a router, ISP, or public Wi-Fi access point, can intercept and read this traffic. Sensitive information like passwords, credit card numbers, and personal messages become vulnerable to eavesdropping. Furthermore, attackers can modify the content in transit. This is known as a man-in-the-middle attack. By altering responses, an attacker could inject malware, steal sessions, or deface the webpage. The TLS handshake mitigates these risks by providing confidentiality, integrity, and authentication. It ensures that the client is talking to the intended server and that the data has not been altered. Modern browsers actively discourage the use of HTTP by displaying prominent warnings. They may label HTTP sites as "Not Secure" in the address bar. Some browsers even block mixed content, where a secure page loads insecure resources like images or scripts. This enforcement encourages developers to implement HTTPS universally. As the web evolves, the expectation is that all connections will be secure by default, eliminating the ambiguity of whether a handshake should occur.Frequently Asked Questions
What happens if I manually type http:// instead of https://?
If you type http://, the browser will connect to port 80 and skip the TLS handshake entirely. No encryption will be applied to the data transmitted between your computer and the server. The connection will be visible to anyone monitoring the network traffic.
Can a website force my browser to use HTTPS without me typing it?
Yes, through HTTP Strict Transport Security (HSTS). If a site has previously sent an HSTS header, your browser remembers this and automatically upgrades any http:// requests to https:// before making the connection. This happens transparently to the user.
Why does my browser show a security warning even with HTTPS?
A security warning indicates that the TLS handshake failed or the certificate is untrusted. This could be due to an expired certificate, a domain name mismatch, or a missing root certificate in your browser's trust store. The browser refuses to proceed until the identity of the server is verified.
Does using HTTPS slow down the website loading time?
The initial TLS handshake adds a small amount of latency due to the cryptographic negotiations. However, modern optimizations like TLS session resumption and HTTP/2 significantly reduce this overhead. The security benefits far outweigh the minimal performance cost.
How can I check if a specific site supports TLS 1.3?
You can inspect the network tab in your browser's developer tools while visiting the site. Look for the connection details after the handshake completes. The protocol version listed there will indicate whether TLS 1.2 or 1.3 was negotiated. Newer sites typically support TLS 1.3 for improved speed and security.