Matt Scott

What Cloudflare’s 5xx error codes actually mean

Cloudflare’s 521 through 526 errors all mean the same broad thing: Cloudflare reached the internet fine, but something went wrong between Cloudflare and your own server. Here is what each code means, and what actually catches each one.

Cloudflare’s 521 through 526 errors all mean the same broad thing: Cloudflare itself is working fine, but something went wrong on the way to your actual server. Which code you see tells you what, specifically, went wrong, and that difference matters, because each one needs a different fix.

If your site sits behind Cloudflare, Cloudflare is not your server. It is a layer in front of your server that forwards visitor requests along and hands back the response. When that hand-off breaks, Cloudflare shows one of these six error pages instead of your site, and the code on the page is the clue to where it broke.

What each code actually means

  • 521, web server is down: your server actively refused the connection. This usually means the server is off, a firewall is blocking Cloudflare’s connection, or the web server software crashed and stopped listening.
  • 522, connection timed out: Cloudflare tried to connect to your server but never got a response in time. The server may be overloaded, or there is a network problem between Cloudflare and your host.
  • 523, origin is unreachable: Cloudflare cannot find a route to your server at all. This is usually a DNS or IP configuration problem, the address Cloudflare has on file for your server does not lead anywhere.
  • 524, a timeout occurred: your server accepted the connection and started working, but took too long to send back a full response. A slow database query or a script stuck in a loop are common causes.
  • 525, SSL handshake failed: your server has a certificate, but Cloudflare could not complete the secure connection to it. The certificate might be missing, corrupted, or configured incorrectly on your server.
  • 526, invalid SSL certificate: Cloudflare completed the secure connection, but rejected your server’s certificate as untrustworthy, usually because it is expired, self-signed, or does not match your domain name.

Why they need different fixes

The six codes split into three groups. 521, 522, and 523 are all connection-level problems, Cloudflare could not even establish contact with your server, so the fix lives in server availability, firewall rules, or DNS. 524 is different: the connection worked, so the fix is about your application being slow, not unreachable. 525 and 526 are both certificate problems, but 525 means the handshake itself broke while 526 means the handshake worked and Cloudflare rejected what it received, so the fix for one is installing or repairing a certificate, and the fix for the other is replacing an untrusted one.

Checking your own server directly, without guessing

One thing that trips people up: a 521, 522, or 523 means Cloudflare cannot reach your server, but that does not automatically mean your server is actually broken. Sometimes the server is fine and the problem is specific to how Cloudflare is trying to reach it, a firewall rule that only blocks Cloudflare’s IP ranges, or a DNS record pointing at the wrong address after a hosting change.

The fastest way to tell the two apart is to check the server on its own, outside of Cloudflare. If you manage the hosting yourself, log in directly and confirm the web server process is actually running. If the site is on shared or managed hosting, your host can usually confirm from their side whether the server itself was reachable at the time the error happened. Either answer narrows things down fast: a server that was up the whole time points at a Cloudflare-to-server connection or DNS problem, not a server outage.

What actually catches each one before visitors do

All six of these show up as a real HTTP status code, the same 521 through 526 a visitor sees, when a monitoring tool checks your site. A basic uptime check configured to expect a normal 200 response will catch any of them the moment they happen, because an unexpected status code is treated as a confirmed failure, not something that needs a second look first.

⚠️
SSL monitoring does not diagnose 525 or 526 the way it sounds like it should. A certificate check connects to whatever certificate your domain actually presents to the outside world, which for a Cloudflare-proxied site is Cloudflare’s own certificate, not the one on your origin server. The certificate problem behind a 525 or 526 lives on the connection between Cloudflare and your server, a hop an external SSL check never sees. An uptime check catching the resulting error code is still the real safety net for these two, not certificate monitoring.

What to check first when you see one

A rough order that matches how these actually get fixed in practice:

  • Is your server actually running: log in and check that the web server process is up. This rules out 521 fastest.
  • Can your server reach the outside world: check DNS records and firewall rules for anything blocking Cloudflare’s IP ranges. This covers 522 and 523.
  • Is something slow, not down: if the server responds to a direct request but times out through Cloudflare, look at slow queries, stuck processes, or an overloaded application. This is 524.
  • Is the certificate on your server valid: check its expiry date, that it matches your domain, and that it is not self-signed if Cloudflare expects a trusted one. This covers 525 and 526.

None of these checks need to happen manually every time. An uptime monitor that captures the actual status code, rather than a plain up/down flag, turns this same order into an automatic first read: which of the six you got tells you which row on this list to start from.