Shulchan Aruch, Orach Chayim 104:5–6 reads:
If he paused [even silently —MB] [amid of sh'mone esre enough time] to finish the entire [sh'mone esre], he goes back to the start [of sh'mone esre]; otherwise, he goes back to the start of the b'racha he paused in. But if he stopped in [one of] the first three [b'rachos], he goes back to the start; [in one of] the last [three], he goes back to "R'tze". That which we said "if he paused to finish the entire", we assess the one reading.
If he spoke during sh'mone esre, his rule regarding going back is like the rule for the interruptions mentioned [above].
MB qualifies this extensively, by limiting the reasons for pauses to which this halacha applies, by limiting the minimum length of a pause to which it applies, by limiting where the pause to which it applies was made, and so on. He cites a number of machlokos in these regards, so consult your rabbi for guidance.