I was asked a question my one of my teachers. What is TCP port 0 reserved for? I did a bit of searching and research found 2 reasons:

  1. For linux based system, to get the next available port from the OS that the program can use. Like asking for dynamically allocated ports.

  2. Packets that don't need port numbers (like ICMP) use port number 0 in their packet.

But these seemed like something that has evolved to be used for, just because port 0 was not being used for anything else. I did not find any use of port 0 that was assigned by 'IANA' in the beginning. Is there anything that was officially assigned to port 0?

  • 5
    ICMP is not TCP and does not use TCP, and as such does not use TCP/0. – YLearn Oct 1 '14 at 14:24

Keep in mind that a "reserved" resource is not an "assigned" resource. Just because it is reserved doesn't mean that it is intended to be used for anything, at least at the current time. Rather it has been set aside and should not be used, unless otherwise specified.

From RFC6335:

 Reserved port numbers are not available for regular
 assignment; they are "assigned to IANA" for special purposes.
 Reserved port numbers include values at the edges of each range,
 e.g., 0, 1023, 1024, etc., which may be used to extend these
 ranges or the overall port number space in the future.
| improve this answer | |
  • 3
    You might imagine inventing TCP+ which is like TCP but with 64-bit port numbers. Then you could (once IANA approves) put 0 in the port number to indicate the extended port number field should be used instead. – richardb Oct 1 '14 at 16:38
  • 1
    @richardb, exactly, although the RFC only provides this as a possible use for those port numbers. It could also be for some purpose that hasn't even been conceived of today...that is the beauty of technology, it is always changing and having the flexibility built into the design can make it much easier for technology to do so. – YLearn Oct 1 '14 at 17:47

Disclaimer: My answer can be considered as having conflict of interest to some people as the material I reference in my answer is actually initially created by me.

Neither IETF nor IANA currently (as of 2019) have any documented real-world use for the TCP port 0, however the book "UNIX Network Programming" by Richard Stevens et.al. teaches people to obtain an dynamically assigned port by binding to port 0. This practice is documented in several other places including Linux and FreeBSD man page.

Currently, there is an open bug at Austin Group (the group who develops POSIX and Single Unix Specification) concerning this waiting resolution.

| improve this answer | |

TCP port 0 has a special meaning in many socket APIs (especially the common Berkeley socket API that the POSIX one grew out of), for requesting an ephemeral/dynamic port from the stack. Probably for that reason IANA has reserved that port, so that it is not used in general.

Within the actual stack, port 0 has no special meaning (nor does any other number have). Due to its API use it might be (very) hard to put into actual use though. And simply, there's no point to try.

Note that ports are only used with some transport-layer protocols. ICMP (which actually belongs to the network layer although it is encapsulated like an L4 protocol) doesn't use ports.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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