How waves reflect at the ends of a medium, or at the interface between two media, is critical to understanding things like musical instruments.
When a wave encounters a fixed end, for instance, it comes back upside down.
When a wave encounters a free end, it comes back the same way it went out.
The actual string is shown at the bottom in purple. A pulse moving to the right is shown in red, and the reflected pulse, moving left, is shown in blue. What the actual string does is the superposition of the top two pictures.
When a wave traveling in a medium encounters a boundary with a lower-velocity medium (i.e., the wave speed is lower in the other medium) part of the wave is reflected and part is transmitted. For the reflected part, the boundary acts like a fixed end and the reflected wave is inverted.
When the wave encounters a higher-velocity medium there is also some reflection and some transmission of the wave. This time the boundary acts like a free end and the reflected wave is upright.