Layer 2 is responsible for switching data whereas Layer 3 is responsible for routing the data.
Layer3: With information gathered from user, Internet protocol make one IP packet with source IP and Destination IP and other relevant information. It can then route packet through router to the destination.
Layer2: Soon after it receives IP packet from layer 3, it encapsulate it with frame header (ATM header in case of ATM technology) and send it out for switching. In case of ethernet it will send data to MAC address there by it can reach to exact destination.