Skip to content
Proxy fundamentals

SOCKS4 vs SOCKS5: Differences Tested on the Wire

SOCKS5 adds passwords, IPv6, UDP and proxy-side DNS; SOCKS4 saves one round trip. Real handshakes from curl, Chrome, Firefox and Go.

On this page 10 sections
  1. SOCKS4 vs SOCKS4a vs SOCKS5 at a glance
  2. The handshakes, byte by byte
  3. Round trips are the only speed difference
  4. Who resolves the hostname
  5. Authentication: SOCKS4 has nowhere to put a password
  6. IPv6 destinations
  7. UDP: in the SOCKS5 spec, often missing from the server
  8. Error reporting
  9. When each one is the right choice
  10. Reproduce it

Use SOCKS5 unless the client in front of you cannot speak it. SOCKS5 carries everything SOCKS4 carries and adds four things SOCKS4 has no field for: a password, an IPv6 destination, UDP, and a hostname for the proxy to resolve. SOCKS4 keeps one advantage. Its handshake is a single round trip, where SOCKS5 needs two, or three with a password. With 50 ms of added round-trip time, that gap measured 50.5 ms per new connection in our test.

The version number decides less than the setting beside it. Whether your hostname ever leaves your machine is decided by socks4 versus socks4a, and socks5 versus socks5h, and the clients we tested do not agree on the default.

SOCKS4 vs SOCKS4a vs SOCKS5 at a glance

SOCKS4a is an extension of SOCKS4, and software labelled “SOCKS4” may mean either, so check which. It gets its own column because it fixes the worst problem SOCKS4 has.

SOCKS4 SOCKS4a SOCKS5
Specification Ying-Da Lee, NEC, “SOCKS: A protocol for TCP proxy across firewalls” Ying-Da Lee, “SOCKS 4A: A Simple Extension to SOCKS 4 Protocol” RFC 1928, March 1996
Password No. One USERID field, no password No. Same USERID field Yes. Username and password (RFC 1929), or GSS-API
What the client can send as the destination An IPv4 address An IPv4 address or a hostname An IPv4 address, an IPv6 address or a hostname
Who resolves the hostname Always the client The proxy Either. The client picks, through the address type
IPv6 destinations No Only by name, if the server resolves to IPv6 Yes
UDP No No Defined (UDP ASSOCIATE). Server support varies
Commands CONNECT, BIND CONNECT, BIND CONNECT, BIND, UDP ASSOCIATE
Round trips before your first byte, measured 1 1 2, or 3 with a password
Failure codes 91 for every failure. 92 and 93 are identd checks Same as SOCKS4 Eight, from X’01’ to X’08’, each naming a cause
curl scheme socks4:// socks4a:// socks5:// (client resolves), socks5h:// (proxy resolves)
Right choice when Almost never The client offers nothing newer Every other case

The rest of this page is the evidence for each row, captured from real software rather than restated from the specs.

What we ran. On 21 October 2026, on macOS 26.6.2 on Apple silicon. The SOCKS server was OpenSSH_10.3p1 ssh -D, which speaks both versions on one port, connected to a local sshd. A 59-line Python relay sat between client and server and recorded every byte in both directions. The clients were curl 8.23.0, Chrome 155.0.8059.85 (headless), Firefox 151.0.2 (headless) and Go 1.24.4’s net/http. OpenSSH sent no failure code in any of our failure tests and does not do SOCKS5 passwords, so for those two rows we also used a small test server we wrote to RFC 1928 and RFC 1929. It dials the real target and answers with the code the spec assigns. Every hex dump and error string below is copied from those runs.

The handshakes, byte by byte

Here is the whole of a SOCKS4 handshake, from curl -x socks4://127.0.0.1:21081 http://example.com/:

-> 04 01 00 50 68 14 17 9a 00     VN=4, CD=1 (CONNECT), port 80, 104.20.23.154, empty USERID
<- 00 5a 00 00 00 00 00 00        CD=0x5a (90): request granted
-> GET / HTTP/1.1 ...

Nine bytes out, eight back, and the HTTP request follows. Note the four bytes 68 14 17 9a. That is an address curl had already looked up for example.com, because the request has no other place to put a destination.

