unbraid

Guides · Published · Updated on

Why your VPN keeps disconnecting on Android

When a VPN keeps dropping on Android, the cause is usually one of four things: the phone’s battery saving stops the VPN app, another VPN app takes over Android’s single VPN slot, the phone moves between Wi-Fi and mobile data, or a router or carrier forgets a connection that went quiet. Each one leaves different signs, so start by checking what you actually see when it happens.

Most of this applies to any VPN app. The last sections explain how a VPN app can tell a tunnel has died, and what unbraid does about it.

Off, or on but not working

People say “disconnected” for two different things.

  • The VPN is off. The key icon is gone from the status bar and the VPN app says it’s disconnected. Something stopped the app or replaced it.
  • The VPN is on, but nothing loads. The key icon is still there, the app says connected, and pages time out. The tunnel may have stopped carrying traffic, but DNS, a Wi-Fi sign-in page or the phone’s own connection can look exactly the same.
What you see Likely cause Where to look
VPN off after the phone sat unused for a while Battery saving closed the app The app’s battery setting, and your phone maker’s extra battery features
VPN off right after you opened another app That app may have started its own VPN Settings, VPN: which app is connected and which is Always-on
A short drop each time you leave or reach home The switch between Wi-Fi and mobile data Weak Wi-Fi at the edge of its range, automatic switching settings
On, but nothing loads after a quiet spell The tunnel’s path was forgotten, or the server stopped answering The VPN app’s keepalive and reconnect behaviour, a different server
On, but nothing loads on public Wi-Fi A sign-in page the VPN can’t get past, or DNS Android’s Wi-Fi sign-in notification, your Private DNS setting

Before changing anything, look at which VPN Android says is connected, and note whether the drops follow locking the phone or changing networks. Then try one stable Wi-Fi network and mobile data, and change one setting at a time. If websites stop opening while the VPN shows connected and you’ve set a Private DNS provider, read Private DNS and a VPN on Android.

Battery saving stops the VPN app

Android saves battery by holding back apps you aren’t using. Doze starts when the phone sits unplugged and still with the screen off: it suspends network access for apps and lets them catch up during brief maintenance windows. A connected VPN app runs as a foreground service, the kind of app that has to post a notification while it works, and Android’s power management tables list no network restriction for an app in that state. On a Pixel, a connected VPN app is usually left alone.

Check the VPN app’s own battery setting. Android lets you restrict an app’s battery use, and a restricted app loses most of its background allowance. On a Pixel, open Settings, Apps, See all apps, your VPN app, then App battery usage, and make sure Allow background usage is on (Pixel Help). Optimized is the default there and is normally fine for a VPN. Older Android versions show the choices under different names; avoid any that says Restricted.

Phone makers that close background apps

Some phone makers add battery restrictions of their own, and some of them stop apps that Android itself would let run. The site Don’t kill my app! collects these per brand, with the settings to change and screenshots. It rates stock Android on Pixel phones as the least likely to cause trouble.

Two examples from that site:

  • Samsung can put apps to sleep. Under Battery, Background usage limits, take your VPN app out of Sleeping apps and Deep sleeping apps, and add it to Never sleeping apps. Samsung can put apps back on these lists after a system update, so check again after one (details).
  • Xiaomi needs autostart allowed for the app and its battery saver set to No restrictions. Locking the app in the recent apps screen keeps it from being cleared along with the others (details).

Menu names change between versions, so search your phone’s Settings for “battery” or the app’s name if a path doesn’t match. If your VPN only drops while the phone is asleep and comes back when you pick it up, battery saving is the most likely cause.

Another VPN app took the slot

Android runs one VPN at a time. Its VPN documentation allows one active VPN service per user or profile, and starting another one stops the one that was running.

The other app isn’t always one you think of as a VPN. Security suites with a “safe browsing” feature, ad blockers, data savers, parental controls, Tailscale and work apps can all use Android’s VPN slot. If your VPN goes off when you open one of them, check Android’s VPN settings to see whether it started a VPN. If it’s Tailscale you need next to your VPN, unbraid runs both inside one VPN app: see Tailscale and a VPN at the same time. Why Android runs only one VPN at a time explains the ways to combine them.

Always-on VPN changes this. While one app is set to Always-on, Android doesn’t let another app take its place: Android’s own code refuses the switch. That protects your VPN when it’s the Always-on app. When a different app holds the setting, your VPN can’t connect at all, often without a clear message. Check under Settings, Network & internet, VPN, and tap the gear next to each app. Only one app per profile can be Always-on.

