// SIP 5xx Server failure

SIP 502 Bad Gateway

A gateway or proxy got an invalid response from the next hop.

5xx Server failure · RFC 3261 · Answer to OPTIONS: Answering, but the server behind it sent a bad response.

What SIP 502 means

A 502 comes from a server acting as a gateway or proxy. It passed the request on, and the response it got back from the next hop was invalid. The problem sits behind the server that sent the 502, so neither the request nor that server's own configuration is usually the cause.

Gateways to the phone network also use it: RFC 3398 maps Q.850 cause 27, destination out of order, to 502. That is the network saying the line or the exchange at the far end can't be reached. On a trunk, a 502 to an INVITE therefore points either at the carrier's next hop or at the called line itself.

Example response

SIP/2.0 502 Bad Gateway
Via: SIP/2.0/UDP 198.51.100.31:5060;branch=z9hG4bK-502-y4
From: <sip:+[email protected]>;tag=9d06
To: <sip:+[email protected]>;tag=bg-64
Call-ID: [email protected]
CSeq: 15 INVITE
Reason: Q.850;cause=27;text="Destination out of order"
Content-Length: 0

Common causes of SIP 502

  • The carrier's next-hop server returned a response the SBC couldn't parse or accept.
  • The called line, or the exchange serving it, is out of order, and the gateway mapped Q.850 cause 27 to 502.
  • Two systems on the path disagree about SIP extensions or headers, so one rejects what the other sends.
  • A gateway between SIP and the phone network failed while converting the call.

How to fix SIP 502

  1. Identify the server that sent the 502, then look one hop beyond it; that is where the bad response came from.
  2. Read the Reason header: cause 27 points at the called destination rather than at your trunk.
  3. Call the same destination through another route to see whether the failure follows the number or the trunk.
  4. Send the carrier a capture with the Call-ID and the time, since the faulty hop is usually inside its network.

SIP 502 as an answer to OPTIONS

A 502 to OPTIONS means the server is answering, but the server behind it sent a bad response. The SBC you probed is alive; its upstream isn't behaving. A PingVo Route counts it as reachable by default; set the Route's expected codes to 200 if it should count as a failure.

See which code your SBC returns. Run a free SIP OPTIONS check

Questions about SIP 502

What is the difference between SIP 502 and 504?

502 means the next hop answered with something invalid. 504 means the next hop didn't answer in time at all.

Is a SIP 502 my carrier's fault?

Often, but not always. It can come from the carrier's network or, with Q.850 cause 27, from the called line itself being out of order.

Related codes

Know a line is down before your callers do

Line checks, real test calls and IVR verification for your call-center numbers, with alerts that say whose side failed.

Start free trial

14 days · full Pro features · no credit card