TodayTools

Internet Protocol version 4

How IPv4 works

The address on every packet

Donate
L3NetworkLink
What brings you here?

Watch it happen

How much detail

One packet hops across four links. The IP addresses stay, the MAC addresses and the TTL change.

Your laptop
Home router
ISP router
Core router
Web server
Wi-FiInternetCableRequestResponse

4 steps, 5 packets

First up: Build the packet. Press Play to watch it happen, one step at a time.

0 of 40/4

What is IPv4?

IPv4 puts a source and destination address on every packet, so routers can pass it from network to network until it reaches the right machine. It does not promise delivery or order. It just tries its best, one packet at a time.

An IPv4 address is 32 bits, written as four numbers like 203.0.113.10. That gives about 4.3 billion addresses, which ran out years ago. NAT and IPv6 are the two answers to that shortage.

Think of it like this. IPv4 is like the address on an envelope. Every sorting office reads only the address, picks the next office on the way and passes it on. The envelope may go in a new bag at each stop (a new MAC frame), but the address written on it never changes.

Step by step

Normal

4 steps

One packet hops across four links. The IP addresses stay, the MAC addresses and the TTL change.

  1. 1

    Build the packet

    Source, destination, TTL 64

    The laptop wraps a TCP segment in a 20-byte IPv4 header. The destination is the server, but the server is not on the home network, so the frame goes to the router's MAC address.

  2. 2

    Leave home

    The router forwards and translates

    The home router lowers the TTL to 63, looks up the destination in its routing table and sends it to the ISP. It also swaps the private source address for its public one. That part is NAT, a separate topic.

  3. 3

    Across the internet

    Router by router

    Each router reads only the destination address, picks the best next hop and lowers the TTL by one. It wraps the packet in a fresh frame for the next link.

  4. 4

    Delivered

    TTL 61 at the server

    The server sees its own address as the destination and hands the contents to TCP. The TTL left over tells you roughly how many routers the packet crossed.

Routing loop

3 steps

Two routers point at each other by mistake. TTL stops the packet from circling forever.

  1. 1

    A bad route

    Each router thinks the other knows the way

    After a mistake in a routing table, the ISP router sends 203.0.113.10 to the core router, and the core router sends it straight back.

  2. 2

    Round and round

    TTL counts down

    Each pass lowers the TTL by one. The packet started near 64, so it bounces about 60 times in a few milliseconds. We show the last few passes.

  3. 3

    TTL hits zero

    Dropped, sender told

    The router that would lower the TTL to zero throws the packet away and sends an ICMP Time exceeded message to the source. Without TTL, looping packets would pile up until the links choked.

Fragmentation

3 steps

A 3008-byte datagram does not fit a 1500-byte link, so IPv4 cuts it into three fragments.

  1. 1

    Too big for the link

    3028 bytes, MTU 1500

    An app sends a 3000-byte UDP message. With the UDP and IP headers it is 3028 bytes, but Ethernet carries at most 1500 bytes of IP per frame (the MTU).

  2. 2

    Cut into pieces

    Three fragments, one ID

    The sender splits the data into fragments of up to 1480 bytes each, so each fits with its own 20-byte header. All share ID 0x5e2a. The offset says where each piece goes, and the More fragments flag is set on all but the last.

  3. 3

    Joined at the end

    Only the receiver reassembles

    Routers forward fragments like any other packet. Only the server puts them back together. If one fragment is lost, the whole datagram is thrown away, which is why modern apps try hard to avoid fragmentation.

Too big, DF set

3 steps

The packet says do not fragment, but the next link is smaller. The router drops it and reports the size that fits.

  1. 1

    Full-size packet with DF

    1500 bytes, Don't fragment

    Most TCP traffic sets the Don't fragment flag. The sender would rather learn the right size than have routers cut its packets.

  2. 2

    Smaller link ahead

    A tunnel with MTU 1400

    The next link adds tunnel headers, so it carries only 1400 bytes. The router cannot split the packet because of DF, so it drops it and sends ICMP Fragmentation needed with the MTU that fits.

  3. 3

    Resend smaller

    Path MTU discovery

    The PC remembers the 1400-byte limit for this destination and resends in smaller pieces. If a firewall blocks these ICMP messages, big packets vanish silently: pages half load and then hang.

