Introduction
An IPv4 address observed inside a site can differ from the source seen by a remote service. Network address translation explains that change. With address-and-port translation, several local endpoints can share an outward-facing address.
Separate address translation from port translation
Basic NAT changes an IP address as a packet crosses between address realms. Network Address Port Translation, also called NAPT or PAT, can change a transport port as well. The shared port space helps distinguish sessions when many hosts use the same external address.
A static mapping can be provisioned ahead of traffic. A dynamic translator can allocate mappings when flows require them. The supported mapping and filtering behaviors are implementation and configuration properties, and TCP and UDP have distinct protocol contexts.
Read the translation in each direction
For a typical outbound TCP connection, the translator replaces the private source address and possibly source port with an external endpoint. The remote service sends the reply toward that external endpoint. The translator uses the applicable mapping to restore the inside destination.
Checksums affected by the rewritten fields must be updated. The TCP or UDP checksum calculation includes IP addresses in its pseudo-header, so changing the IP source can affect a transport checksum even when the payload bytes stay identical.
Track state, lifetime and routing separately
Returning traffic must reach a device with the necessary translation information. A reboot, mapping timeout or asymmetric return path through an independent translator can break that association. Recording the time, protocol, addresses and ports helps distinguish sessions in an administrative log.
Translation and packet-filter policy serve different purposes. A mapping describes how to rewrite an endpoint. Firewall rules determine permitted traffic. Capacity also depends on address pools, usable ports, protocol behavior and the implementation's state limits.
Diagram
- Client · 10.20.1.8:51514
- Inside of translator
- Outside · 198.51.100.7:41001
- Service · 203.0.113.80:443
Worked examples
Distinguish two clients sharing an external address
- Two clients start TCP connections to 203.0.113.80:443. Both choose local port 51514, one on 10.20.1.8 and the other on 10.20.1.9.
- For these sessions, suppose the translator assigns external endpoints 198.51.100.7:41001 and 198.51.100.7:41002. The remote service can distinguish them even though their outside IPv4 address is identical.
- A reply to 198.51.100.7:41002 for the second connection is translated back to destination 10.20.1.9:51514. The illustrated port choices are sample assignments, not values derived from the private addresses.
IPv4 Calculator: Locate 192.0.2.77 inside a /26
- A /26 keeps 24 bits from the first three octets and two bits from the last. Six host bits give a block of 64 addresses.
- Write 77 as 01001101. Keeping the first two bits gives 01000000, or 64. Filling the remaining six with ones gives 01111111, or 127.
- The block is 192.0.2.64/26. On a conventional LAN its first and last ordinary host addresses are 192.0.2.65 and 192.0.2.126.
Reference table
| Transport | Inside endpoint | Translated endpoint | Peer |
|---|---|---|---|
| TCP | 10.20.1.8:51514 | 198.51.100.7:41001 | 203.0.113.80:443 |
| TCP | 10.20.1.9:51514 | 198.51.100.7:41002 | 203.0.113.80:443 |
Configuration example
- Inside prefix = 10.20.1.0/24
- Example external address = 198.51.100.7
- Outbound translation = dynamic source address and port
- Session record = timestamp, protocol, inside endpoint, external endpoint, remote endpoint
Common mistakes
- Assuming two connections seen from one external IP originated on the same client.
- Recording only the translated address when several active clients share it.
Frequently asked questions
Must the outside source port differ from the inside source port?
No. A translator can preserve the original port when its mapping rules and available port space permit. Another mapping may require a different value.
Why can an existing session fail after gateway failover?
The new gateway may lack the prior dynamic mapping. Designs that preserve these sessions need compatible state synchronization or another means of maintaining the association.
Does NAT make every internal host directly reachable from the internet?
No. Outbound address and port translation commonly lets internal flows share an external address, but unsolicited inbound traffic generally needs a mapping or another explicit path.
Is NAT the same as a firewall?
No. Translation changes address or port fields. A firewall applies policy. A deployment can combine both functions, but translation alone is not a complete access-control policy.
Why can some protocols have trouble through NAT?
Protocols that embed addresses or ports in their payload can conflict with translated headers. Application gateways or traversal techniques may be needed, depending on the protocol and deployment.
Does IPv6 eliminate all translation?
No. IPv6 commonly supports end-to-end addressing without address sharing, but translation can still be deployed for specific transition or policy needs. It is not an automatic property of IPv6.
What is carrier-grade NAT?
It is address sharing performed by a provider, often using shared address space between customer networks and public IPv4. A subscriber may therefore not control the outermost translation.
Why can inbound port forwarding fail behind carrier-grade NAT?
A customer router can configure its own mapping, but traffic must also pass any upstream provider translation. Without provider support or a public reachable address, the inbound path may not exist.
Does NAT keep a connection alive by itself?
Translation state can expire after an idle interval. Applications may need keepalives or reconnection behavior, and a mapping does not guarantee that the remote service remains available.
What is hairpin NAT?
It is a router behavior that lets an internal client reach an internal service through the network's external address. Support and configuration vary by gateway.
What is the difference between source NAT and destination NAT?
Source NAT changes the source address or port of a flow, often for outbound sharing. Destination NAT changes the destination, often to direct an inbound connection to an internal service.
Why does NAT keep connection state?
A stateful translator needs a mapping between internal and external flow identifiers so reply traffic can be associated with the correct internal endpoint.
Is 100.64.0.0/10 a private RFC 1918 range?
No. It is shared address space designated for carrier-grade NAT. It can appear between a customer router and a provider's public address translation.
How does NAT64 differ from ordinary IPv4 NAT?
NAT64 translates between IPv6 and IPv4 traffic, often paired with DNS64 synthesis for IPv4-only destinations. It is a protocol-family transition mechanism, not just IPv4 address sharing.
Can a NAT mapping replace an access-control rule?
No. A mapping defines how addresses or ports are translated. Separate firewall policy should explicitly control which flows are permitted.

