# What does the HTTP 502 status code mean?

> HTTP 502 Bad Gateway means a server acting as a gateway or proxy received an invalid response from an inbound server, under RFC 9110.

*A 502 comes from a gateway or proxy that got a bad answer from the server behind it, and RFC 9110 keeps it apart from 504, where no timely answer arrived.*

- Type: Explainer
- Section: Tech
- By: Tech Desk
- Published: 2026-11-12T23:40:02-05:00
- Updated: 2026-11-12T23:40:02-05:00
- Checked: 2026-11-12T23:39:42-05:00
- URL: https://factsdesk.com/tech/what-does-the-http-502-status-code-mean/

## Key facts

- HTTP 502 Bad Gateway means a server acting as a gateway or proxy received an invalid response from an inbound server it accessed while trying to fulfill the request, under RFC 9110. Source: [RFC Editor (Internet Engineering Task Force)](https://www.rfc-editor.org/rfc/rfc9110.html). Confirmed 2026-11-12T23:39:12-05:00. Cite: https://factsdesk.com/tech/what-does-the-http-502-status-code-mean/#http-502-bad-gateway-means-a-server-acting-as-a-gateway-or
- RFC 9110 defines inbound as toward the origin server, and a gateway, also called a reverse proxy, as an intermediary that forwards requests inbound to another server or servers. Source: [RFC Editor (Internet Engineering Task Force)](https://www.rfc-editor.org/rfc/rfc9110.html). Confirmed 2026-11-12T23:39:12-05:00. Cite: https://factsdesk.com/tech/what-does-the-http-502-status-code-mean/#rfc-9110-defines-inbound-as-toward-the-origin-server-and-a
- RFC 9110 separates 502 from 504 Gateway Timeout, which a gateway or proxy sends when it did not receive a timely response from an upstream server. Source: [RFC Editor (Internet Engineering Task Force)](https://www.rfc-editor.org/rfc/rfc9110.html). Confirmed 2026-11-12T23:39:12-05:00. Cite: https://factsdesk.com/tech/what-does-the-http-502-status-code-mean/#rfc-9110-separates-502-from-504-gateway-timeout-which-a
- RFC 2616, published in June 1999, defined 502 as an invalid response from the upstream server that the gateway or proxy accessed. Source: [RFC Editor (Internet Engineering Task Force)](https://www.rfc-editor.org/rfc/rfc2616.html). Confirmed 2026-11-12T23:39:42-05:00. Cite: https://factsdesk.com/tech/what-does-the-http-502-status-code-mean/#rfc-2616-published-in-june-1999-defined-502-as-an-invalid
- The IANA HTTP Status Code Registry lists code 502 with the description Bad Gateway and the reference RFC 9110, Section 15.6.3. Source: [Internet Assigned Numbers Authority (IANA)](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml). Confirmed 2026-11-12T23:39:12-05:00. Cite: https://factsdesk.com/tech/what-does-the-http-502-status-code-mean/#the-iana-http-status-code-registry-lists-code-502-with-the

The HTTP 502 (Bad Gateway) status code means that a server acting as a gateway or proxy received an invalid response from an inbound server it accessed while trying to fulfill the request, according to [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html), the IETF standard that defines HTTP semantics. In the words of [Section 15.6.3 of RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-502-bad-gateway), "The 502 (Bad Gateway) status code indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request."

## Who sends a 502

[Section 3.7 of RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-intermediaries) names three common forms of intermediary: proxy, gateway and tunnel. It describes a gateway, also known as a reverse proxy, as an intermediary that acts as an origin server for the outbound connection but forwards requests inbound to another server or servers, and says gateways are often used for caching, to encapsulate legacy or untrusted services, and to partition or load balance HTTP services across multiple machines. A proxy is chosen by the client, usually through local configuration, and is often used to group an organization's requests through a common intermediary for security, annotation or shared caching.

The same section defines the direction words the 502 definition relies on: inbound means toward the origin server, and outbound means toward the user agent.

## How 502 compares with nearby codes

RFC 9110 gives each server error its own condition, and the gateway codes differ by what the intermediary got back.

| Code | Name | What RFC 9110 says it means |
| --- | --- | --- |
| 500 | Internal Server Error | An unexpected condition prevented the server from fulfilling the request |
| 502 | Bad Gateway | A gateway or proxy received an invalid response from an inbound server |
| 503 | Service Unavailable | The server cannot handle the request now because of a temporary overload or scheduled maintenance |
| 504 | Gateway Timeout | A gateway or proxy did not receive a timely response from an upstream server |

The meanings are summarized from Sections [15.6.1](https://www.rfc-editor.org/rfc/rfc9110.html#name-500-internal-server-error), [15.6.3](https://www.rfc-editor.org/rfc/rfc9110.html#name-502-bad-gateway), [15.6.4](https://www.rfc-editor.org/rfc/rfc9110.html#name-503-service-unavailable) and [15.6.5](https://www.rfc-editor.org/rfc/rfc9110.html#name-504-gateway-timeout) of RFC 9110. The practical split is between a response that arrived but was invalid (502) and a response that did not arrive in time (504). A [503](/tech/what-does-the-http-503-status-code-mean/) is the code for a server that is currently unable to handle the request due to a temporary overload or scheduled maintenance, and it may carry a Retry-After header field suggesting how long to wait; the [504](/tech/what-does-the-http-504-status-code-mean/) page covers the timeout case, and the [500](/tech/what-does-the-http-500-status-code-mean/) page covers the general server error. The [IANA registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) lists all four codes with references to these RFC 9110 sections.

## What a server should send with a 502

For every 5xx code, [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-server-error-5xx) says the server should send a representation explaining the error situation and whether it is temporary or permanent, except when responding to a HEAD request, and that a user agent should display any included representation to the user. The [list of classes](https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes) sums up 5xx as "The server failed to fulfill an apparently valid request", which separates it from client errors such as [400 Bad Request](/tech/what-does-the-http-400-status-code-mean/) and [404 Not Found](/tech/what-does-the-http-404-status-code-mean/).

## Finding which hop failed

A request can pass through several intermediaries, and [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-intermediaries) shows a chain of three between the user agent and the origin server, which means four separate connections. The [Via header field](https://www.rfc-editor.org/rfc/rfc9110.html#name-via) records that chain: each member of its value represents a proxy or gateway that has forwarded the message, in the order they forwarded it. RFC 9110 says a proxy must send Via in each message it forwards, and an HTTP-to-HTTP gateway must send it in each inbound request and may send it in forwarded responses. A sender may replace its real host with a pseudonym when the host is considered sensitive, so Via does not always name the machine.

## Retrying after a 502

The 502 definition sets no retry rule and, unlike 503, mentions no Retry-After header. The general rules on [idempotent methods in RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-idempotent-methods) still apply: PUT, DELETE and the safe methods are idempotent, so repeating them has the same intended effect. A client should not automatically retry a request with a non-idempotent method, such as POST, unless it has some way to know the request is idempotent or was never applied, a proxy must not automatically retry non-idempotent requests, and a client should not automatically retry a failed automatic retry.

## Can a 502 be cached?

Not by heuristic expiration. The [overview of status codes in RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-overview-of-status-codes) gives the heuristically cacheable codes in that specification, by way of example, as 200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414 and 501, and says all other status codes are not heuristically cacheable. That leaves 502 outside the list.

## What changed and when

The wording of 502 moved from "upstream" in RFC 2616 to "inbound" in RFC 7231.

| Specification | Published | Wording of the 502 definition |
| --- | --- | --- |
| RFC 2616, Section 10.5.3 | June 1999 | An invalid response from the upstream server it accessed in attempting to fulfill the request |
| RFC 7231, Section 6.6.3 | June 2014 | An invalid response from an inbound server it accessed while attempting to fulfill the request |
| RFC 9110, Section 15.6.3 | June 2022 | Same sentence as RFC 7231 |

[RFC 2616](https://www.rfc-editor.org/rfc/rfc2616.html#section-10.5.3), published in June 1999, described the server "while acting as a gateway or proxy" receiving an invalid response from "the upstream server". [RFC 7231](https://www.rfc-editor.org/rfc/rfc7231.html#section-6.6.3), published in June 2014, obsoleted RFC 2616 and changed the phrase to "an inbound server". [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html) was published in June 2022 on the Standards Track, carries the number STD 97 and obsoletes RFC 7231, as its header shows; the 502 definition moved to Section 15.6.3 with the RFC 7231 wording unchanged. The 504 definition in RFC 9110 still refers to "an upstream server". The [IANA registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) now points code 502 to RFC 9110, Section 15.6.3, and shows its last update as September 15, 2025.

## Sources

1. [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html), RFC Editor (Internet Engineering Task Force), 2022-06 (primary source)
2. [Hypertext Transfer Protocol (HTTP) Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml), Internet Assigned Numbers Authority (IANA), 2025-09-15 (primary source)
3. [RFC 7231: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content](https://www.rfc-editor.org/rfc/rfc7231.html), RFC Editor (Internet Engineering Task Force), 2014-06 (primary source)
4. [RFC 2616: Hypertext Transfer Protocol (HTTP/1.1)](https://www.rfc-editor.org/rfc/rfc2616.html), RFC Editor (Internet Engineering Task Force), 1999-06 (primary source)

## Asked next

- [NGINX fixes HTTP/2 flaw present since 2015 that could let attackers run code remotely](https://factsdesk.com/tech/nginx-vulnerability/): NGINX released 1.31.9 and 1.30.7 on Nov. 18, 2026, fixing CVE-2026-123007, an HTTP/2 flaw that could let attackers run code remotely.
- [What does the HTTP 500 status code mean?](https://factsdesk.com/tech/what-does-the-http-500-status-code-mean/): HTTP 500 Internal Server Error means the server encountered an unexpected condition that prevented it from fulfilling the request, under RFC 9110.
- [What does the HTTP 503 status code mean?](https://factsdesk.com/tech/what-does-the-http-503-status-code-mean/): HTTP 503 Service Unavailable means the server cannot handle the request now due to a temporary overload or scheduled maintenance, under RFC 9110.
- [What does the HTTP 504 status code mean?](https://factsdesk.com/tech/what-does-the-http-504-status-code-mean/): HTTP 504 Gateway Timeout means a server acting as a gateway or proxy did not get a timely response from an upstream server, under RFC 9110.
- [What does the HTTP 404 status code mean?](https://factsdesk.com/tech/what-does-the-http-404-status-code-mean/): HTTP 404 Not Found means the server did not find a current representation for the target resource or is not willing to disclose that one exists.
- [What does the HTTP 400 status code mean?](https://factsdesk.com/tech/what-does-the-http-400-status-code-mean/): HTTP 400 Bad Request means the server cannot or will not process a request because of something it perceives to be a client error, under RFC 9110.
