A fan is a propeller with a large number of blades. A fan therefore produces a lot of thrust for a given diameter but the closeness of the blades means that each strongly affects the flow around the others. If the flow is supersonic, this interference can be beneficial if the flow can be compressed through a series of shock waves rather than one. By placing the fan within a shaped duct, specific flow patterns can be created depending on flight speed and engine performance. As air enters the duct, its speed is reduced while its pressure and temperature increase.
If the aircraft is at a high subsonic speed this creates two advantages: the air enters the fan at a lower Mach speed; and the higher temperature increases the local speed of sound. While there is a loss in efficiency as the fan is drawing on a smaller area of the free stream and so using less air, this is balanced by the ducted fan retaining efficiency at higher speeds where conventional propeller efficiency would be poor. A ducted fan or propeller also has certain benefits at lower speeds but the duct needs to be shaped in a different manner than one for higher speed flight.
More air is taken in and the fan therefore operates at an efficiency equivalent to a larger un-ducted propeller. Noise is also reduced by the ducting and should a blade become detached the duct would help contain the damage. However the duct adds weight, cost, complexity and (to a certain degree) drag.