5xx Server errors
Last updated Jun 09, 2026

What is HTTP Status Code 502? - Bad Gateway

Benjamin Bouchet
Benjamin Bouchet
Get your free
Abstract
 API key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

The HTTP Status Code 502 means that a server was acting as a gateway or proxy and received an invalid response from the upstream server.

Understanding the “Bad Gateway” Error


Frequently Asked Questions

What does HTTP 502 Bad Gateway mean?

A 502 Bad Gateway error means a server acting as a gateway or proxy received an invalid response from an upstream server it was trying to reach. It signals a communication failure between servers, not a problem with the client’s request. The error is returned by the intermediary — such as a CDN or load balancer — not the origin server itself.

What causes a 502 Bad Gateway error?

Common causes include upstream server failures or crashes, server overload during traffic spikes, misconfigured firewalls blocking legitimate responses, and timeout issues when waiting for an upstream response. Network connectivity problems between servers in the request chain can also trigger a 502. Because requests often flow through multiple layers — CDN, load balancer, application server, external API — a breakdown at any link can produce this error.

How do I fix a 502 Bad Gateway error?

As a developer or DevOps engineer, start by checking the upstream service’s status page and reviewing application and server logs to identify where the failure occurred. Test the upstream endpoint directly using tools like curl or Postman, and audit your firewall and gateway configurations. If you are an end user, refreshing the page, clearing your browser cache, or trying a different network may resolve a transient 502.

What is the difference between a 502 and a 504 error?

Both codes originate at a gateway or proxy, but they describe different failure modes. A 502 Bad Gateway means the upstream server responded with something invalid or malformed. A 504 Gateway Timeout means the upstream server did not respond within the allowed time — so 502 points to a bad response, while 504 points to no response.

How is a 502 different from a 500 Internal Server Error?

A 500 error indicates something went wrong within the server handling your request directly. A 502 is more specific: it tells you the problem occurred at a gateway or proxy that was relaying your request to another server. The 502 code pinpoints the failure to the communication between servers rather than a general internal fault.

Is a 502 error temporary?

502 errors are often temporary, caused by short-lived conditions such as a traffic spike overloading an upstream server or a brief network disruption between servers. Retrying the request after a short wait frequently resolves the issue. Persistent 502 errors, however, indicate a deeper problem — such as a misconfigured proxy, a crashed upstream process, or a blocked network path — that requires investigation.

Get your free
API
key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required