It is well-known that, on most systems, using 0 for the UDP destination port or for the TCP source or destination ports is disallowed. Is this required by RFCs, or is this just common practice? If it's required, which RFCs require it?

  • 4
    Port 0 is reserved by networking libraries (either socket or streams API) to return a random unused port number. All popular OSes do this. If you use port 0 the socket library will give you port 63812 or 23712 or 11328 or 9035 etc. Because of this it is generally impossible for port 0 to appear on the wire (unless you write your own implementation of TCP/IP stack)
    – slebetman
    Oct 7, 2021 at 5:30
  • daniel.haxx.se/blog/2014/10/25/…
    – Joshua
    Oct 7, 2021 at 21:44
  • @slebetman please don't answer in a comment, write a proper answer. Oct 7, 2021 at 23:32
  • 1
    @PaŭloEbermann It's a comment because Ron already said the same thing in his answer. My comment is just to clarify to the OP what the meaning of "ephemeral" is. Also, I commented here because it's aimed at the OP instead of Ron because I don't think there's anything wrong with his answer.
    – slebetman
    Oct 8, 2021 at 16:02

2 Answers 2


IANA has reserved both TCP and UDP port 0. See the IANA Service Name and Transport Protocol Port Number Registry. IANA is the Internet Assigned Numbers Authority, so all internet numbers, including port numbers, are assigned by IANA.

OSes have reserved that port number for an application to request an ephemeral port number by using it as a source port number, but that is off-topic here.



Port zero has been included in the "Network Wide Standard Functions" range since RFC433 in 1972, but has never been assigned.

In October 1983, for the first time, it was explicitly listed as "reserved" in RFC870.

It's probably not a coincidence that this is about the same time the BSD sockets API was released.

  • The release of BSD is mentioned as a conforming system

Within the R&D community, it will be the policy that network identifiers will only be granted to applicants who show evidence that they are acquiring standard Bolt Beranek and Newman gateway software or have implemented or are acquiring a gateway meeting the Exterior Gateway Protocol requirements. Acquisition of the Berkeley BSD 4.2 UNIX software might be considered evidence of the latter.

  • The BSD sockets API uses port zero to mean the operating system should assign an available port.
  • If BSD conforms, then it follows that port 0 cannot be used.

It may well be that other systems were already using this convention in their APIs, or that this was agreed somewhere, but I haven't found any documentation to prove that.

  • You should also mention that RFC 870 you reference has been obsoleted to HISTORIC status, as have the obsoleting RFCs (900, 923, 943, 960, 990, 1010, 1060, 1340, 1700), up to RFC 3232, which is INFORMATIONAL (not STANDARDS TRACK). RFC 3232, now says "Assigned Numbers: RFC 1700 is Replaced by an On-line Database" That is now IANA.
    – Ron Maupin
    Oct 7, 2021 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.