SOCKS4a keeps the same layout and abuses it. The client writes 0.0.0.1 as the address, which no real host uses, and appends the name after the USERID:

-> 04 01 00 50 00 00 00 01 00 65 78 61 6d 70 6c 65 2e 63 6f 6d 00
   DSTIP 0.0.0.1, empty USERID, then "example.com" and a closing NUL
<- 00 5a 00 00 00 00 00 00

SOCKS5 adds a negotiation step before the request. This is socks5h://, so the name goes to the proxy as address type 3:

-> 05 02 00 01                      greeting: two methods offered, 00 (none) and 01 (GSS-API)
<- 05 00                            server picks 00
-> 05 01 00 03 0b 65 78 61 6d 70 6c 65 2e 63 6f 6d 00 50
                                    CONNECT, ATYP 3, an 11-byte name, port 80
<- 05 00 00 01 00 00 00 00 00 50    REP 00: succeeded

The 01 in curl’s greeting surprised us. This curl build lists GSS-API among its features, and curl’s manual says GSS-API authentication is enabled by default in such builds, so it is offered even though nobody asked for it. Go 1.24.4 and Chrome 155 both sent the shorter 05 01 00, offering no authentication only.

Variant (curl 8.23.0, CONNECT to example.com:80) Bytes from client Bytes from server Round trips
SOCKS4 9 8 1
SOCKS4a 21 8 1
SOCKS5, client resolves 14 12 2
SOCKS5h, proxy resolves 22 12 2
SOCKS5h with username and password 37 14 3

The byte counts are noise next to a TLS handshake. The round trips are where the time goes.

Round trips are the only speed difference

Once the handshake is done, neither version touches your data. Both copy bytes in each direction until one side closes. So a claim that one is “faster” can only be about setup, and setup is a count of round trips.

We measured it. The relay added 25 ms to every chunk in each direction, so each request and reply exchange cost about 50 ms. TCP setup was not delayed. The target was a local web server, so almost nothing else contributed. Each variant ran 30 times, interleaved round by round, and the figure is curl’s %{time_starttransfer}.

Median time to first byte with 50 ms of added round-trip time, 30 runs per variant, curl 8.23.0, 21 October 2026 Drawn from the table below.
Median time to first byte with 50 ms of added round-trip time, 30 runs per variant, curl 8.23.0, 21 October 2026. Bar chart of Median (ms) by Handshake.6 rows, drawn from the table that follows this chart.No SOCKS, relay onlyNo SOCKS, relay only: 53.353.3SOCKS4, OpenSSHSOCKS4, OpenSSH: 106.7106.7SOCKS5, OpenSSHSOCKS5, OpenSSH: 157.2157.2SOCKS4, test serverSOCKS4, test server: 106.3106.3SOCKS5, test serverSOCKS5, test server: 158.9158.9SOCKS5 with password, test serverSOCKS5 with password, test server: 210.5210.5050100150200250 msMedian time to first byte with 50 ms of added round-trip time, 30 runs per variant, curl 8.23.0, 21 October 2026. Bar chart of Median (ms) by Handshake.6 rows, drawn from the table that follows this chart.No SOCKS, relay onlyNo SOCKS, relay only: 53.353.3SOCKS4, OpenSSHSOCKS4, OpenSSH: 106.7106.7SOCKS5, OpenSSHSOCKS5, OpenSSH: 157.2157.2SOCKS4, test serverSOCKS4, test server: 106.3106.3SOCKS5, test serverSOCKS5, test server: 158.9158.9SOCKS5 with password,test serverSOCKS5 with password, test server: 210.5210.50100200300 ms
Handshake Server Round trips before the request Median (ms) 90th percentile (ms)
No SOCKS, relay only none 0 53.3 57.6
SOCKS4, OpenSSH OpenSSH_10.3p1 1 106.7 138.1
SOCKS5, OpenSSH OpenSSH_10.3p1 2 157.2 164.5
SOCKS4, test server RFC test server 1 106.3 117.9
SOCKS5, test server RFC test server 2 158.9 169.2
SOCKS5 with password, test server RFC test server 3 210.5 223.6

