I'm confused about how the data flows through the layers of the TCP/IP model, so I'll just tell what I think it happens (using an email example) and I'd appreciate if you can point my mistakes.
Suppose A wants to send an email to B via gmail. A opens gmail, writes the text and sends. In this moment, gmail calls the Application Layer, which will provide gmail with the correct email protocol (in this case it's IMAP, but it could be SMTP or POP3). What these protocols do is to turn that email into a "box" that contains only the binary representation of this email in a way that only the same protocol can interprete: it can be encrypted, compressed, etc. Until this point, there is no address in the "box", only pure data, and the "box" is a single unit of data (that can be very large). The name of the "box" is data.
Then, the data is given to the Transport Layer (suppose it uses TCP), which will deal with the ports. My confusion starts here. Suppose gmail tab uses the port 1000 to stablish connection and the IMAP port is 143. I've read that the Transport Layer breaks data in multiple pieces if it is too big. In each of this pieces (which are called segments), it adds some things: the origin and destination ports and some security/integrity information (checksum, etc).
- What will these origin and destination ports be?
- Is the Transport Layer who breaks a big file in pieces or it comes already divided from the Application Layer?
Then, comes the Internet Layer, which takes the segments and add the origin and destination IP addresses on them, turning the segments into packets.
- How does the Internet Layer find out the destination IP address to begin with?
Lastly, the Network Access Layer, using the protocol ARP, finds out the MAC address of the destination IP and adds the origin and destination MAC addresses into the packets, turning them into frames, that will be physically send across the network using protocols such as WiFi, Ethernet, etc.