WireGuard: what the protocol is and how it works

WireGuard is a VPN protocol that carries IP packets inside UDP with one fixed set of cryptography: Curve25519 keys, ChaCha20-Poly1305 encryption and BLAKE2s hashing, joined in a Noise IK handshake. Each device is known by its public key, and a ten-line .conf file with an [Interface] and a [Peer] section is the whole setup. It has been part of the Linux kernel since version 5.6 in March 2020, and it makes no attempt to hide what it is.

Updated

On this page

Facts

What it is

VPN: a virtual adapter that carries IP packets

Since, by

Jason A. Donenfeld; paper at NDSS 2017

Transport

UDP only, no TCP mode

Encryption

Noise IK: Curve25519, ChaCha20-Poly1305, BLAKE2s

To the network it looks like

UDP with fixed type bytes and handshake sizes

Usual port

Any UDP port; 51820 in the official examples

Comes as

.conf file with [Interface] and [Peer] sections

License

GPLv2 in the Linux kernel, MIT for wireguard-go

In Veli

Windows, macOS, Linux, Android · file

Own server from the app

Yes

Versions and history

  1. 2017

    The NDSS paper

    Jason A. Donenfeld presents WireGuard at the NDSS 2017 symposium: a one-round-trip Noise handshake, keys bound to tunnel addresses and a Linux implementation in under 4,000 lines.

  2. 2020

    Linux 5.6 and WireGuard 1.0.0

    From Linux 5.6, released at the end of March 2020, the kernel has WireGuard built in. The project kept backports for the 5.4 and 5.5 kernels, Ubuntu 20.04 and Debian Buster.

  3. 2021

    First blocking reports from Russia

    From 3 to 8 September 2021 users of several Russian ISPs reported WireGuard handshakes failing (net4people #76). One tester saw plain UDP to the same port get through.

  4. 2023

    Cut with OpenVPN, and forked

    On 7 August 2023 WireGuard and OpenVPN stopped working on several Russian mobile networks (net4people #274). The same year the Amnezia project started AmneziaWG, a fork that disguises the packets.

How WireGuard works

Each side has a Curve25519 key pair. The server lists every device by its public key together with the tunnel addresses that device may use, its AllowedIPs. That list is the whole access control: there are no user names, passwords or certificates. WireGuard calls it cryptokey routing. On the way out, the destination address picks the peer and its key; on the way in, a packet that decrypts with a peer's key is kept only if its source address is on that peer's list.

The handshake is a single round trip built on the Noise framework, Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s. The first message already proves who sent it and carries an encrypted TAI64N timestamp, so a replayed copy is thrown away. Then both sides derive session keys and send data with ChaCha20-Poly1305. A fresh handshake runs about every two minutes (Rekey-After-Time is 120 seconds), and old keys are wiped.

There is no connection to keep alive. When a phone moves from Wi-Fi to mobile data, the server answers to the address the last authentic packet came from, and the tunnel goes on. A packet that doesn't authenticate gets no reply at all, which the paper calls “silence is a virtue”: to a port scanner the server looks like a closed UDP port.

The four packet types

Every WireGuard packet begins with a one-byte type and three zero bytes. Handshake messages have fixed lengths, and data is padded inside the encryption to a multiple of 16 bytes. These values are what DPI keys on.

  • 1

    MessageHandshake initiation

    UDP payload148 bytes

    What is insideSender index, ephemeral key, encrypted static key and timestamp, mac1, mac2

  • 2

    MessageHandshake response

    UDP payload92 bytes

    What is insideSender and receiver index, ephemeral key, an empty encrypted field, mac1, mac2

  • 3

    MessageCookie reply

    UDP payload64 bytes

    What is insideSent only by a server under load, so the client proves its address before it gets an answer

  • 4

    MessageTransport data

    UDP payload32 bytes + data

    What is insideReceiver index, an 8-byte counter, the encrypted packet and a 16-byte tag; a keepalive is exactly 32 bytes

The .conf file, line by line

wg-quick and the WireGuard apps read the same INI-style file. A client file usually looks like this.

client.conf
[Interface]
PrivateKey = w5Ze8aDPTRUdKj0uKpqZ6+VBCOTAdl33C7HiK1KiiT8=
Address = 10.8.0.2/32
DNS = 1.1.1.1

[Peer]
PublicKey = C/oVjMOrvIkRWl60tMMhXZ+grNt44x+BuDfdCtXCKbk=
PresharedKey = BTPIhjedFnS7jQc82zfglHxSWtfE31CZ/7WLae10k1c=
Endpoint = 203.0.113.10:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

The keys and the address are made up. A server file has ListenPort in [Interface] and one [Peer] per device.

  • PrivateKey

    What it doesThis device's key, base64 from wg genkey. Whoever has the file can connect as this device.

  • Address

    What it doesThe device's address inside the tunnel. wg-quick and the apps set it; the protocol itself never sends it.

  • DNS

    What it doesResolvers for the time the tunnel is up; wg-quick passes them to resolvconf.

  • MTU

    What it doesOptional. Without it wg-quick takes the MTU of the route to the server, or 1500, and subtracts 80: usually 1420.

  • ListenPort

    What it doesOn a server, the UDP port to listen on. If it is missing, a random port is chosen.

  • PublicKey

    What it doesThe server's public key. The server also knows this device by the matching public key.

  • PresharedKey

    What it doesOptional shared secret mixed into the handshake as an extra symmetric layer.

  • Endpoint

    What it doesServer address and UDP port. It is updated to wherever authentic packets arrive from.

  • AllowedIPs

    What it doesWhat goes into this peer. 0.0.0.0/0, ::/0 takes all traffic, and wg-quick then adds policy routing so the tunnel's own UDP goes around it.

  • PersistentKeepalive

    What it doesOff by default. 25 seconds keeps a NAT mapping open; without it an idle tunnel sends nothing.

UDP only: port, MTU and TCP

WireGuard has no TCP mode, and its authors say it will not get one: putting it over TCP is a job for a separate layer such as udp2raw or udptunnel. So the answer to “UDP or TCP” is always UDP, and a network that drops UDP to the server stops WireGuard completely.

There is no fixed port either. A server listens where ListenPort says, a client sends from a random port, and 51820 is simply the number in the official examples, which most installers copy. Any free UDP port works, 443 and 53 included, but another port number doesn't make the packets look any different.

1420 comes from 1500 minus 80 bytes: 32 for WireGuard, 8 for UDP and 40 for an IPv6 header (over IPv4 the overhead is 60). On a link with a smaller MTU, such as PPPoE or some mobile networks, set MTU 80 below the link's own. Small pages loading while large downloads and some sites hang is the usual sign that it is too high.

What a censor sees

  • Without any key: UDP to one address and port, with the first payload byte 1, 2, 3 or 4 followed by 00 00 00. The handshake is 148 bytes one way and 92 the other, a keepalive is 32, and data grows in steps of 16. The 4-byte index from the handshake reappears in every data packet, so a flow is easy to follow.
  • Open DPI does exactly this. nDPI, an open-source DPI library, recognises WireGuard by the type byte, the zero bytes, the fixed handshake sizes and the matching indexes.
  • Probing gets nothing back. Without a valid mac1 the server stays silent, so a censor learns more by watching than by knocking.
  • What stays hidden: the sites you open, DNS inside the tunnel and the keys. The server's address is visible and can be blocked on its own.
  • Reported blocking: Russia in September 2021 (net4people #76, several ISPs; one report pointed at UDP packets starting with 01 00) and again from 7 August 2023 on mobile networks, together with OpenVPN (net4people #274, where users described tunnels cut right after the handshake). These are user reports collected on the net4people forum, not a published measurement.

Strengths and weaknesses

Strengths

  • One fixed set of algorithms: there is no cipher list to get wrong and nothing to downgrade.
  • In the Linux kernel since 5.6, so many routers, NAS boxes and servers already have it.
  • A change of network doesn't break the tunnel: the next authentic packet updates the address.
  • Silent to unauthenticated packets, so a scan doesn't reveal the server.
  • Little overhead: 32 bytes per packet on top of the UDP and IP headers.

Weaknesses

  • UDP only: where UDP is blocked or throttled, it doesn't connect at all.
  • Recognisable from the first packet by its type bytes and handshake sizes.
  • No users or certificates: access is a key in a file, revoked by deleting it on the server.
  • Addresses, routes and DNS live in each device's file; the server can't push them.
  • Not post-quantum by default; PresharedKey only adds a symmetric layer.

Where it works

Programs and servers from our comparison tables that list this protocol.

Clients

  • Happ
  • Hiddify
  • v2RayTun
  • INCY
  • Karing
  • v2rayNG
  • v2rayN
  • NekoBox for Android
  • Throne
  • V2Box
  • AmneziaVPN
  • Clash Verge Rev
  • Clash Party
  • FlClash
  • Shadowrocket
  • Stash
  • mihomo
  • sing-box
  • podkop
  • zapret
  • PassWall
  • PassWall 2

Servers and panels

  • 3X-UI
  • S-UI
  • Hiddify Manager
  • wg-easy
  • PiVPN
  • Tailscale
  • NetBird
  • Headscale

Compare these programs

Sources

How we write and check

In Veli

WireGuard in Veli

Veli connects WireGuard on Windows, macOS, Linux and Android. Profiles → Add → “Open a file” takes the .conf, and a profile moves from a computer to the phone by its QR code. On a computer the “Apps and sites” rules for WireGuard work by IP address only; on Android, choosing which apps use the VPN works with any protocol.

“Own server” installs WireGuard on your VPS over SSH, and each device gets its own file and QR code. If plain WireGuard is recognised on your network, a WireGuard profile on a computer can turn on AmneziaWG obfuscation in its settings: junk packets go out before each handshake, and the server stays plain WireGuard.

Questions

Is WireGuard UDP or TCP?

UDP only. The project explicitly doesn't support TCP; tools like udp2raw can wrap it as a separate layer, or you take a protocol that runs over TCP.

What port does WireGuard use?

Whatever the server sets in ListenPort. 51820 is the port in the official examples and most installers; with no port set, a random one is picked.

Why is WireGuard blocked or not connecting?

Either the network recognises the handshake by its type byte and fixed sizes, or UDP to the server is cut. If wg show has no recent latest handshake, the server never answered.

What MTU should WireGuard use?

1420 is what wg-quick sets on a 1500-byte link: 80 bytes go to WireGuard, UDP and IPv6 headers. On a link with a smaller MTU, go 80 below it.

Is WireGuard secure?

Its algorithms are fixed and current, and session keys change every two minutes. The weak spot is usually the file: anyone with the private key connects as that device.

What is the difference between WireGuard and AmneziaWG?

AmneziaWG keeps WireGuard's keys and encryption and changes how the packets look: random prefixes, other type values and junk packets. A plain WireGuard app can't use a file that changes them.