Skip to content
SIP Mastery

Part 8 · Call flow library / Module 24

PSTN interworking and SIP trunks

How a PBX reaches the telephone network: SIP trunks that register or that the carrier knows by IP address; E.164 numbers, tel URIs, user=phone, and normalisation; caller ID with From, P-Asserted-Identity, and Privacy; Diversion and History-Info on forwarded calls; how a gateway maps ISUP messages and Q.850 causes to SIP, with the Reason header; and early media from the PSTN.

AdvancedNOC coreDEV core

After this module, you can

  • Compare a registration-based and an IP-based SIP trunk, and say how the carrier knows the PBX in each.
  • Turn a dialled number into E.164, and write it as a tel URI and as a SIP URI with user=phone.
  • Explain how From, P-Asserted-Identity, and Privacy decide the number that the called phone shows.
  • Read Diversion and History-Info on a forwarded call, and say why a carrier or a voicemail server needs them.
  • Map the ISUP messages IAM, ACM, ANM, and REL to SIP, and a Q.850 cause to a SIP response with a Reason header.
  • Tell ringback or an announcement in a 183 from a local ringback tone after a 180.
On this page8 sections
  1. 24.1SIP trunks: registration-based and IP-based
  2. 24.2Numbers: E.164, tel URIs, user=phone, normalisation
  3. 24.3Caller ID: From, PAI, and Privacy; withheld numbers
  4. 24.4Diversion and History-Info for forwarded calls
  5. 24.5Q.850 causes and SIP codes; the Reason header
  6. 24.6Early media from the PSTN: ringback and announcements in 183
  7. Common mistakes
  8. Summary

24.1 SIP trunks: registration-based and IP-based

A SIP trunkSIP trunk. A SIP connection between an organisation's PBX and a carrier, in place of physical phone lines. connects a company’s PBXPBX. The phone system of an organisation. Modern PBXs use SIP. to a carrier, in place of physical phone lines. The carrier gives the company a block of numbers (DIDsDID. A telephone number from the carrier that reaches one user or extension behind a PBX directly.), takes its outgoing calls to the PSTNPSTN. The traditional telephone network, built on circuits between telephone exchanges., and sends it the incoming ones. Every trunk must answer one question: how does the carrier know that a request comes from this customer, and where to send calls for its numbers? There are two common answers.

Registration-based trunk IP-based trunk
The PBX’s address Can change; the PBX tells the carrier with REGISTER Fixed, and written in the carrier’s configuration
Authentication Digest: 401 to REGISTER, often 407 to every INVITE The source IP address, often with TLS and certificates
Is the PBX alive? The registration expires if the PBX stops refreshing The carrier sends OPTIONS and stops calls if no answer comes
Typical use Small offices, PBXs behind NAT, cloud PBXs Larger sites and data centres, with a fixed address

The PBX in this module, in Atlanta, uses the carrier’s Carrier SBCCarrier SBC. The SBC at the edge of a carrier's network. It ends its customers' SIP trunks, checks who is calling, and passes calls to the carrier's gateways., a B2BUA at the edge of the carrier’s network. Behind it, a Carrier gatewayCarrier gateway. The gateway between SIP and the public telephone network. converts SIP to ISUP, the signaling of the telephone exchanges. Switch Trunk between the two types. Every option in this builder changes the messages, so try each one as you read this module:

Flow builder · a call to the PSTN on a SIP trunk

A call to the PSTN on a registered trunk: Bob answers

  • SIP
  • RTP media
  • TCP / IP
Trunk
Number sent
Caller ID
Forwarded call
The PSTN
What if

PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.80PSTNBob's mobile01REGISTER02401 Unauthorized03REGISTER (credentials)04200 OK05INVITE06407 Proxy Authentication Required07ACK08INVITE (credentials)09100 Trying10INVITE11100 Trying12ISUP IAM13ISUP ACM14183 Session Progress15183 Session Progress16RTP (ringback tone)17ISUP ANM18200 OK19200 OK20ACK21ACK22RTP23ISUP REL (cause 16)24BYE25200 OK26BYE27200 OK
01/27

The PBX registers the trunk's main number, like a phone. The carrier then sends calls for the whole number block there.

