“In music , modulation is the change from one tonality (tonic, or tonal center) to another. This may or may not be accompanied by a change in key signature.”
"And how is it done?" in thousands (or more) of ways.
simplest way I can think of…you want to change form a D (5 chord) to a G (1 chord) in the key of G
to modulate you throw in a D7 between the two…this makes a pleasing/natural
sounding transition.and creates expectation of the chord you’re going to.
You will often hear a simple chromatic modulation between the 4 & 5 chords or between the 1 & 4 chords.
It can get really involved and can be studied for years…