Does Swimming Break Your Fast?
Question

Can you swim while fasting for a school requirement?
Praise be to Allah.The ruling on swimming when fasting depends on the following: 
When can you swim while fasting? 
If the swimmer thinks it most likely that no water will enter his stomach through the mouth or nose , and he is a good swimmer and can guarantee that his fast will not be broken, then in that case there is nothing wrong with him swimming. The ruling is the same as that on doing ghusl when fasting . The scholars have stated that that is permissible even if it is just for the purpose of cooling down. 
Al-Bukhari (may Allah have mercy on him) said: “Chapter on doing ghusl when fasting. Ibn ‘Umar (may Allah be pleased with him) wetted his garment and put it on when fasting.” 
Al-Sha’bi entered the hammam (bath) when fasting. And al-Hasan said: There is nothing wrong with the fasting person rinsing his mouth and cooling himself off … and Anas said: I have a tub which I keep immersing myself in when I am fasting. 
Abu Bakr al-Athram narrated with his isnad that Ibn 'Abbas entered the hammam when he was fasting, he and some of his companions, during the month of Ramadan. Al-Mughni, 3/18 
It says in Fatawa al-Lajnah al-Daimah (10/281): 
“It is permissible to swim during the day in Ramadan, but the swimmer should take care to avoid letting water enter his stomach.”
Shaykh Ibn ‘Uthaymin (may Allah have mercy on him) said: 
“There is nothing wrong with the fasting person swimming, and he may swim as he wants, and immerse himself in the water, but he must be careful to avoid letting water enter his stomach, as much as he can. This swimming will energize the fasting person and help him to fast, and whatever gives a person energy to carry out Allah’s commands should not be disallowed, for it is something that makes it easy for people to carry out His commands. Allah says in the verses on fasting (interpretation of the meaning): 
“Allah intends for you ease, and He does not want to make things difficult for you. (He wants that you) must complete the same number (of days), and that you must magnify Allah [i.e. to say Takbir (Allahu Akbar: Allah is the Most Great)] for having guided you so that you may be grateful to Him.” [al-Baqarah 2:185]
And the Prophet (peace and blessings of Allah be upon him) said: “This religion is easy, and whoever overburdens himself in religious matters will not be able to continue in that way.” And Allah knows best.”
He also said: 
“There is nothing wrong with a fasting person diving into water or swimming in it, because that is not among the things that break the fast. The basic principle is that things are permissible unless there is evidence to show that they are makruh or haram. There is no evidence that swimming is makruh or haram, rather some of the scholars regarded it as makruh lest anything enter the swimmer’s throat without him realizing it.” (Fatawa Ibn ‘Uthaymin, 19/284-285) 
When can’t you swim while fasting?
If he thinks it most likely that water will enter his stomach because of swimming, then it is not permissible for him to do this, and it is haram for him to go swimming during the day in Ramadan. The evidence for that is the report narrated from Laqit ibn Sabirah (may Allah be pleased with him) who said: I said: O Messenger of Allah, tell me about wudu’. He said: “Do wudu’ well, make the water go between your fingers and toes, and go to extremes in rinsing the nose, unless you are fasting.” Narrated by Abu Dawud (142) and al-Tirmidhi (788), who said it is hasan sahih. Classed as sahih by Ibn Hajar and al-Albani. 
Imam Ahmad said that a fasting person may immerse himself in water if he does not fear that it will get into his ears. 
Al-Hasan and al-Sha’bi regarded it as makruh to immerse oneself in water, lest water get into the ears. al-Mughni (3/18). 
Al-Adhra’i (one of the Shafi’i fuqaha’) said: 
“If he knows that water usually enters his stomach when he immerses himself in water, and he cannot avoid it, it is haram for him to immerse himself.” (Hashiyat al-Bujayrami, 2/74)
The question now is: if he goes to extremes in rinsing his nose – and similarly if he immerses himself in water and swims during the day in Ramadan – and water reaches his stomach without him intending it to, whether he thought it most likely that water would not enter his stomach or not – is he regarded as having broken the fast? 
The scholars differed concerning that. 
The first view is that of the majority of Hanafi, Maliki and Shafi'i scholars, which is that his fast is invalidated. 
The second view is that it is not invalidated. This is the view of some of the Tabi'in, and is the view of the Hanbalis, and was the view favoured by Ibn ‘Uthaymin (may Allah have mercy on him). Al-Sharh al-Mumti’ (6/407). 
See: al-Majmu’ (6/338); al-Mughni (3/18). 
You must also be careful to avoid showing the ‘awrah when swimming. Do not swim in a place where people uncover their ‘awrahs, and do not take lightly the issue of looking at the ‘awrahs of others. 
For more, please see these answers: 23464  and 38907 .