Ping works by sending ICMP Echo Request messages to test connectivity and measure response times. It opens a raw socket to directly interface with ICMP at the Internetworking layer, bypassing TCP and UDP. Ping programs format Echo Requests and examine all incoming ICMP messages to extract Echo Replies and error messages relevant to that instance. The identification field allows multiple pings to differentiate their own messages.