All steps as text
  1. PBX → Carrier SBC: REGISTER. The PBX registers the trunk's main number, like a phone. The carrier then sends calls for the whole number block there.
  2. Carrier SBC → PBX: 401 Unauthorized. The carrier asks for the trunk's username and password.
  3. PBX → Carrier SBC: REGISTER (credentials). The PBX sends the REGISTER again, with Authorization.
  4. Carrier SBC → PBX: 200 OK. The carrier stores the binding for an hour. The PBX refreshes it before then.
  5. PBX → Carrier SBC: INVITE. The PBX sends the number in E.164 format: + and the country code. Any carrier can route it.
  6. Carrier SBC → PBX: 407 Proxy Authentication Required. The carrier challenges every INVITE on a registered trunk. This stops anyone else from calling on its account.
  7. PBX → Carrier SBC: ACK. The PBX acknowledges the 407 on the same hop.
  8. PBX → Carrier SBC: INVITE (credentials). The PBX sends the INVITE again, with Proxy-Authorization and the next CSeq.
  9. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  10. Carrier SBC → Carrier gateway: INVITE. The SBC checks that the caller's number belongs to this trunk. It relays the media through its own address.
  11. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  12. Carrier gateway → PSTN: ISUP IAM. The gateway starts the PSTN call. It removes +1, because the country code is local to it.
  13. PSTN → Carrier gateway: ISUP ACM. Bob's mobile rings. The ACM says that the exchange plays the ringback tone in-band.
  14. Carrier gateway → Carrier SBC: 183 Session Progress. The gateway sends 183 with an SDP answer, and connects the in-band audio.
  15. Carrier SBC → PBX: 183 Session Progress. The SBC passes the 183 on, with its own SDP. The PBX must play the media, not a local tone.
  16. Carrier gateway → PBX: RTP (ringback tone). Alice hears the ringback tone from the far exchange, through the gateway and the SBC.
  17. PSTN → Carrier gateway: ISUP ANM. Bob answers. The ANM starts the charge for the call.
  18. Carrier gateway → Carrier SBC: 200 OK. The gateway maps the ANM to 200 OK.
  19. Carrier SBC → PBX: 200 OK. The SBC answers the PBX on its own dialog.
  20. PBX → Carrier SBC: ACK. The PBX acknowledges the 200 OK.
  21. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the 200 OK on its own dialog.
  22. PBX → Carrier gateway: RTP. The call audio flows in both directions, through the SBC.
  23. PSTN → Carrier gateway: ISUP REL (cause 16). Bob hangs up. The exchange releases the call with cause 16, normal call clearing.
  24. Carrier gateway → Carrier SBC: BYE. The gateway ends the SIP call. The Reason header carries the Q.850 cause.
  25. Carrier SBC → Carrier gateway: 200 OK. The SBC confirms the BYE.
  26. Carrier SBC → PBX: BYE. The SBC ends its dialog with the PBX, and copies the Reason.
  27. PBX → Carrier SBC: 200 OK. The PBX confirms. Its call record shows cause 16: Bob hung up.

A registration-based trunk registers one number, often the main number of the company, and the carrier routes the whole number block to that binding. RFC 6140 defines a standard REGISTER for a block of numbers, but most carriers use their own conventions. Read your carrier’s trunk guide.

RFC 6140 §1 · Introduction
“For purposes of efficiency, many of these deployments do not wish to maintain separate registrations for each of the AORs in the block.”
Read the section ↗

24.2 Numbers: E.164, tel URIs, user=phone, normalisation

Users dial numbers in many ways: 9 for an outside line, seven digits for a local call, 011 for an international one. A carrier cannot guess what each PBX means, so trunks almost always carry numbers in E.164E.164. The ITU-T plan for international telephone numbers: a country code and a national number, at most 15 digits. Written with a leading +, as in +14045550199. format: +, the country code, and the national number, with no prefixes.

RFC 3966 §5.1.4 · Global Numbers
“Globally unique numbers are identified by the leading "+" character.”
Read the section ↗

The PBX therefore does number normalisationnumber normalisation. Changing a number from the format a user dialled, or a network uses, into another format, usually E.164.: it removes the outside-line prefix, replaces an international prefix with +, and adds the country code and area code where they are missing. Try some numbers, in two different countries:

Number normaliser

From what the user dialled to what the trunk carries

Outside line 9 · international prefix 011 · country code +1 · area code 404

Local number

  1. Remove spaces, dashes, dots, and brackets 95550199
  2. Remove the outside-line prefix 9 5550199
  3. Add +1 and the PBX's area code, 404 +14045550199
E.164
+14045550199
tel URI
tel:+14045550199
Request-URI
sip:+14045550199@sip.carrier.example;user=phone
Unnormalised
tel:5550199;phone-context=+1-404
ISUP, at a gateway in this country
4045550199 (national number)

A local number in a URI must say where it is valid, with phone-context. Most carriers accept only E.164, so the PBX adds the country and area code.

A number can travel in two kinds of URI. A tel URItel URI. A URI that holds a telephone number, such as tel:+12025550123., tel:+14045550199, is only a number. A SIP URI with user=phone, sip:+14045550199@sip.carrier.example;user=phone, says that the user part is a telephone number, and also names the host that routes it. Trunks usually use the second form. A local number in either form must say where it is valid:

RFC 3261 §19.1.1 · SIP and SIPS URI Components
“If the user string contains a telephone number formatted as a telephone-subscriber, the user parameter value "phone" SHOULD be present.”
Read the section ↗
RFC 3966 §5.1.5 · Local Numbers
“Local numbers MUST have a 'phone-context' parameter that identifies the scope of their validity.”
Read the section ↗