Android also starts the Always-on app when the phone boots, and from Android 8 it shows a notification you can’t swipe away while that VPN is disconnected or can’t connect. Block connections without VPN covers both settings and what they do to your apps.

Switching between Wi-Fi and mobile data

When your phone moves from Wi-Fi to mobile data, it gets a new address on the internet. The VPN server has been sending its replies to the old one, so the VPN app has to tell the server where it is now.

WireGuard handles this by design. The WireGuard paper describes how the server learns your new address from the next valid packet you send, which lets a client move between networks, mobile networks included, without a new connection. OpenVPN over TCP can’t move a connection like that: the connection breaks and the app has to connect again. Many VPN apps also restart their tunnels when Android reports a new network, which shows up as a short gap.

Repeated switches are what hurt. At the edge of a Wi-Fi network’s range, a phone can hop back and forth between Wi-Fi and mobile data, and each hop interrupts traffic; whether the VPN has to reconnect each time depends on the protocol and the app. Many phones also have a setting that moves you to mobile data when the Wi-Fi seems poor; on Samsung phones it’s Switch to mobile data under the Wi-Fi settings, Intelligent Wi-Fi. If your drops happen at the same spots, forget the weak network or turn that setting off and see whether they stop.

Quiet connections get forgotten

On most IPv4 connections your phone doesn’t have a public address of its own. The router at home, or your carrier’s equipment on mobile data, shares one public address between many devices, and that sharing is called NAT. For each connection out, the router keeps a short note of which device it belongs to, so it knows where to send the replies. For UDP, which WireGuard and most OpenVPN setups use, that note is thrown away once the connection has been quiet for a while.

The standard for this, RFC 4787, asks routers to keep these notes for at least two minutes, with exceptions for some well-known ports, and recommends five minutes or more. Real equipment is often much quicker. A 2016 study of carrier networks found that 74% of the NATs it detected dropped idle UDP state after a minute or less, with values from 10 seconds to 200 seconds. For carrier NATs the median was 65 seconds on mobile networks and 35 seconds on others. The test measured up to 200 seconds in 10 second steps, and it describes the networks measured then, not every carrier today.

WireGuard is quiet on purpose. Its quick start says it only sends when there’s something to send. If nothing goes through the tunnel for a minute, the router’s note can expire. Anything the server tries to send you after that never reaches your phone, until your phone sends something and a new note is made. So an expired note delays incoming traffic after a quiet spell. If pages stay broken while you’re actively trying to load them, the cause is something else, and a keepalive won’t fix it.

What a keepalive does

A keepalive is a small packet sent when the tunnel has been idle for a set time, so the router’s note doesn’t expire. In WireGuard it’s the PersistentKeepalive setting: an empty encrypted packet to the server after so many seconds without traffic. The WireGuard quick start calls 25 seconds “a sensible interval” that works with a wide variety of firewalls, and leaves it off by default because most setups don’t need it. A phone behind NAT that needs to receive traffic after quiet spells does.

25 seconds is below both medians from the study above. A network with a shorter timeout would need a shorter interval, but that’s rare enough that you should only try it once you’ve traced the drops to that network.

Going shorter doesn’t make a VPN more stable on a network that keeps notes longer, and it can cost battery. On mobile data, a transfer while the radio is resting wakes it, and the radio stays at full power for a few seconds afterwards. Android’s network access guide explains this “tail time” and notes that the carrier sets how long it lasts. With the 3G timings in that guide, each transfer keeps the radio drawing power for at least 18 seconds, so a packet every 15 seconds on an otherwise quiet phone would never let it rest. Several tunnels with their own timers add to that, though other traffic on the phone changes the picture.

OpenVPN has its own pair of settings, ping and ping-restart. Its manual says a client restarts after 120 seconds without hearing from the server by default. The client’s config can change that, and values the server sends override the client’s own.

A keepalive doesn’t notice a dead tunnel

A WireGuard keepalive is one way. Your phone sends it and expects nothing back, so it keeps the path open but can’t tell you whether anyone is listening. If the server has gone down, removed your key or ended your session, keepalives keep going out and the VPN app still shows connected.

WireGuard does notice a silent server when traffic goes out. Following the paper’s timers, if your phone has sent data and heard nothing back for about 15 seconds, WireGuard starts a new handshake and retries roughly every 5 seconds. It gives up after 90 seconds, though sending more data starts that window again. It does this quietly. It doesn’t tell the VPN app that something is wrong, and even a handshake that works doesn’t prove websites are reachable through the server.

