Iʿtikāf is only valid when performed inside a mosque. However, if you are unable to then if you isolate yourself (called khalwah) in the prayer area of your house and spend much of your time worshipping Allah the way you would in iʿtikāf, then you may hope that Allah accepts this as having a similar reward to if you were able to do it in a mosque (masjid).
What the Qur’an and Sunnah Say
Allah says, “Do not be intimate with them [wives] while you are observing iʿtikāf in mosques.” (Qur’an 2:187)
Shaykh Mustafa Umar