At the gateway, the number goes into the ISUP IAMIAM. The ISUP message that starts a call. It carries the called and calling numbers. A gateway sends it when it receives an INVITE.. If the country code is the gateway’s own, it becomes a national number:

RFC 3398 §12.2 · tel URL to ISUP format mapping
“If the country code is local to the gateway (the gateway has one or more trunks that point to switches which are homed to the country code in question), the gateway SHOULD set the NoA to reflect 'national (significant) number' and strip the country code from the URI before populating the digits field.”
Read the section ↗

A number that is not in international format may not work at all. Set Number sent to Local in the builder:

Flow builder · seven digits, with no area code

A call to the PSTN on an IP-based trunk: the number is incomplete

  • SIP
Trunk
Number sent
Caller ID
Forwarded call
The PSTN
What if

PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.8001OPTIONS02200 OK03INVITE04100 Trying05INVITE06100 Trying07484 Address Incomplete08ACK09484 Address Incomplete10ACK
01/10

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. The PBX sends seven digits, as the user dialled them. Without an area code, the number is incomplete.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. The SBC cannot know which area code the PBX means. It passes the seven digits on.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → Carrier SBC: 484 Address Incomplete. The number has no + and no area code, so the gateway cannot build an ISUP number from it.
  8. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the failure on its hop.
  9. Carrier SBC → PBX: 484 Address Incomplete. The SBC passes the 484 back, with the Reason. The PBX must send the number in a format that the carrier accepts.
  10. PBX → Carrier SBC: ACK. The PBX acknowledges it, and shows the user the right message.
RFC 3398 §12.2 · tel URL to ISUP format mapping
“If the URI is not in international format, the gateway MAY attempt to treat the telephone number within the URI as if it were appropriate to its national or network-specific dialing plan; if doing so gives rise to internal gateway errors or the gateway does not support such procedures, then the gateway SHOULD respond with appropriate SIP status codes to express that the URI could not be understood (if the URI in question is the Request-URI, a 484).”
Read the section ↗

24.3 Caller ID: From, PAI, and Privacy; withheld numbers

Module 7 introduced the three headers, and Module 14 the trust domain. On a trunk, they decide the number on the called phone:

  • From is what the PBX writes. Carriers do not trust it for the caller’s number.
  • P-Asserted-Identity (PAI) is the identity that the carrier checks. The carrier SBC accepts it only if the number belongs to this trunk, or if the call shows why it does not (24.4).
  • Privacy: id asks the network to keep that identity from the called party. At the gateway, it becomes the ISUP presentation restrictionpresentation restriction. A request that the called phone does not show the caller's number. The network still knows the number. flag.
The PBX sends The SBC passes on The ISUP IAM Bob’s mobile shows
From and PAI with Alice’s number PAI Presentation allowed +1 404 555 0101
Anonymous From, PAI, Privacy: id PAI and Privacy: id Presentation restricted “Withheld”
Anonymous From and PAI, no Privacy PAI Presentation allowed +1 404 555 0101

Flow builder · a withheld number

A call to the PSTN on an IP-based trunk: Bob answers

  • SIP
  • RTP media
  • TCP / IP
Trunk
Number sent
Caller ID
Forwarded call
The PSTN
What if

PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.80PSTNBob's mobile01OPTIONS02200 OK03INVITE04100 Trying05INVITE06100 Trying07ISUP IAM08ISUP ACM09183 Session Progress10183 Session Progress11RTP (ringback tone)12ISUP ANM13200 OK14200 OK15ACK16ACK17RTP18ISUP REL (cause 16)19BYE20200 OK21BYE22200 OK
01/22

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. Alice withholds her number: an anonymous From, P-Asserted-Identity, and Privacy: id.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. The SBC checks that the caller's number belongs to this trunk. It relays the media through its own address.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → PSTN: ISUP IAM. The gateway starts the PSTN call. Privacy: id becomes "presentation restricted", so the mobile shows no number.
  8. PSTN → Carrier gateway: ISUP ACM. Bob's mobile rings. The ACM says that the exchange plays the ringback tone in-band.
  9. Carrier gateway → Carrier SBC: 183 Session Progress. The gateway sends 183 with an SDP answer, and connects the in-band audio.
  10. Carrier SBC → PBX: 183 Session Progress. The SBC passes the 183 on, with its own SDP. The PBX must play the media, not a local tone.
  11. Carrier gateway → PBX: RTP (ringback tone). Alice hears the ringback tone from the far exchange, through the gateway and the SBC.
  12. PSTN → Carrier gateway: ISUP ANM. Bob answers. The ANM starts the charge for the call.
  13. Carrier gateway → Carrier SBC: 200 OK. The gateway maps the ANM to 200 OK.
  14. Carrier SBC → PBX: 200 OK. The SBC answers the PBX on its own dialog.
  15. PBX → Carrier SBC: ACK. The PBX acknowledges the 200 OK.
  16. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the 200 OK on its own dialog.
  17. PBX → Carrier gateway: RTP. The call audio flows in both directions, through the SBC.
  18. PSTN → Carrier gateway: ISUP REL (cause 16). Bob hangs up. The exchange releases the call with cause 16, normal call clearing.
  19. Carrier gateway → Carrier SBC: BYE. The gateway ends the SIP call. The Reason header carries the Q.850 cause.
  20. Carrier SBC → Carrier gateway: 200 OK. The SBC confirms the BYE.
  21. Carrier SBC → PBX: BYE. The SBC ends its dialog with the PBX, and copies the Reason.
  22. PBX → Carrier SBC: 200 OK. The PBX confirms. Its call record shows cause 16: Bob hung up.