Myths and mix-ups

  • TTL is not a time in seconds today; every router simply lowers it by one.
  • The IP address does not change at each router; the MAC address of the frame does.
  • IP does not guarantee delivery; TCP or the app has to handle loss.
  • 192.168.x.x addresses are not reachable from the internet; they are private and need NAT.
  • Blocking all ICMP is not harmless; it breaks path MTU discovery and causes hanging connections.

Try it yourself

Run these on your own computer to see IPv4 at work.

  • See your IPv4 address (Windows)

    ipconfig

    Look for IPv4 Address, Subnet Mask and Default Gateway.

  • See your IPv4 address (macOS)

    ifconfig en0 inet

    The inet line is your address. Wi-Fi is usually en0.

  • See your IPv4 address (Linux)

    ip -4 addr

    Each inet line is an address with its prefix length, like /24.

  • See your routing table

    netstat -rn

    Works on Windows, macOS and Linux. The default route, 0.0.0.0, points at your router.

  • Test the path MTU (Windows)

    ping -f -l 1472 example.com

    -f sets Don't fragment. 1472 bytes of data plus 28 bytes of headers is 1500. Lower it if you see Packet needs to be fragmented.

IPv4 at a glance

Layer
Network (3)
Address size
32 bits, about 4.3 billion addresses
Header size
20 to 60 bytes
Max packet
65,535 bytes
Ethernet type
0x0800
Private ranges
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
Defined in
RFC 791 (1981)

Defined inRFC 791RFC 1918RFC 1191RFC 4632

Header fields

What IPv4 puts in its messages, with example values from the stories above.

UDP

Source port
50514
Destination port
9000
Length
3008 bytesLarger than one Ethernet frame can carry, so IP must split it.

IPv4

Version
4
Header length
20 bytes (5 words)20 bytes when there are no options, which is almost always.
DSCP and ECN
0x00 (normal service)
Total length
1500 bytesHeader plus data. The largest possible IPv4 packet is 65,535 bytes.
Identification
0x5e2aFragments of the same packet share this number, so they can be joined again.
Flags
0x1, More fragmentsMore fragments: this is not the last piece.
Fragment offset
185Where this piece goes, counted in 8-byte units: 185 x 8 = byte 1480.
Time to live
64Each router lowers it by one. At zero the packet is thrown away, so it cannot loop forever.
Protocol
17 (UDP)What is inside: 1 is ICMP, 6 is TCP, 17 is UDP.
Header checksum
verifiedCovers only the header. Routers fix it at each hop because the TTL changed.

Test yourself

Question 1 of 5Score 0

What does a router change in an IPv4 packet at each hop?

Questions people ask

What is an IPv4 address?

A 32-bit number that identifies a device's network interface, written as four numbers from 0 to 255, like 203.0.113.10. Routers use it to deliver packets to the right network and machine.

What is TTL in IP?

Time to live: a counter in every packet that each router lowers by one. When it hits zero, the packet is dropped. It stops packets from looping forever. Most systems start it at 64 or 128.

What is the difference between a public and a private IP address?

Public addresses are unique on the internet and reachable from anywhere. Private ones (10.x, 172.16 to 172.31, 192.168.x) are reused in millions of homes and offices and need NAT to reach the internet.

What is IP fragmentation?

Splitting a packet that is too big for the next link into smaller pieces. Each piece gets its own header, and the receiver joins them. Losing one piece loses the whole packet.

Did IPv4 addresses run out?

Yes. The global free pool ran out in 2011, and the regional registries ran out over the following years. Networks now share addresses with NAT, buy them from others, or move to IPv6.

Donate