Whenever you release a recording of a song that someone else wrote in an audio-only format, even if it's just a small portion of the song, you need a mechanical license. Mechanical licenses are most commonly used for cover songs; new recordings of you or your band performing the copyrighted song. For example, if you release a record of your band playing a Prince song, even if you use only a portion of the song, you need a mechanical license. If you release a recording of yourself playing a Billy Joel song or singing Adele lyrics, you need a mechanical license.
A mechanical license is required no matter how small a portion of the song you use. For medleys, direct permission is required from each copyright holder as they are considered derivative works. There are some exceptions where a mechanical license is not required: You don't need a mechanical license for songs that you wrote yourself or songs that are in the public domain.
Note that mechanical licenses are for audio-only products (CDs, digital downloads, interactive audio streams). If you are creating a visual product, such as a slideshow or video, you need a synchronization license instead. Mechanical is for audio-only, synchronization is for video.
If you use an original recording belonging to someone else (for example, an actual Beatles recording featuring John Lennon, Paul McCartney, Ringo Starr, and George Harrison) you will need a mechanical license to pay the composer for the right to use the composition (song), and also a Master license to pay the artists for the right to use the recording. This is true even if you are sampling only a very small portion of any existing copyrighted audio recording.