Air compressors work by forcing air into a container and pressurizing the container. Then, the air is forced through a hole in the tank, where the pressure increases. Think of it like an open balloon: compressed air can be used as energy when released.
They are powered by an engine that converts electrical energy into kinetic energy. Similar to how a combustion engine works, it uses a crankshaft, pistons, valves, heads, and connecting rods.
From there, compressed air can be used to power a variety of equipment. Some of the more popular choices are nails, wrenches, sanders, and paint sprayers.
There are different types of air compressors and each has different specialties. In general, the differences aren't too severe: it all comes down to how the compressor handles air displacement.