Each added round trip cost between 50.5 and 53.4 ms, close to the 50 ms the relay adds per exchange. So the result is linear in round trips, and the two servers agree to within 2 ms. Scale it to your own link. A gateway with a 150 ms round trip costs SOCKS5 roughly 150 ms more than SOCKS4 on every new connection, and another 150 ms if it asks for a password.

Two things shrink that cost in practice. Keep-alive pays the handshake once per connection, not once per request. And the cost only exists when the SOCKS server is across the network. With ssh -D the SOCKS server is a process on your own machine, the slow hop is the SSH channel behind it, and the extra SOCKS5 round trip is local. Unthrottled, our relay saw OpenSSH answer curl’s SOCKS5 greeting 0.16 ms after the greeting went past. Per-request rotating gateways get no such discount: every request is a new connection.

Who resolves the hostname

This is the difference that causes real bugs. Plain SOCKS4 has a four-byte address field and nowhere to put a name, so the client must resolve the name first. Two things follow. Your local resolver sees every hostname you visit, which is a DNS leak. And the name is resolved from your location, so a CDN can hand you an address chosen for you rather than for the proxy’s exit country.

SOCKS4a and SOCKS5 with address type 3 move the lookup to the proxy. You can see which one happened in the failure mode. Port 21081 below is OpenSSH behind our relay and 21084 is the RFC test server. With socks4:// and a name that does not exist, curl failed before it sent the proxy a single byte:

$ curl -x socks4://127.0.0.1:21081 http://nx-host.invalid/
curl: (6) Could not resolve host: nx-host.invalid

$ curl -x socks5h://127.0.0.1:21084 http://nx-host.invalid/
curl: (97) cannot complete SOCKS5 connection to nx-host.invalid. (4)

Exit code 6 means your machine did the lookup. Exit code 97, which curl’s manual calls “Proxy handshake error”, means the proxy did and reported back.

The trap is that the same URL means different things in different clients. We pointed each one at the logging relay and read what actually went out:

Client Setting What went on the wire Name resolved by
curl 8.23.0 socks4:// SOCKS4, address 104.20.23.154 Client
curl 8.23.0 socks4a:// SOCKS4a, 0.0.0.1 plus “example.com” Proxy
curl 8.23.0 socks5:// SOCKS5, ATYP 1, 104.20.23.154 Client
curl 8.23.0 socks5h:// SOCKS5, ATYP 3, “example.com” Proxy
Chrome 155.0.8059.85 --proxy-server=socks4:// SOCKS4, an IPv4 address Client
Chrome 155.0.8059.85 --proxy-server=socks5:// SOCKS5, ATYP 3, the hostname Proxy
Firefox 151.0.2 SOCKS v4, prefs at default SOCKS4, address 172.66.147.243 Client
Firefox 151.0.2 SOCKS v4, network.proxy.socks_remote_dns true SOCKS4a, 0.0.0.1 plus “example.com” Proxy
Firefox 151.0.2 SOCKS v5, prefs at default SOCKS5, ATYP 3, “example.com” Proxy
Firefox 151.0.2 SOCKS v5, network.proxy.socks5_remote_dns false SOCKS5, ATYP 1, an IPv4 address Client
Go 1.24.4 net/http socks5:// SOCKS5, ATYP 3, “example.com” Proxy
Go 1.24.4 net/http socks4:// A plain HTTP request, GET http://example.com/, sent to the SOCKS port Nothing reached a SOCKS server

Go’s documentation says it outright: "socks5" is treated the same as "socks5h". Chrome’s proxy documentation says SOCKS5 name resolution is always done at the proxy and SOCKSv4 resolution is always done on the client. curl and urllib3, the library under Python requests, take socks5:// literally and resolve locally. So a proxy URL copied from a Go service into a Python script starts leaking DNS with no error and no warning. Our Python proxy guide and curl guide both default to socks5h:// for that reason.

The last Go row is worth a second look. Go 1.24.4 does not reject socks4://. It treats the unknown scheme as an HTTP proxy, writes an HTTP request into the SOCKS port, and reports only Get "http://example.com/": EOF. If a Go program fails that way, check the scheme before you check the proxy.

