Rabbi Abahu said in the name of Rabbi Shimon ben Lakish: “… With regard to prayer in a Shul and the obligation to wash hands, the distance set by the Sages is four mil .”…
Rabbi Yose the son of Rabbi Chanina said: “The aforementioned teaching only applies when one must travel forwards; but where he would have to travel back (i.e. away from the direction of his destination) he would not even have to return one mil.”
Rav Acha said: “We can learn from Rabbi Yose’s phraseology that although one does not have to go back an entire mil, he would have to go back less than a mil.” (Gemara Pesachim 46a)
Mishnah Berurah writes that one who is sitting in his home has the status as one who must travel back (i.e. up until one mil). Therefore, one who lives within a mil of a Minyan would have to travel to join them. The amount of time it takes to walk a mil is 18 minutes. We calculate the mil based on time and not on distance. For instance, one who travels by car would be obligated to travel up to 18 minutes in order to pray with a Minyan. This would apply to one who is in his home. However, one who is travelling and has availability to a Minyan ahead of him, would indeed be obligated to travel four mil (72 minutes) to join them. One would not be allowed to stop over in a hotel if it would cause him to miss this Minyan (unless going there would cause him to entirely miss the proper time for davening or by travelling there he would be putting himself in danger).
The Gemara  explains that the exegetical principle of Gezeirah Shavah (comparison of phrases) is utilised twice in order to derive the requirement of ten for a Minyan quorum. The verse states in VaYikra 22:32: “… and I will be sanctified among (‘toch’) the children of Israel …”. The Rabbis had the tradition that this word ‘toch’ is associated with the same word in BeMidbar 16:21: “Separate yourselves from among (‘toch’) this community (‘eidah’) …”. Rabbinic tradition teaches a further association between the word ‘eidah’ just cited and the same word in BeMidbar 14:27, referring to the ten spies who brought back a bad report about the land of Israel as “… this evil community (‘eidah’) …”. Therefore, matters of holiness, such as communal prayer, require at least ten men.
The benefit of praying together with a Minyan is famously illustrated by the following parable: Once, a new King announced that on a certain date he would be visiting the two main regions of his kingdom. The council of the first region decided that every day of the week leading up to the King’s visit they would send a gift to the King; whilst the other region collected many gifts and presented them all on the day before the King visited them. Each day, the King found fault with the gifts from the first region; whereas the King was overwhelmed on the day before his arrival at the second region when he received such a large number of gifts together. When we pray alone God might find fault with us; but when we unite with a Minyan God looks at the whole group and does not scrutinise each individual. It is therefore in our interests to pray with a Minyan.
1. 1 mil = 1 kilometre
3. Biur Halachah 163:1
4. Based on the article “Effort required to daven with a minyan” in the Daf Yomi Digest Number 369 from the Chicago Centre for Torah & Chesed
5. Gemara Megillah 23b