Assuming your horse listens to your leg aid already, you apply alternate leg aid in ryhthm with i's stride. That means squeezing or tapping with your lower leg, first the left then the right, alternately. The idea is to apply the leg aid as the horse's hind leg on that side comes forward, asking him to step under more/step bigger.
It's actually easier to feel this/learn to apply it at the posting trot - your inside leg aid is applied as you post, the outside as you sit (assuming you're posting to the outside diagonal) You'll know that the horse has lengthening when you're staying up in the air longer when you post - if the horse quickens rather than lengthens, you'll post faster and stay in the air a shorter amount of time.
The same principles apply at the walk, though you have to have a more sophisticated feel for the beats of the walk, and apply your inside aid as the inside hind comes forward, outside as the outside hind comes forward.