RFC 3398 §5.7 · Privacy Protection
“ISUP has a concept of presentation restriction - a mechanism by which a user can specify that they would not like their telephone number to be displayed to the person they are calling (presumably someone with Caller ID).”
Read the section ↗
RFC 3325 §9.3 · The "id" Privacy Type
“The presence of this privacy type in a Privacy header field indicates that the user would like the Network Asserted Identity to be kept private with respect to SIP entities outside the Trust Domain with which the user authenticated.”
Read the section ↗

A withheld number is hidden only from the called party. The carrier still has it in the IAM, for emergency services, for complaints about nuisance calls, and for its own records.

24.4 Diversion and History-Info for forwarded calls

Carol calls Alice’s DID from the PSTN, and Alice has forwarded her calls to her mobile. The PBX makes a new call on the trunk, from Carol’s number to the mobile. To the carrier, this looks like a PBX that uses a number it does not own. The forwarding history explains it:

Diversion: <sip:+14045550101@sip.carrier.example;user=phone>;reason=unconditional;counter=1

History-Info: <sip:+14045550101@pbx.atlanta.example;user=phone?Reason=SIP%3Bcause%3D302>;index=1
History-Info: <sip:+14045550199@sip.carrier.example;user=phone>;index=1.1;mp=1

Both say the same thing: the call was for +1 404 555 0101, and that number forwarded it unconditionally. In History-Info, cause=302 is the reason, and mp=1 says that the new target is a different user, “mapped from” entry 1. Set Forwarded call in the builder, and compare With no history:

Flow builder · a forwarded call, with Diversion

A call to the PSTN on an IP-based trunk: Bob answers

  • SIP
  • RTP media
  • TCP / IP
Trunk
Number sent
Caller ID
Forwarded call
The PSTN
What if

PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.80PSTNBob's mobile01OPTIONS02200 OK03INVITE04100 Trying05INVITE06100 Trying07ISUP IAM08ISUP ACM09183 Session Progress10183 Session Progress11RTP (ringback tone)12ISUP ANM13200 OK14200 OK15ACK16ACK17RTP18ISUP REL (cause 16)19BYE20200 OK21BYE22200 OK
01/22

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. From and P-Asserted-Identity give Carol's number: Alice forwards the call, so Carol is the caller.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. Carol's number is not one of the trunk's numbers. Diversion shows that Alice's number forwarded the call, so the SBC accepts it.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → PSTN: ISUP IAM. The gateway starts the PSTN call. Alice's number goes in the original called number.
  8. PSTN → Carrier gateway: ISUP ACM. Bob's mobile rings. The ACM says that the exchange plays the ringback tone in-band.
  9. Carrier gateway → Carrier SBC: 183 Session Progress. The gateway sends 183 with an SDP answer, and connects the in-band audio.
  10. Carrier SBC → PBX: 183 Session Progress. The SBC passes the 183 on, with its own SDP. The PBX must play the media, not a local tone.
  11. Carrier gateway → PBX: RTP (ringback tone). Carol hears the ringback tone from the far exchange, through the gateway and the SBC.
  12. PSTN → Carrier gateway: ISUP ANM. Bob answers. The ANM starts the charge for the call.
  13. Carrier gateway → Carrier SBC: 200 OK. The gateway maps the ANM to 200 OK.
  14. Carrier SBC → PBX: 200 OK. The SBC answers the PBX on its own dialog.
  15. PBX → Carrier SBC: ACK. The PBX acknowledges the 200 OK.
  16. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the 200 OK on its own dialog.
  17. PBX → Carrier gateway: RTP. The call audio flows in both directions, through the SBC.
  18. PSTN → Carrier gateway: ISUP REL (cause 16). Bob hangs up. The exchange releases the call with cause 16, normal call clearing.
  19. Carrier gateway → Carrier SBC: BYE. The gateway ends the SIP call. The Reason header carries the Q.850 cause.
  20. Carrier SBC → Carrier gateway: 200 OK. The SBC confirms the BYE.
  21. Carrier SBC → PBX: BYE. The SBC ends its dialog with the PBX, and copies the Reason.
  22. PBX → Carrier SBC: 200 OK. The PBX confirms. Its call record shows cause 16: Bob hung up.
RFC 5806 §3 · Diversion Indication, Overview
“Question 1: From whom was the request diverted? Question 2: Why was the request diverted?”
Read the section ↗
RFC 7044 §1 · History-Info, Introduction
“This request history information allows the receiving application to obtain information about how and why the SIP request arrived at the application/user.”
Read the section ↗

