When you press a piano key, a hammer inside hits the corresponding strings, just as a device called a damper is lifted. This enables the strings to vibrate, producing a sound before the key is released and the damper returns to its position, stopping the vibration.
Pressing the piano’s right-hand pedal keeps the damper off the strings, even after the key’s released, allowing the vibration to continue and the note to resonate. The middle pedal, called the sostenuto pedal, has a similar purpose, but only lifts the damper off the strings you’ve hit, enabling the effect to be controlled.
Finally, the left-hand una corda pedal is used for a softer sound. Most treble keys of a piano are attached to three strings, but this pedal will cause the hammer to only hit two instead of all three at once.