This question doesn’t have a brief answer. Please click on the detailed answer.
a) For the shar’i distance needed to travel in order for one’s prayer to become shortened, the fuqaha (Jurisprudents) have various rulings. Some say the distance necessary is approximately 22.5 kilometers. Others say that the distance is approximately 21.5 kilometers. Another group says that it is approximately 22 kilometers.
b) In regards to the second part of the question, the criteria for one’s prayer to be shortened is to no longer see any of the houses of the city or the wall of the city (in the case of the city having one) and if the city doesn’t have walls then the basis will just be the houses of that city.
Our respected Maraji’ (Jurisprudents) have ruled in this regard as follows:
Ayatullah Udhma Khamenei:
1. If you are going to take a route that is 8 ‘Farsakhs’*, then your prayer will become ‘shortened’ (qasr), but if the route you take is less than 8 ‘Farsakhs’ then your prayers will be complete.
2. The beginning of 8 ‘Farsakhs’ has to be counted from the houses at the end of the city.
* 8 ‘Farsakhs’ means 45 Kilometers, even if this distance is covered going and coming back (for instance if you are going to travel 4 farsakhs to your destination and return the next day, your prayer will be shortened because that sums up to 8 farsakhs).
Ayatollah Al-Udhma Makarim Shirazi:
1. What matters is the route that will be used.
2. The last houses of the city are the basis for establishing the ‘shortened’ prayer.
Ayatollah Al-Udhma Safi Gulpayghani:
1. If the person leaves with no intention of returning, from a way that exits the city and the distance to his destination is approximately 45 kilometers then he must shorten his prayers. If he has the intention of returning then 22.5 kilometers will make him a traveler and his prayers will become ‘shortened’. The houses at the end of the city indicate the beginnings of his travel. If the person’s route is from a way that is entirely inside of a city and the houses continue to be near one another then he isn’t considered a traveler and his prayers will be complete. And Allah knows best.
2. The homes at the city limits have the same rule of the walls of the city, and they count as the end of the city and the start of the traveling. And God knows best.
 Imam Khomeini, Ayatullahs Bahjat, Khamenei, Fadhil Lankarani, Safi and Nouri. Tawdhihul-Masa’el (of Marja’s), vol. 1, issue 1272.
 Makarem Shirazi, Tawzihul-Masa’el (of Maraji’), vol. 1, pg. 684.
 Tabrizi, Sistani and Vahid Khorasani, Minhajul-Salehin, issue 884.
 With help from Question 1691 (website: 1853).