The gateway copies the history into the IAM as the original called number and the redirection information. A voicemail system in the PSTN or behind the PBX uses the same history for the same purpose: to find the right mailbox. Many carriers accept only one of the two headers; the trunk guide says which.

24.5 Q.850 causes and SIP codes; the Reason header

The gateway translates between two signaling protocols, message by message (RFC 3398):

ISUP message Meaning SIP
IAMIAM. The ISUP message that starts a call. It carries the called and calling numbers. A gateway sends it when it receives an INVITE. Set up a call to this number INVITE
ACMACM. The ISUP message that says the exchange has the whole number and the phone is ringing. A gateway turns it into 180 or 183. The number is complete; the phone rings 180 Ringing, or 183 with SDP for in-band tones
ANMANM. The ISUP message that says the called phone answered. Charging starts here. A gateway turns it into 200 OK. The phone answered; charging starts 200 OK
RELREL. The ISUP message that ends or rejects a call. It carries a Q.850 cause., with a cause End or reject the call BYE, CANCEL, or a 4xx–6xx response
RFC 3398 §7.2.4.1 · ISDN Cause Code to Status Code Mapping
“An REL can be sent to tear down a call that is already in progress (BYE), to cancel a previously sent call setup request that has not yet been completed (CANCEL), or to reject a call setup request (IAM) that has just been received (corresponding to a SIP status code).”
Read the section ↗

Every REL carries a Q.850Q.850. The ITU-T list of cause values that telephone networks use to say why a call ended, such as 16 (normal clearing) or 17 (user busy). cause. The gateway maps it to a SIP response, and also copies it into a Reason header, so the SIP side keeps the exact cause:

RFC 6432 §3 · Applicability
“Any SIP Response message, with the exception of a 100 (Trying), MAY contain a Reason header field with a Q.850 [Q.850] cause code.”
Read the section ↗
SIP/2.0 486 Busy Here
Reason: Q.850;cause=17;text="User busy"

Change The PSTN in the builder to see each cause:

Flow builder · the mobile is busy

A call to the PSTN on an IP-based trunk: Bob is busy

  • SIP
  • TCP / IP
Trunk
Number sent
Caller ID
Forwarded call
The PSTN
What if

PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.80PSTNBob's mobile01OPTIONS02200 OK03INVITE04100 Trying05INVITE06100 Trying07ISUP IAM08ISUP REL (cause 17)09486 Busy Here10ACK11486 Busy Here12ACK
01/12

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. The PBX sends the number in E.164 format: + and the country code. Any carrier can route it.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. The SBC checks that the caller's number belongs to this trunk. It relays the media through its own address.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → PSTN: ISUP IAM. The gateway starts the PSTN call. It removes +1, because the country code is local to it.
  8. PSTN → Carrier gateway: ISUP REL (cause 17). Bob's mobile is on another call. The exchange releases the call with cause 17.
  9. Carrier gateway → Carrier SBC: 486 Busy Here. The gateway maps cause 17 to 486, and adds the cause in a Reason header.
  10. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the failure on its hop.
  11. Carrier SBC → PBX: 486 Busy Here. The SBC passes the 486 and its Reason to the PBX.
  12. PBX → Carrier SBC: ACK. The PBX acknowledges it, and shows the user the right message.
Q.850 cause (REL) → SIP response SIP response → Q.850 cause (REL)
1 Unallocated number 404 404 Not Found 1
17 User busy 486 486 Busy Here 17
19 No answer from user 480 480 Temporarily Unavailable 18 No user responding
28 Invalid number format 484 484 Address Incomplete 28
34 No circuit available 503 503 Service Unavailable 41 Temporary failure
16 Normal call clearing BYE (not a response) BYE 16

The mapping is not the same in both directions. A cause that passes through two gateways can therefore change, and many networks change the defaults. When the cause matters, as for billing records or for announcements, read the Reason header, not only the status code. Module 6 has the longer table.

24.6 Early media from the PSTN: ringback and announcements in 183

On a SIP call between two phones, the caller’s phone makes its own ringback tone when a 180 arrives. On a call to the PSTN, the far exchange often plays the tones, or an announcement such as “The number you have called is not in service”. The ACM says so, and the gateway sends 183 Session Progress with SDP, then sends that audio as early mediaearly media. Audio sent before the call is answered, such as a ringback tone or an announcement from the far network.:

RFC 3398 §7.2.6 · ACM received
“After early media transmission has been initiated, the gateway SHOULD send a 183 Session Progress response code.”
Read the section ↗
RFC 3398 §5.5 · Early Media
“For telephony, establishment of media in the backwards direction is desirable so that tones and announcements can be played, especially when interworking with a network that cannot signal call status out of band (such as a legacy MF network).”
Read the section ↗

Flow builder · an announcement before the 404

A call to the PSTN on an IP-based trunk: the number is not in service

  • SIP
  • RTP media
  • TCP / IP
