The device used by the Spy in order to disguise is known as The Disguise Kit. This kit contains a few sticks of his iconic cigarettes, along with a not often mentioned piece of technology known as the Spytron 3000:

Although not much is revealed about it, this device is a technological breakthrough in infiltration, giving the Spy this great power of tricking the enemy team into seeing whoever the Spy wants them to see.
Seeing as how the disguise is achieved technologically, and based on the visual effects of cloaking (see Meet the Spy at 2:09), the most likely cause of the disguise is in the form of a holographic projection. As for why the teammates can see the the masks and "undisguised body", we can only speculate: perhaps this is caused by an adjustment to the hologram, tuned to a frequency known only to the own team, or perhaps it's a representation of a close familiarity with the Spy by his own team members (I would recognize that walk anywhere; that's my friend, Monsieur Blu Spy, not an enemy Pyro).
But then what are the masks used for? And if the masks aren't small enough to be kept in his Disguise Kit, then where does the Spy then get them from you ask? Don't ask. Perhaps the same place weapons in the secondary slots when they aren't holding on to them. (which might explain why the running speed of the Heavy Weapons Guy is so slow even when he is holding a smaller weapon...)