I am taking a networking class, and I understand that payload data is part of a packet (within TCP or UDP), that is actual data that is being sent from the sender to the recipient. However, what kind of data other than an e-mail message will a computer send to the recipient?
If you look at the network layers, each layer of the network stack has a payload:
- Layer-2 frames have a payload of layer-3 packets.
- Layer-3 packets have a payload of layer-4 segments.
- Layer-4 segments have a payload of application data.
- Application data can also have its own datagrams, which have payloads, but anything above OSI layer-4 is off-topic here.
You should look at one of the network models, e.g. the OSI model, but remember that the models are just models, and the real world can often be different than any of the models predict.
Any application using the network will have data as a payload to the network stack. For instance, web browsers and servers use HTTP as an application-layer protocol, and HTTP uses TCP as its layer-4 protocol, so HTTP is a payload of TCP. The browser sends requests to the server, and the server returns web pages as a result. Both the requests and results are payload of TCP segments.
... and from the analogy department:
You drive with an envelope containing a document which is a cover letter with a cheque which you're going to hand to someone.
- The car thinks you are the payload
- You think the envelope is the payload
- The envelope thinks the letter is the payload
- The letter thinks the cheque is the payload
- It is no matter to the car what you are taking
- It is no matter to you what's in the envelope
- It is no matter to the envelope what the letter says
- It is no matter to the letter whether the cheque is good
Of course, the whole purpose of the exercise was to get the cheque there, which might be called the ultimate payload.
Any data that is not part of the protocol can be considered payload.
In your email message example, the specific message text, attachments, ... are payload. The message format adds the required headers to this payload to form a standard RFC email message. This message can then for instance be transmitted over SMTP:
SMTP gets the message from above as payload and adds its protocol dialogue to the communication (the payload is wrapped). This is sent over TCP.
TCP (L4) gets the SMTP dialogue as payload and adds its headers to the packetized stream to make it work. TCP then uses IP to send the packets to the destination.
IP (L3) gets the TCP segment as payload and adds its IP header to the TCP segment to form a network layer packet that can actually be transported to the destination. IP may use Ethernet as a hop in the route to this destination.
The Ethernet frame (L2) gets the IP packet as payload and adds its frame header to enable Ethernet transport. Ethernet also adds packet overhead (L1) to the frame to actually enable physical transport. This Ethernet packet is then line encoded according to the specific physical layer and the line symbols are sent over the wire (or fiber or ...). This last step repeats until the destination is reached.
This is a simplified view that only shows examples - in practice there are many different ways and protocols for this to work. The beauty of it is that you can combine the various layer options in countless ways.