Trunk
Number sent
Caller ID
Forwarded call
The PSTN
What if

PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.80PSTNBob's mobile01OPTIONS02200 OK03INVITE04100 Trying05INVITE06100 Trying07ISUP IAM08ISUP ACM09183 Session Progress10183 Session Progress11RTP (announcement)12ISUP REL (cause 1)13404 Not Found14ACK15404 Not Found16ACK
01/16

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. The PBX sends the number in E.164 format: + and the country code. Any carrier can route it.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. The SBC checks that the caller's number belongs to this trunk. It relays the media through its own address.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → PSTN: ISUP IAM. The gateway starts the PSTN call. It removes +1, because the country code is local to it.
  8. PSTN → Carrier gateway: ISUP ACM. The exchange has an announcement for this number. The ACM says to listen in-band.
  9. Carrier gateway → Carrier SBC: 183 Session Progress. The gateway sends 183 with an SDP answer, and connects the in-band audio.
  10. Carrier SBC → PBX: 183 Session Progress. The SBC passes the 183 on, with its own SDP. The PBX must play the media, not a local tone.
  11. Carrier gateway → PBX: RTP (announcement). Alice hears the exchange's announcement: "The number you have called is not in service."
  12. PSTN → Carrier gateway: ISUP REL (cause 1). After the announcement, the exchange releases the call with cause 1.
  13. Carrier gateway → Carrier SBC: 404 Not Found. The gateway maps cause 1 to 404, with the cause in a Reason header.
  14. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the failure on its hop.
  15. Carrier SBC → PBX: 404 Not Found. The SBC passes the 404 on. Alice has already heard why the call failed.
  16. PBX → Carrier SBC: ACK. The PBX acknowledges it, and shows the user the right message.

If the ACM says only that the phone rings, with no in-band information, the gateway sends 180 with no SDP, and the PBX makes the ringback tone itself. Turn off In-band tones to compare.

RFC 3398 §7.2.6 · ACM received
“If the ACM contains a Backward Call Indicators parameter with a value of 'subscriber free', the gateway SHOULD send a '180 Ringing' response.”
Read the section ↗

Early media is free for the caller: the exchanges start charging at the ANM. Some networks limit how long early media can last for this reason, and some phones abuse it to talk before the answer.

RFC 3398 §7.2.6 · ACM received
“In common ISUP network practice, billing commences when the ANM is received.”
Read the section ↗

Three practical points:

  • A PBX that plays its own ringback tone on 183 hides the announcement from the caller. Module 21 shows this mistake.
  • Many gateways send the 183 reliably, with Require: 100rel, and expect a PRACK (Module 22). A PBX that does not support 100rel may get no early media at all.
  • In IMS networks, the P-Early-Media header (RFC 5009) says whether the network allows early media to flow on this call.

Common mistakes

A number in the wrong format for the carrier

A PBX sends numbers on the trunk as its users dial them. National numbers work, because this carrier adds +1. Local seven-digit numbers fail with 484, and an international call fails as soon as the PBX moves to a carrier in another country.

Broken: seven digits, as dialled

A call to the PSTN on an IP-based trunk: the number is incomplete

  • SIP
PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.8001OPTIONS02200 OK03INVITE04100 Trying05INVITE06100 Trying07484 Address Incomplete08ACK09484 Address Incomplete10ACK
01/10

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. The PBX sends seven digits, as the user dialled them. Without an area code, the number is incomplete.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. The SBC cannot know which area code the PBX means. It passes the seven digits on.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → Carrier SBC: 484 Address Incomplete. The number has no + and no area code, so the gateway cannot build an ISUP number from it.
  8. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the failure on its hop.
  9. Carrier SBC → PBX: 484 Address Incomplete. The SBC passes the 484 back, with the Reason. The PBX must send the number in a format that the carrier accepts.
  10. PBX → Carrier SBC: ACK. The PBX acknowledges it, and shows the user the right message.

Remember: normalise every number to E.164 in the PBX, before the trunk. Use the format the carrier’s trunk guide asks for, and test local, national, international, and emergency calls.

The original called number is lost on a forwarded call

Calls to Alice that she does not answer go to a voicemail server. The PBX makes the new INVITE with Carol’s number in From, but adds no Diversion or History-Info. The voicemail server cannot tell whose mailbox to open, plays its main menu, and Carol hangs up.

Problem: no history

Forwarded to voicemail, with no history

  • SIP
  • RTP media
  • ⚠Problem
Carrier SBC198.51.100.50PBX192.0.2.20Alice192.0.2.10Voicemail server192.0.2.4001INVITE02100 Trying03INVITE04180 Ringing05180 Ringing06CANCEL07200 OK (CANCEL)08487 Request Terminated09ACK10INVITE⚠11200 OK12ACK13200 OK14ACK15RTP (main menu)⚠
01/15

Carol calls Alice's direct number from the PSTN. The carrier sends the call down the trunk.

