Sahih Muslim Book 6, Hadith 14
I asked Anas b. Malik about shortening of prayer. He said: When the Messenger of' Allah (ﷺ) had covered a distance of three miles or three farsakh (Shu'ba, one of the narrators, had some doubt about it) he observed two rak'ahs.
I observed four rak'ahs in the noon prayer with the Messenger of Allah (ﷺ) at Medina, and said two rak'ahs in the afternoon prayer at Dhu'l-Hulaifa.
I went along with Shurahbil b. al-Simt to a village which was situated at a distance of seventeen or eighteen miles, and he said only two rak'ahs of prayer. I said to him (about it) and he said: I saw 'Umar observing two rak'ahs at Dhu'l-Hulaifa and I (too) said to him (about it) and he said: I am doing the same as I saw the Messenger of Allah (ﷺ) doing.