Documentation covers clients we did not run. urllib3, and so requests, accepts socks4://, socks4a://, socks5:// and socks5h://, and sends the username of a SOCKS4 URL as the USERID. HTTPX documents socks5:// only, through the httpx[socks] extra. apt 3.3.3 lists socks5h as its one SOCKS scheme. Chrome does not offer SOCKS4a at all.

A SOCKS server can also refuse clients that resolved the name themselves. With SafeSocks enabled, Tor’s SOCKS listener rejects “socks4 and socks5 when not doing remote DNS”, and TestSocks logs which kind each connection used.

Authentication: SOCKS4 has nowhere to put a password

SOCKS4’s only identity field is USERID, a NUL-terminated string. The original design checked it against identd on the client machine, which is what reply codes 92 and 93 are for. There is no password, so any gateway that authenticates by username and password is out of reach over SOCKS4. The only way in would be an allowlist of source IPs.

curl drops the password without a word. We gave curl 8.23.0 -x socks4://alice:secret@127.0.0.1:21081. It sent 04 01 00 50 ac 42 93 f3 61 6c 69 63 65 00: the username “alice” in the USERID field, and no trace of “secret”. No warning appeared in -v output. If a provider gave you a username and password and the connection is failing, check that the scheme is not socks4.

SOCKS5 does have a password, through the RFC 1929 sub-negotiation, and it travels in the clear. This is what curl sent after the server picked method 02:

-> 01 05 61 6c 69 63 65 06 73 65 63 72 65 74
   VER=1, ULEN=5, "alice", PLEN=6, "secret"
<- 01 00                              STATUS 00: accepted

RFC 1929 itself says that, because the request carries the password in cleartext, the method is not recommended where sniffing is possible. In practice a SOCKS5 password is about as exposed as the Basic credentials of an HTTP proxy. The proxy authentication entry covers the alternatives.

When authentication goes wrong, curl’s messages are specific:

# no credentials, server requires them (server answered 05 ff)
curl: (97) No authentication method was acceptable.

# wrong password (server answered 01 01)
curl: (97) User was rejected by the SOCKS5 server (1 1).

These play the role a 407 plays for an HTTP proxy, and the logic in 403 vs 407 vs 429 carries over. One more limit: Chromium’s documentation states that Chrome supports no authentication for SOCKSv4 or SOCKSv5. A password-protected SOCKS5 gateway in Chrome needs an IP allowlist, or a local forwarder that adds the credentials for it.

IPv6 destinations

SOCKS4’s address field is four bytes, so an IPv6 literal cannot be expressed. curl checks before it sends anything. The TCP connection to the proxy opened and closed with zero bytes written, and curl printed:

curl: (97) SOCKS4 connection to ::1 not supported

SOCKS4a gets through by accident. curl wrote ::1 into the hostname slot, OpenSSH resolved that “name” to the IPv6 loopback address, connected, and we got a 200. The reply still had only four bytes of address, all zeros. SOCKS5 carries the address properly, as address type 4 with 16 bytes:

-> 05 01 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 6d c3
   CONNECT, ATYP 4, ::1, port 28099

Chromium’s documentation states the same limit from the browser side: with SOCKSv4 the target must be IPv4.

UDP: in the SOCKS5 spec, often missing from the server

Only SOCKS5 defines UDP, through the UDP ASSOCIATE command. SOCKS4 is TCP only. But a protocol that defines UDP is not a server that relays it. We sent UDP ASSOCIATE and BIND to OpenSSH’s SOCKS5 listener by hand. It accepted the greeting with 05 00, then closed the connection on both commands without sending a reply code. OpenSSH’s dynamic forwarding is CONNECT only.

The browser side is the same story. Chromium’s documentation says SOCKSv5 in Chrome is used only for TCP-based URL requests and cannot relay UDP. So Chrome will not send QUIC, which runs over UDP, through a SOCKS5 proxy, whatever the proxy supports. If you need UDP for DNS, QUIC, games or voice, get the provider to confirm UDP ASSOCIATE in writing and test it yourself. The word “SOCKS5” on a product page does not answer the question.

Error reporting

SOCKS4 has one code for every network failure. SOCKS5 says why. Same failures, same curl:

