Why does a gas get hot when suddenly compressed? What is happening at the molecular level? My guess is that the molecules of gas all have the same speed as before, but now there are much more collisions per unit area onto the thermometer, thus making the thermometer read a higher temperature. If this is so, then density is directly related to temperature when a substance experiences a change in density.
Is this the case?
 A: Because you are doing work to compress the gas, and the energy has to go somewhere. The molecules speed up because they collide with the wall moving forward--- if you move a wall forward, a ball which bounces off the wall reflects going faster by twice the speed of the wall, because if you move along with the wall, it reflects at the same speed.
Answers to comment questions


*

*After the gas cools off, the gas molecules are moving at the same speed as before.

*The second question is a form of Maxwell demon. If you know when the molecular collisions come with such precision that you can move the wall when the molecules will not bounce, you can compress the gas without doing any work. But in order to do this, you must get and store the information about where all the molecules are, a process which requires a huge amount of entropy production. The information about the molecules allows you to reduce their volume without increasing their energy.

*In any situation where classical mechanics works, for kinetic energy of gasses in particular, the temperature is just the same as the average molecular kinetic energy. For all nonrelativistic systems, the average kinetic energy in each atom is $3T\over 2$ in Boltzmann units (k=1). This is a special case of the equipartition law--- every quadratic degree of freedom gets ${kT\over 2}$ energy in equilibrium. Because of the relation between temperature and kinetic energy, the speeds of molecules in two gasses at the same temperature are the same. So after the gas comes to equilibrium with the surroundings, it has the same average speed for the molecules independent of its volume (this is a molecular kinetic-energy potential-energy separation theorem, which is even true when the material liquifies or solidifies, at least at room temperature  where normal solids obey the Dulong Petit law).


Entropy increase
There is a second way to understand the temperature increase. When you squeeze the gas, you are increasing your knowledge of where the molecules are, you are decreasing their wandering volume. This means that, if nothing else happens, you decrease their entropy. So something must have happened to make you know less about the state of the universe. If they are not allowed to dump heat and entropy into the exterior universe, the only thing that can happen is that they move faster, increasing your uncertainty about how fast they are going.
The decrease in entropy with a decrease in volume from $V_i$ to $V_f$ is
$$ N\log({V_f\over V_i}) $$
This is intuitive--- the logarithm of the number of configuration is the log of $V^N$ (ignoring an N! denominator from indistinguishable particles.
The increase in entropy from a change in temperature from $T_i$ to $T_f$ is given by
$$ NC_V \log({T_f\over T_i}) $$
Where $C_v$ is the rate of entropy increase per unit temperature. So that the relation that the entropy is constant gives the adiabatic expansion law: $V\over T^{C_v}$ is constant, that is, the ratio of absolute temperatures before and after is a certain power of the ratio of the volumes after and before.
I should point out that if you move the piston extremely quickly, at comparable to the speed of sound of the gas, you will produce extra heat in addition to the minimum necessary to ensure the entropy doesn't go down. The extra heat can be understood in two equivalent ways:


*

*you are overcompressing a thin skin of gas near the piston, that momentarily exerts a greater back-pressure on the piston than the gas would normally if you did things slowly. So you are doing more work to compress the gas quickly.

*You are learning more about the positions of the molecules from the slow rate of pressure relaxation--- you know that a large fraction of the volume of the gas is mushed near the piston.


This is a classical more-you-know less-you-know statement, that the more precisely you know where the molecules in a gas are, the less precisely you know how fast they are moving (the hotter the gas gets), at constant information (entropy). This is not the Heisenberg uncertainty principle, it is just classical thermodyanamics, and here the knowledge interpretation is exact, because the entropy is a measure of classical knowledge you have about the microstate. The quantum mechanical uncertainty principle is not a statement of ignorance about hidden variables, at least not in any obvious way, so it doesn't have a precise informational interpretation like this does.
A: temperature is the measure of speed of molecules. when you compress the gas molecules start moving faster, which is the same as saying the temperature increases.
why do molecules start moving faster? there are many ways of explaining this. here's one. when molecules are squeezed into a smaller volume their location is now more certain, it's locked in a smaller space. we seem to get more order and less chaos? this should come at a price, and it does: the molecules resist to being ordered. so they pay back by moving faster. so, in the end there no more order than it was before. the nature resists order.
A: The reason why a gas heats up when it is compressed into a smaller space, is because the ambient heat that the gas possessed in its original volume, has now been confined to a smaller volume—same amount of heat but now more concentrated—the temperature goes up. When the vessel storing the newly compressed gas cools off to the ambient temperature of its environment, energy in the form of heat is lost to the environment. If the air is now released into the atmosphere, it expands from its compressed state to resume the volume that it previously occupied—except that it can't because it has lost energy. In order for the gas to occupy its original volume, it requires heat from the surrounding environment—which may include your hand, which is why the expanding gas feels cool—it's sucking heat energy from your body.
A: The gas gets hotter because the energy has no where to go and it must convert into heat. The molecules bounce back and forth with one another creating more and more energy and less space, so the molecules began to compress through the helical rotors.
