Praise be to Allah.
Prayer in congregation is obligatory for every adult man who can hear the call.
What is meant by hearing the call is that a person can hear the adhaan given in a regular voice without amplification of the sound, if the muezzin raises his voice and there is no wind or other noise that could affect hearing it.
See question no. 20655.
Based on this, you are not obliged to attend prayers in congregation in the mosque if it is far away from you.
This has to do with the five daily prayers in congregation. With regard to Jumu’ah (Friday prayer), that is a different matter. It is obligatory for everyone who is in the city or town in which Jumu’ah prayers are held regularly, whether he can hear the adhaan or not, not matter how spread out the city is. This is according to scholarly consensus.
Al-Nawawi (may Allaah have mercy on him) said: al-Shaafa’i and the companions said: If there are forty or more mature people in the city, then Jumu’ah is obligatory for everyone in the city, even if the city is widely spaced out and whether they can hear the adhaan or not. There is consensus on this point. End quote from al-Majmoo’ (4/353).
If a person is not obliged to pray in congregation because he is far away from the mosque, it is still mustahabb for him, and he should be keen to come to the mosque time after time, especially if he is living far away from other Muslims. By meeting other Muslims he will renew his faith, raise his status, strengthen the bonds of brotherhood and love, and make his children get used to loving and respecting the mosque. He should also join the efforts to build mosques and increase their numbers, and cooperate with others for that purpose. It should be noted that European cities vary greatly in that regard, and this is due to many factors, which sometimes include lack of effort on the part of some, their lack of unity and their being distracted from this important matter and from striving to find solutions.
It is no secret that there is a great reward for striving to reach the mosque, no matter how great the distance. Muslim (654) narrated that Ibn Mas’ood (may Allaah be pleased with him) said: Whoever would like to meet Allaah, may He be exalted, tomorrow as a Muslim, let him regularly offer these prayers where the call to prayer is given, for Allaah has prescribed the Sunnahs of guidance to your Prophet (S) and they (the prayers) are among the Sunnahs of guidance. If you pray in your houses like this one who stays away from the mosque prays in his house, you will have forsaken the Sunnah of your Prophet, and if you forsake the Sunnah of your Prophet you will go astray. There is no man who purifies himself and purifies himself well, then he goes to one of these mosques, but Allaah will record one good deed for him for every step he takes, and will raise him in status one degree thereby, and will erase one bad deed thereby. I remember when no one would stay away but a hypocrite whose hypocrisy was known, and a man would come staggering between two others in order to stand in the row.
You should also be keen to establish prayer in congregation in the home, or with your neighbours, if you do not go to the mosque. Among the means of achieving that is striving to bring Muslim families to live close to one another, when all of them will be keen to offer the prayer in congregation on time, and this great ritual will hold its rightful place in their hearts.
We ask Allaah to increase you in faith, guidance and piety, and to help you to carry and spread the message of Islam.
And Allaah knows best.