All steps as text
  1. Carrier SBC → PBX: INVITE. Carol calls Alice's direct number from the PSTN. The carrier sends the call down the trunk.
  2. PBX → Carrier SBC: 100 Trying. The PBX looks up the extension for this DID: Alice.
  3. PBX → Alice: INVITE. The PBX calls Alice's desk phone on its own dialog.
  4. Alice → PBX: 180 Ringing. Alice's phone rings, but she is not at her desk.
  5. PBX → Carrier SBC: 180 Ringing. The PBX passes the ringing on to Carol.
  6. PBX → Alice: CANCEL. After 20 seconds with no answer, the PBX stops ringing Alice's phone.
  7. Alice → PBX: 200 OK (CANCEL). Alice's phone accepts the CANCEL.
  8. Alice → PBX: 487 Request Terminated. Alice's phone ends the INVITE transaction.
  9. PBX → Alice: ACK. The PBX acknowledges the 487.
  10. PBX → Voicemail server: INVITE. The PBX forwards the call to voicemail. The INVITE gives only Carol's number, and nothing about Alice. Problem: The voicemail server cannot tell whose mailbox this call is for.
  11. Voicemail server → PBX: 200 OK. The voicemail server answers. It does not know which mailbox to open.
  12. PBX → Voicemail server: ACK. The PBX acknowledges the 200 OK.
  13. PBX → Carrier SBC: 200 OK. The PBX answers Carol's call, with its own SDP.
  14. Carrier SBC → PBX: ACK. The carrier acknowledges the 200 OK.
  15. Voicemail server → Carrier SBC: RTP (main menu). Carol hears "Please enter the mailbox number". She does not know it, and hangs up. Problem: Carol leaves no message, and Alice never learns that she called.

Remember: every element that forwards a call adds Diversion or History-Info, and every B2BUA in the path passes them on. Check which header the voicemail server and the carrier read.

Forwarding a call with the caller's number and no history

The same PBX forwards a call from Carol to Alice’s mobile, with Carol’s number in P-Asserted-Identity and no Diversion. The carrier sees a number that does not belong to the trunk and replaces it with the company’s main number, or rejects the call. Alice’s mobile never shows who is calling.

Broken: no history

A call to the PSTN on an IP-based trunk: Bob answers

  • SIP
  • RTP media
  • TCP / IP
  • ⚠Problem
PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.80PSTNBob's mobile01OPTIONS02200 OK03INVITE04100 Trying05INVITE⚠06100 Trying07ISUP IAM08ISUP ACM09183 Session Progress10183 Session Progress11RTP (ringback tone)12ISUP ANM13200 OK14200 OK15ACK16ACK17RTP18ISUP REL (cause 16)19BYE20200 OK21BYE22200 OK
01/22

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. From and P-Asserted-Identity give Carol's number: Alice forwards the call, so Carol is the caller.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. Carol's number is not one of the trunk's numbers, and nothing shows a forwarded call. The SBC replaces it with the trunk's main number. Problem: The PSTN now gets the company's main number, not Carol's. Bob cannot tell who is calling.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → PSTN: ISUP IAM. The gateway starts the PSTN call. It removes +1, because the country code is local to it.
  8. PSTN → Carrier gateway: ISUP ACM. Bob's mobile rings. The ACM says that the exchange plays the ringback tone in-band.
  9. Carrier gateway → Carrier SBC: 183 Session Progress. The gateway sends 183 with an SDP answer, and connects the in-band audio.
  10. Carrier SBC → PBX: 183 Session Progress. The SBC passes the 183 on, with its own SDP. The PBX must play the media, not a local tone.
  11. Carrier gateway → PBX: RTP (ringback tone). Carol hears the ringback tone from the far exchange, through the gateway and the SBC.
  12. PSTN → Carrier gateway: ISUP ANM. Bob answers. The ANM starts the charge for the call.
  13. Carrier gateway → Carrier SBC: 200 OK. The gateway maps the ANM to 200 OK.
  14. Carrier SBC → PBX: 200 OK. The SBC answers the PBX on its own dialog.
  15. PBX → Carrier SBC: ACK. The PBX acknowledges the 200 OK.
  16. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the 200 OK on its own dialog.
  17. PBX → Carrier gateway: RTP. The call audio flows in both directions, through the SBC.
  18. PSTN → Carrier gateway: ISUP REL (cause 16). Bob hangs up. The exchange releases the call with cause 16, normal call clearing.
  19. Carrier gateway → Carrier SBC: BYE. The gateway ends the SIP call. The Reason header carries the Q.850 cause.
  20. Carrier SBC → Carrier gateway: 200 OK. The SBC confirms the BYE.
  21. Carrier SBC → PBX: BYE. The SBC ends its dialog with the PBX, and copies the Reason.
  22. PBX → Carrier SBC: 200 OK. The PBX confirms. Its call record shows cause 16: Bob hung up.

Remember: a forwarded call keeps the original caller’s number only if the INVITE shows which of the trunk’s numbers forwarded it.

