Hello Ameen,
the main difference is that "in dem" or "im" is a prepositional phrase, where as "indem" (notice that it is written as one word) is a conjunction.
"in dem" or "im" means "in the", where as "Indem" means by, by doing this"
For example.
Die Katze ist in dem Haus - The cat is in the house.
Ich lerne Deutsch, indem ich viel übe - I learn German by practicing a lot.
Hope this helps :)