Failure SOCKS4 reply curl 8.23.0 said SOCKS5 reply curl 8.23.0 said
Target port closed 91 [SOCKS] cannot complete SOCKS4 connection to 0.0.0.0:0. (91), request rejected or failed. X’05’ cannot complete SOCKS5 connection to 127.0.0.1. (5)
Name does not resolve at the proxy 91 (over SOCKS4a) The same message as above X’04’ cannot complete SOCKS5 connection to nx-host.invalid. (4)
Any failure behind OpenSSH ssh -D None. Connection closed Failed to receive SOCKS response, proxy closed connection None. Connection closed The same message

Two details are easy to misread. The 0.0.0.0:0 in curl’s SOCKS4 message is not your destination. curl prints the address fields of the reply, which the SOCKS4 spec tells clients to ignore. And OpenSSH reports nothing to the SOCKS client. The reason goes to ssh’s own stderr instead, as channel 1: open failed: connect failed: Connection refused, or nodename nor servname provided, or not known for a bad name on macOS. When you debug through ssh -D, read the ssh terminal, not the client.

When each one is the right choice

  • Use SOCKS5 with proxy-side resolution (socks5h:// in curl and Python) for scraping, for any commercial proxy gateway, for anything that authenticates with a password, for anything that might meet an IPv6 address, and for UDP once you have confirmed the server relays it. This covers nearly every case.
  • Use SOCKS4a when the client offers SOCKS4 and nothing newer. You keep DNS at the proxy and lose passwords, IPv6 literals and UDP.
  • Use plain SOCKS4 only for a trusted proxy that needs no credentials, with IPv4 destinations, where a leaked lookup does not matter. The saved round trip is real, but SOCKS4a saves the same round trip without the leak, so even then there is little reason to pick it.

If you are deciding between SOCKS and an HTTP proxy rather than between SOCKS versions, that is a different question. An HTTP proxy understands HTTP and tunnels everything else with CONNECT; the SOCKS5 entry and what a proxy server is cover that split.

Reproduce it

Any machine with OpenSSH and curl can repeat the capture. ssh -D gives you a server that speaks both versions on one port, so the comparison stays fair.

# OpenSSH 10.3p1: one listener, SOCKS4, SOCKS4a and SOCKS5
ssh -N -D 127.0.0.1:1080 user@ssh.example.net

# curl 8.23.0: one request per variant, -v shows the SOCKS step
curl -v -x socks4://127.0.0.1:1080  http://example.com/
curl -v -x socks4a://127.0.0.1:1080 http://example.com/
curl -v -x socks5://127.0.0.1:1080  http://example.com/
curl -v -x socks5h://127.0.0.1:1080 http://example.com/

# time to first byte, to compare handshakes against a remote gateway
curl -s -o /dev/null -w '%{time_starttransfer}\n' \
  -x socks5h://user:pass@gw.example.net:1080 http://example.com/

To see the bytes without a capture tool, this script speaks each handshake by hand. It uses only the standard library and ran on Python 3.15.0:

#!/usr/bin/env python3
# Speak SOCKS4, SOCKS4a or SOCKS5 by hand and print every byte. Standard library only.
# usage: python3 socks_probe.py {4|4a|5} PROXY_HOST PROXY_PORT DEST_HOST DEST_PORT
import socket, struct, sys

ver, phost, pport, host, port = sys.argv[1], sys.argv[2], int(sys.argv[3]), sys.argv[4], int(sys.argv[5])
s = socket.create_connection((phost, pport), timeout=10)

def send(b):
    print("->", b.hex(" ")); s.sendall(b)

def recv(n):
    b = s.recv(n); print("<-", b.hex(" ") if b else "(connection closed)"); return b

if ver == "4":    # client resolves the name; only an IPv4 address fits in the request
    send(struct.pack(">BBH", 4, 1, port) + socket.inet_aton(socket.gethostbyname(host)) + b"\0")
    r = recv(8); print("granted" if r[1:2] == b"\x5a" else f"CD={r[1] if r else None}")
elif ver == "4a": # 0.0.0.1 tells the server a hostname follows the USERID
    send(struct.pack(">BBH", 4, 1, port) + b"\0\0\0\1" + b"\0" + host.encode() + b"\0")
    r = recv(8); print("granted" if r[1:2] == b"\x5a" else f"CD={r[1] if r else None}")
else:             # greeting, method choice, then a request carrying the name (ATYP 3)
    send(b"\x05\x01\x00")
    recv(2)
    send(b"\x05\x01\x00\x03" + bytes([len(host)]) + host.encode() + struct.pack(">H", port))
    r = recv(10); print("succeeded" if r[1:2] == b"\x00" else f"REP={r[1] if len(r) > 1 else None}")
s.close()

Against ssh -D, python3 socks_probe.py 5 127.0.0.1 1080 example.com 80 printed:

-> 05 01 00
<- 05 00
-> 05 01 00 03 0b 65 78 61 6d 70 6c 65 2e 63 6f 6d 00 50
<- 05 00 00 01 00 00 00 00 00 50
succeeded

Point the same script at a port nothing listens on and the difference between versions shows up at once. Our RFC test server answered 00 5b (91) to SOCKS4 and 05 05 (connection refused) to SOCKS5. OpenSSH closed the connection on both.

Frequently asked questions

Is SOCKS5 faster than SOCKS4?
Only SOCKS4's setup is faster. SOCKS4 needs one round trip before your data and SOCKS5 needs two, or three with a password. With 50 ms of added round-trip time we measured medians of 106.7 ms and 157.2 ms to first byte through OpenSSH's ssh -D. After the handshake both versions relay bytes unchanged, so throughput is the same.
Is SOCKS5 more secure than SOCKS4?
Neither encrypts anything. SOCKS5 adds password authentication, but RFC 1929 sends the password in cleartext. Its practical gain is that it can hand the hostname to the proxy, so your local resolver never sees the lookup. SOCKS4a can do that too.
What is SOCKS4a?
An extension to SOCKS4 by the same author, Ying-Da Lee. The client writes 0.0.0.x as the address, which no real host uses, and appends the hostname after the USERID field. The proxy resolves the name. In curl the scheme is socks4a://.
Can one proxy port accept both SOCKS4 and SOCKS5?
Yes, if the server supports it, because the first byte of every request is the version number. OpenSSH's ssh -D answered SOCKS4, SOCKS4a and SOCKS5 on the same port in our test. A commercial gateway may accept only SOCKS5, so check its documentation.
Which is better, an HTTP proxy or a SOCKS proxy?
They work at different layers. An HTTP proxy understands HTTP, can read plain HTTP requests and tunnels HTTPS with CONNECT. SOCKS5 relays any TCP connection without reading it. For HTTP scraping either works. For other protocols, such as SSH, SMTP or a database connection, use SOCKS5.
What are the disadvantages of SOCKS5?
No encryption, a cleartext password, one or two more round trips than SOCKS4 on every new connection, and UDP support that many servers and clients leave out. Chrome supports no SOCKS authentication at all, and curl, urllib3 and requests resolve names locally unless you write socks5h://.
Is a SOCKS5 proxy the same as a VPN?
No. A SOCKS5 proxy is set per application and relays that application's connections without encrypting them. A VPN usually moves all of a device's traffic through an encrypted tunnel. You can run SOCKS5 inside an encrypted channel, as ssh -D does, but then SSH is providing the encryption.

Sources

  1. Ying-Da Lee: SOCKS, A protocol for TCP proxy across firewalls (SOCKS4)
  2. Ying-Da Lee: SOCKS 4A, A Simple Extension to SOCKS 4 Protocol
  3. RFC 1928: SOCKS Protocol Version 5
  4. RFC 1929: Username/Password Authentication for SOCKS V5
  5. curl manual: --socks4, --socks4a, --socks5, --socks5-hostname and exit code 97
  6. Chromium: Proxy support in Chrome (SOCKSv4 and SOCKSv5)
  7. OpenSSH ssh(1): -D dynamic port forwarding
  8. Go net/http: Transport.Proxy URL schemes
  9. urllib3: SOCKS proxies
  10. HTTPX: Proxies
  11. apt-transport-http(1): supported proxy schemes
  12. tor(1): SafeSocks and TestSocks

Read this page as Markdown · Quote it freely under CC BY 4.0 with a link back.