Networks are layered because layering separates concerns: each layer provides a service to the layer above and uses the service of the layer below. The OSI model has seven layers, and the standard memory aid reads from top to bottom: Application, Presentation, Session, Transport, Network, Data Link, Physical. The TCP/IP model, which the internet actually uses, has four layers: Application, Transport, Internet and Network Access (sometimes split into Link and Physical). The two models map onto each other: TCP/IP's Application covers OSI's top three layers, and TCP/IP's Network Access covers OSI's bottom two.
Each layer has a distinct job. The physical layer moves bits over a medium. The data link layer frames data and handles local delivery using MAC addresses, with switches operating here. The network layer routes packets between networks using IP addresses, with routers operating here. The transport layer provides end-to-end delivery: TCP is reliable, ordered and connection-oriented, while UDP is fast, unordered and connectionless. The session layer manages dialogues between applications. The presentation layer handles data formats, encryption and compression. The application layer provides network services to programs: HTTP for the web, DNS for names, SMTP for mail.
Worked example — tracing a web request. You type a URL. The application layer (HTTP) forms the request; DNS, also at the application layer, resolves the name to an IP address. The transport layer (TCP) opens a connection and splits the request into segments. The network layer (IP) addresses packets to the destination. The data link layer frames them for the local network with MAC addresses. The physical layer transmits bits. At the destination the process reverses, layer by layer. If a question asks where a failure occurred, find which layer's job failed: wrong IP address is a network-layer problem, lost segments are a transport-layer problem, and a garbled format is a presentation-layer problem.