So a VPN app that wants to find a dead tunnel has to check for itself, for example by sending a small request through the tunnel and waiting for the answer. That’s a liveness check, a different job from a keepalive. Checking very often can cost battery, like a short keepalive, and checking on a phone that just woke up or changed network gives false alarms. A check over the phone’s own connection, outside the tunnel, helps avoid blaming the server for a network problem.

Check the account, server and connection settings

  • Your account. An expired subscription, a password changed elsewhere, or too many devices connected at once. Providers limit simultaneous connections, and going over the limit can disconnect one of the others.
  • One server. A busy or failing server can stop answering. Connecting to another server in the same country is a quick test.
  • The protocol or port. Some networks block or slow VPN traffic on certain ports. If your app lets you choose, try another protocol or port.

If the app has a connection log, look at the entries around the time of the drop. When you contact support, give the time, the network type and any error message.

How unbraid handles a dead tunnel

While you’re connected, unbraid checks each provider tunnel on its own:

  • Every minute or so it sends a small test through each tunnel. A check that doesn’t get an answer within 8 seconds counts as failed.
  • A failed check is repeated 10 seconds later, then once more. If it still fails, unbraid checks again once a minute has passed since the first failure, to give the tunnel time to come back on the same server. Four failures in a row over that minute mark it dead; one check that works clears the count.
  • When a tunnel is dead, unbraid tries another server in the same location. This is for provider exits that can change servers: not pinned servers, imported configs, Dedicated IPs or Tailscale exits. Moving one exit can briefly reconnect the others. After a move, that route waits before it can move again: 2 minutes, then 5, 15 and 30 if the new server doesn’t work either. After that it stops moving and Routes shows Doesn’t work on this network. For providers with several WireGuard ports and Port set to Automatic, a dead tunnel also tries the next port, which helps when a network blocks one. The port choice goes back to the first one on a new network.
  • When every tunnel checked fails and a check over the phone’s own connection fails too, unbraid takes it for a network problem and counts it against no server. If that keeps happening, the regular checks slow down to about every 8 minutes. After the phone sleeps, changes network or reconnects, checks wait 30 seconds, and results from a stretch in which the phone slept are thrown away.
  • A route that can’t get a tunnel is blocked: its apps lose internet access while the other routes keep running. Local network and home access you’ve set up can still work. A failed exit never falls back to Direct while unbraid is connected. If the reason may pass, such as no network or a provider that doesn’t answer, unbraid tries again after 5 seconds, 15 seconds, 30 seconds and a minute, then every 5 minutes, and at once on a new network. A route that was signed out or refused waits until you sign in again.

An imported server with Check internet access on shows Not answering on the Routes screen once repeated checks say it can’t reach the internet, and the label goes when a check works again. When a provider route keeps failing and recovering, Settings, Providers & servers shows that it keeps dropping and that the provider may be over its connection limit. That’s one possible cause, not a diagnosis. Provider WireGuard tunnels use a 25 second keepalive. An imported WireGuard config keeps its own PersistentKeepalive value, including 0 or off, and gets 25 seconds when it has none.

If another VPN app takes over, unbraid stops and tells you that Android turned off its VPN.

Questions

Should I lower the keepalive to stop the disconnects? Usually not. 25 seconds is shorter than the timeouts most networks in the study used. Try a shorter interval only if you’ve traced the drops to one network that forgets quiet connections sooner. A keepalive still can’t tell you whether the server is answering.

Why does my VPN only disconnect at night? Most likely battery saving. A phone left still with the screen off enters Doze, and some phone makers close background apps after a while. Check the app’s battery setting and your phone maker’s page on Don’t kill my app!.

Does Always-on VPN stop the disconnects? It stops other apps from taking the VPN slot and starts your VPN when the phone boots. With Block connections without VPN on too, your apps stay offline while the VPN is down. It doesn’t fix a tunnel that’s connected but no longer carrying traffic. That’s up to the VPN app.

Bring your own VPN

unbraid is a VPN client with no servers of its own. You sign in with an account you already have, or add your own server. It has built-in support for AirVPN, ExpressVPN, IVPN, Mullvad, NordVPN (affiliate link), Private Internet Access, Proton VPN (Free included), Surfshark (affiliate link) and Windscribe. For CyberGhost, you import config files from your account, with step-by-step help in the app.

We earn a commission if you subscribe through a link marked (affiliate link). It helps keep unbraid free. If you're about to subscribe to a VPN service, thank you for considering doing it through one of them.