TCP/IP syntax refers to the formal notation, field layouts, and formatting rules used to express network addresses, endpoints, protocol headers, and application messages across the Transmission Control Protocol and Internet Protocol suite. Whether you write firewall rules, configure network interfaces, parse packet captures, or build client-server applications, following exact TCP/IP syntax ensures different operating systems, routers, and software stacks interpret network data without ambiguity.
IP Addressing and Subnet Syntax
At the Internet layer, hosts and networks are identified using structured numeric formats that routers parse bit by bit.
IPv4 Dotted-Decimal and CIDR Notation
An IPv4 address is a 32-bit value conventionally written as four decimal octets separated by periods (0 to 255 in each octet), such as 192.0.2.10. To specify a network prefix and host range without writing separate subnet masks, engineers use Classless Inter-Domain Routing syntax—an address followed by a slash and a prefix length from /0 to /32, such as 192.0.2.0/24. The prefix length indicates how many leading bits belong to the network portion.
IPv6 Colon-Hexadecimal Syntax
An IPv6 address is a 128-bit identifier written as eight 16-bit hexadecimal groups (hextets) separated by colons, such as 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Because full IPv6 strings are long, two standard shorthand rules apply:
- Leading-zero omission: Leading zeros inside any 16-bit group may be dropped (for example,
0db8becomesdb8, and0000becomes0). - Zero compression (
::): One contiguous run of all-zero groups can be replaced with a double colon (::), such as2001:db8::1. Using::more than once in a single address is invalid because decoding the number of omitted zero groups would become ambiguous. - Prefix notation: Like IPv4, IPv6 subnets use slash notation from
/0to/128, such as2001:db8::/32.
Socket Endpoints and URI Syntax
Applications connect over TCP or UDP using sockets, which pair an IP address (or hostname) with a 16-bit port number (0 to 65535).
- IPv4 socket format: Written as
ip:port, such as203.0.113.25:443. - IPv6 socket format: Because IPv6 addresses contain colons, IPv6 literals in sockets and URLs are enclosed in square brackets before the colon and port, such as
[2001:db8::1]:8080. - Uniform Resource Identifier (URI) authority: In web and network URIs (
scheme://userinfo@host:port/path?query#fragment), the authority component separates credentials (@), bracketed IPv6 or domain hosts, and optional:portvalues cleanly so parsers never confuse colons inside an IPv6 address with a port delimiter.
Header and Wire-Format Syntax
Below the application layer, TCP/IP syntax is defined at the bit and byte level so hardware and kernels can read headers deterministically.
IP Header Fields
An IPv4 header starts with fixed fields—including Version (4), Internet Header Length (IHL) (measuring header size in 32-bit words), Differentiated Services / ECN bits, Total Length, Identification, Flags and Fragment Offset, Time to Live (TTL), Protocol number (such as 6 for TCP and 17 for UDP), Header Checksum, and Source/Destination IP Addresses. IPv6 simplifies the fixed base header to 40 bytes while using Next Header and extension headers for optional routing or fragmentation metadata.
TCP Segment Header Fields
A TCP segment begins with a mandatory 20-byte header (extendable up to 60 bytes via options) followed by payload bytes:
- Source Port and Destination Port (16 bits each): Identify sending and receiving application endpoints on each host.
- Sequence Number and Acknowledgment Number (32 bits each): Track byte-stream ordering and acknowledge received bytes for reliable delivery.
- Data Offset (4 bits): Specifies the TCP header length in 32-bit words so the receiver knows where payload data starts.
- Control Flags (
SYN,ACK,FIN,RST,PSH,URG): Coordinate connection setup, acknowledgment, graceful teardown, resets, and urgent or push handling. - Window Size (16 bits) and Checksum (16 bits): Advertise receive buffer space for flow control and verify header/payload/pseudo-header integrity.
Common TCP/IP Notation and Syntax Rules
| Notation / Format | Example | Syntax Rule to Remember | Common Pitfall |
| IPv4 CIDR | 10.20.0.0/16 | Four octets (0–255) plus /prefix (0–32) | Setting host bits inside a network prefix or misreading /cidr masks |
| IPv6 Address | fe80::1ff:fe23:4567:890a | Hex groups separated by :; at most one :: | Using :: twice in one address or omitting brackets in [ip]:port |
| Socket Endpoint | [2001:db8::10]:8443 | host:port with [...] around literal IPv6 | Writing 2001:db8::10:8443 without brackets around the IPv6 address |
| TCP Header Offset | 5 (20 bytes) | Counted in 32-bit (4-byte) words, not bytes | Multiplying or dividing by the wrong unit when parsing options |
Application and Command-Line Syntax
At the top of the stack, protocols layered on TCP/IP enforce text or structured syntax—such as HTTP request lines (METHOD /path HTTP/1.1), Host headers for virtual hosting, CRLF (\r\n) line endings in classic text protocols like SMTP, and DNS domain labels separated by dots. Meanwhile, command-line tools (ping, ss, ip, curl, nmap) expect strict flag and argument syntax.
When working with TCP/IP syntax in scripts, configs, or code, validate address families explicitly, avoid hardcoding unbracketed IPv6 strings, and test edge cases like dual-stack (IPv4 + IPv6) hosts, port ranges, and malformed inputs before deploying to production.