Sahih Muslim Book 6, Hadith 13
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.
The Messenger of Allah (ﷺ) said four rak'ahs in the noon prayer while at Medina, but he offered two rak'ahs in the afternoon prayer at Dhu'l-Hulaifa.
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.