Modulation refers to the changing of the tonal center in a piece of music. While modulation can be achieved by simply introducing chords and notes from another key their are more subtle ways to do this.
Pivot Chord Modulation
The smoothest transition you can make from one key to another is by pivot chord modulation. This type of modulation works by using a chord that is shared by two keys to "pivot" from one key to the other.
For example, in the key of C major the I, VIm, IIm, V7 chord progression (C, Am, Dm, and Gdom7) establishes the tonal center at C. However, since Am is also the IIm chord in the key of G, we could pivot into this key. Often the V chord of the new key follows the pivot chord to announce the new tonal center.
Below is a chord progression that modulates from the key of C major to G major using Am7 as a pivot chord.
Below is another example of pivot chord modulation from C Major to G Major by pivoting on the tonic chord. The tonic chord of C Major becomes the sub-dominant (four chord) of G Major.
Below is another example of pivoting. This time the tonic chord of C Minor becomes the submediant (six chord) of E< Major.
Below shows C diminished as the pivot chord. While C diminished is the VIIdim (seven chord) in the key of D< major, in the key of B< harmonic minor it is the IIdim (two chord).
In this example we actually pivoted into a Harmonic Minor scale form. We could have just as easily pivoted into B< natural minor but we would have ended up with an Fm (Vm of B< natural minor) acting as a dominant chord which does not create as much movement as the F7 (V7 of Bb harmonic minor).
Another way to go from one key to another is by way of direct modulation. This is often done by changing the chord type without changing the root of the chord. For instance, changing from Am7 to A7.
Because of its construction, a diminished seventh chord (dim7) offers several inverted combinations that work as chord substitutes. This chord is made up of four notes spaced a b3rd (minor third) apart. The notes of the diminished seventh repeat every 1-1/2 steps up or down the scale. The diminished seventh chord is not diatonic to the major scale; instead it is derived from the harmonic minor scale.
This type of modulation is not so subtle. It is easy to hear the shift in the tonal center. That makes it a common way to add tonal variety to a song.
This type of modulation get you from one key to another by moving chromatic to that key. That is, you step up or down the scale using chords a half-step at a time.
The root walks up the scale until it comes to a chord that is diatonic to the new key (C Major in this example above).