Short answer
Killing ants that do you no harm is disliked, because the Prophet ﷺ forbade killing ants and a few other creatures. If ants bite you, spoil food or infest your home, you may kill them, preferably with a quick method. Burning ants or drowning them is disliked by the Hanafi scholars.
Killing an ant that has not harmed you is makruh. If ants cause harm, killing them is permitted. Burning them is makruh tahrimi, and throwing them into water is disliked.
The four schools agree on this.
Explanation
Ants have a special mention in Islam. A whole surah, an-Naml, is named after them, and it tells how Prophet Sulayman smiled at an ant warning its colony. The Prophet ﷺ forbade killing four creatures: the ant, the bee, the hoopoe and the shrike. He also told of a prophet who was bitten by an ant and had the whole colony burned, and Allah rebuked him: because one ant bit you, you burned a nation that glorifies Allah?
From this the Hanafi scholars drew a balanced rule. If an ant has not harmed you, do not kill it; it is makruh. If ants begin to harm, by biting, getting into food or invading the house, there is no blame in killing them. The Fatawa Hindiyya records this as the chosen view.
How to deal with ants at home:
- Start with prevention: clean up crumbs, seal food and block entry points.
- Use deterrents such as chalk lines, vinegar or peppermint to keep them away.
- For a real infestation, ant bait or pest control is permitted.
- Do not pour boiling water or set fire to a nest when other ways work. Killing with fire is for Allah alone.
- Ants you see outside in the garden or on a path should be left alone.
The other schools give much the same answer: harmless ants should not be killed, and harmful ones may be. For other insects and pests, see is it haram to kill insects and is it haram to kill spiders.
The evidence
Quran, Surah An-Naml 27:18
حَتَّىٰٓ إِذَآ أَتَوْا۟ عَلَىٰ وَادِ ٱلنَّمْلِ قَالَتْ نَمْلَةٌۭ يَٰٓأَيُّهَا ٱلنَّمْلُ ٱدْخُلُوا۟ مَسَٰكِنَكُمْ لَا يَحْطِمَنَّكُمْ سُلَيْمَٰنُ وَجُنُودُهُۥ وَهُمْ لَا يَشْعُرُونَ ﴿١٨﴾
Until, when they came upon the valley of the ants, an ant said, "O ants, enter your dwellings that you not be crushed by Solomon and his soldiers while they perceive not."
The Quran honours the ant by telling its story.
Sunan Abi Dawud 5267
Grading to be checked... نهى عن قتل أربع من الدواب النملة والنحلة والهدهد والصرد ...
"He forbade killing four creatures: the ant, the bee, the hoopoe and the shrike."
Ants that do no harm should not be killed.
Sahih al-Bukhari 3019
Sahih... قرصت نملة نبيا من الأنبياء فأمر بقرية النمل فأحرقت ...
"An ant bit one of the prophets, so he ordered the colony to be burned."
Allah rebuked him for punishing a whole colony for one ant.
Sahih al-Bukhari 3016
Sahih... إن النار لا يعذب بها إلا الله ...
"Only Allah punishes with fire."
Burning ants is not allowed.
Where the ruling is recorded
- al-Fatawa al-Hindiyya, Kitab al-Karahiyya, chapter on killing animals. Killing an ant that has not harmed is disliked; if it harms, there is no blame; throwing it in water is disliked.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.