Jurists have declared that If one moves about three steps or more in succession, then his prayer becomes invalid.
If one moves less than three steps or four to five steps but at different intevals then it does not invalidate the prayer. This ruling is for both compulsory and extra prayers [1].
In instances when in congregation the row in front is to be completed, one should fill the spot with two strides. It doesn’t invalidate the prayers.
[1] Tuhfa 2:491