# Internet Layer
## What is the Internet Layer
The Internet layer is the second layer of the TCP/IP model, corresponding to the Network layer of the OSI model. It is the layer that makes the internet function as a global network connecting billions of devices across thousands of individual networks. The Internet layer is responsible for logical addressing using IP addresses, routing packets from the source to the destination across multiple networks, and defining the format of IP packets. The Internet Protocol is the primary protocol at this layer, and the internet is named after this protocol.
## Internet Protocol
The Internet Protocol defines the format of packets and the addressing scheme used across the internet. An IP packet consists of a header and a payload. The header contains the source IP address, the destination IP address, a time-to-live value, protocol information indicating which Transport layer protocol is being used, and various other fields. The payload contains the data being transported, which is typically a TCP segment or UDP datagram.
IPv4 is the original version of IP that has been in use since the early internet. It uses 32-bit addresses that allow for approximately 4.3 billion unique addresses. Due to the explosive growth of the internet, IPv4 addresses are now exhausted. IPv6 was developed to address this problem, using 128-bit addresses that provide an astronomically large address space sufficient for the foreseeable future.
## Routing at the Internet Layer
Routing is the process of determining the path that an IP packet should take from its source to its destination. Routers are the devices that perform routing at the Internet layer. Each router maintains a routing table that maps network addresses to the next hop on the path toward that network. When a packet arrives at a router, the router examines the destination IP address, looks up the best matching entry in its routing table, and forwards the packet to the next router on the path. This process repeats at each router until the packet reaches the destination network.
## Supporting Protocols at the Internet Layer
Several supporting protocols work alongside IP at the Internet layer. ICMP, the Internet Control Message Protocol, provides error reporting and diagnostic functions. The ping utility uses ICMP Echo Request and Echo Reply messages to test reachability. Traceroute uses ICMP Time Exceeded messages to trace the path packets take through the network. ARP, the Address Resolution Protocol, resolves IP addresses to MAC addresses within a local network. IGMP, the Internet Group Management Protocol, manages multicast group membership.
## Time to Live
Every IP packet contains a time-to-live value, abbreviated as TTL. This is a number that starts at some initial value, typically 64 or 128, and is decremented by one at each router the packet passes through. If the TTL reaches zero, the packet is discarded and the router sends an ICMP Time Exceeded message back to the source. The TTL mechanism prevents packets from circulating indefinitely in the network if there is a routing loop.Back to Subject