Withholding the number in From only

A user asks for their number to be withheld. The PBX writes an anonymous From, but still sends P-Asserted-Identity, and no Privacy header. The network treats the asserted identity as public, and the called phone shows the number.

Broken: anonymous From only

A call to the PSTN on an IP-based trunk: Bob answers

  • SIP
  • RTP media
  • TCP / IP
  • ⚠Problem
PBX192.0.2.20Carrier SBC198.51.100.50Carrier gateway198.51.100.80PSTNBob's mobile01OPTIONS02200 OK03INVITE⚠04100 Trying05INVITE06100 Trying07ISUP IAM⚠08ISUP ACM09183 Session Progress10183 Session Progress11RTP (ringback tone)12ISUP ANM13200 OK14200 OK15ACK16ACK17RTP18ISUP REL (cause 16)19BYE20200 OK21BYE22200 OK
01/22

The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.

All steps as text
  1. Carrier SBC → PBX: OPTIONS. The carrier knows the PBX by its fixed address, 192.0.2.20: no REGISTER, no password. It checks the PBX with OPTIONS.
  2. PBX → Carrier SBC: 200 OK. The PBX is up. The carrier sends calls only to a PBX that answers its OPTIONS.
  3. PBX → Carrier SBC: INVITE. Alice withholds her number, but the PBX only makes From anonymous. It sends no Privacy header. Problem: Without Privacy: id, the network treats the identity in P-Asserted-Identity as public.
  4. Carrier SBC → PBX: 100 Trying. The SBC accepts the INVITE and starts its own call to the gateway.
  5. Carrier SBC → Carrier gateway: INVITE. The SBC checks that the caller's number belongs to this trunk. It relays the media through its own address.
  6. Carrier gateway → Carrier SBC: 100 Trying. The gateway takes the call.
  7. Carrier gateway → PSTN: ISUP IAM. The gateway starts the PSTN call. With no Privacy header, the number goes out as "presentation allowed". Problem: Alice wanted her number withheld, but the PSTN now treats it as public.
  8. PSTN → Carrier gateway: ISUP ACM. Bob's mobile rings. The ACM says that the exchange plays the ringback tone in-band.
  9. Carrier gateway → Carrier SBC: 183 Session Progress. The gateway sends 183 with an SDP answer, and connects the in-band audio.
  10. Carrier SBC → PBX: 183 Session Progress. The SBC passes the 183 on, with its own SDP. The PBX must play the media, not a local tone.
  11. Carrier gateway → PBX: RTP (ringback tone). Alice hears the ringback tone from the far exchange, through the gateway and the SBC.
  12. PSTN → Carrier gateway: ISUP ANM. Bob answers. The ANM starts the charge for the call.
  13. Carrier gateway → Carrier SBC: 200 OK. The gateway maps the ANM to 200 OK.
  14. Carrier SBC → PBX: 200 OK. The SBC answers the PBX on its own dialog.
  15. PBX → Carrier SBC: ACK. The PBX acknowledges the 200 OK.
  16. Carrier SBC → Carrier gateway: ACK. The SBC acknowledges the 200 OK on its own dialog.
  17. PBX → Carrier gateway: RTP. The call audio flows in both directions, through the SBC.
  18. PSTN → Carrier gateway: ISUP REL (cause 16). Bob hangs up. The exchange releases the call with cause 16, normal call clearing.
  19. Carrier gateway → Carrier SBC: BYE. The gateway ends the SIP call. The Reason header carries the Q.850 cause.
  20. Carrier SBC → Carrier gateway: 200 OK. The SBC confirms the BYE.
  21. Carrier SBC → PBX: BYE. The SBC ends its dialog with the PBX, and copies the Reason.
  22. PBX → Carrier SBC: 200 OK. The PBX confirms. Its call record shows cause 16: Bob hung up.

Remember: to withhold a number, send Privacy: id with P-Asserted-Identity, and an anonymous From. Test with a mobile phone, not only with another phone on the same PBX.

Summary

  • A SIP trunk connects a PBX to a carrier. A registration-based trunk uses REGISTER and digest authentication; an IP-based trunk uses a fixed address, and often OPTIONS to check that the PBX is up.
  • Trunks carry numbers in E.164: +, the country code, and the national number. The PBX normalises what users dial. A local number in a URI needs phone-context.
  • P-Asserted-Identity carries the caller’s number that the carrier checks; Privacy: id withholds it and becomes ISUP presentation restriction. An anonymous From alone withholds nothing.
  • On a forwarded call, Diversion or History-Info shows which number forwarded the call. Carriers need it to accept the caller’s number, and voicemail needs it to find the mailbox.
  • The gateway maps IAM, ACM, ANM, and REL to INVITE, 180 or 183, 200 OK, and BYE or an error. Reason: Q.850 keeps the exact cause, because the mapping between causes and status codes loses detail.
  • 183 with SDP carries tones and announcements from the PSTN. Play that media; make a local ringback tone only after a 180 without SDP.