now, I have read a lot of explanations on that but still can't really understand why it would happen so if you can give some examples for a such a thing happening. I mean lets say gravity attracts the air and due to air viscosity all of the air gets carried with the Earth but why will the speed be same ?
I have three answers to your question. I'll start with the short and snippy versions first:
Why does the atmosphere move with the Earth?
- Because it already is.
- It isn't. At least not exactly.
The air rotates with the Earth because of conservation of angular momentum.
Because the atmosphere is already more or less rotating with the Earth, an external torque would be needed to make the atmosphere rotate at some speed other than the Earth's rotation rate. You've heard of Newton's first law: An object with no external forces acting on it will move at a constant velocity. The simple rotational analogue of this law is that an object with no external torques acting on it will rotate at a constant rate. Just as an external force is needed to change an object's linear momentum, an external torque is needed to change an object's angular momentum.
This part of the answer says that because the atmosphere was rotating with the Earth today (and 100 years ago), it will keep rotating with the Earth tomorrow (and 100 years from now).
Winds keep the atmosphere more or less rotating with the Earth.
The above answer isn't quite enough. The Earth was rotating quite a bit faster four billion years ago. If the atmosphere rotated in sync with the Earth four billion years ago, conservation of angular momentum alone would dictate that the atmosphere would have retained that high rotation rate. This would mean that we would suffer perpetually fierce winds from the west. We don't suffer those fierce winds. The moderate winds we do suffer provide exactly the torque needed to keep the atmosphere rotating with the Earth.
The atmosphere isn't rotating exactly with the Earth.
That said, we do see persistent winds. The prevailing wind is from the east in some places, but in others, it's from the west. Higher above the surface, the jet streams can move at up to 160 km/h, generally west to east (so faster than the Earth's rotation rate). Even higher up (e.g., where the Space Station orbits), the atmosphere is generally in a super-rotating flow, about 10% faster than the Earth's rotation rate at the Space Station's altitude.
Other planets are even weirder. Venus, for example, has a very slow retrograde rotation. The atmosphere at the surface of Venus is so very dense that surface winds rarely exceed a few km/h. Higher up, it's a very different story. There the winds are very fierce, rotating much faster than Venus's extremely slow rotation rate.
Global circulation of the Earth's and Venus's atmospheres
A picture being worth a thousand words, here are two thousand words on the global circulations of Earth's and Venus's atmospheres:
Both Earth and Venus have a Hadley cell, a cell that moves cool air toward the equator (surface level) and warm air from the equator poleward (from above). The Earth's Hadley cell can't sustain itself all the way to the poles because of the Coriolis effect. Venus's Hadley cell also falters poleward, but not as strongly as does Earth's.
Venus's extremely slow rotation (one Venus sidereal day is 243 day long, one Venus solar day is 116.75 days long) and Venus's close position to the Sun make understanding Venus's atmosphere a bit challenging. As to why Venus's upper atmosphere rotates so very fast compared to Venus itself is still a bit of a mystery. Atmospheric global circulation models have been coerced to yield such a huge super rotation, but whether that coercion was valid remains questionable.