Maskelyne joined the Royal Engineers when the Second World War broke out, thinking that his skills could be used in camouflage. He convinced skeptical officers by creating the illusion of a German warship on the Thames using mirrors and a model. He was eventually deployed to the African theatre in the Western Desert, although he spent most of his time entertaining the troops.
In January 1941, General Archibald Wavell created A Force for subterfuge and counterintelligence. Maskelyne was assigned to serve in it and gathered a group of 14 assistants, including an architect, art restorer, carpenter, chemist, electrical engineer, electrician, painter, and stage-set builder. It was nicknamed the Magic Gang.
The Magic Gang built a number of illusions. They used painted canvas and plywood to make jeeps look like tanks — with fake tank tracks — and tanks look like trucks. They created illusions of armies and battleships.
His largest illusion was to conceal Alexandria and the Suez Canal to misdirect German bombers. He built a mockup of the night-lights of Alexandria in a bay three miles away with fake buildings, lighthouse, and anti-aircraft batteries. To mask the Suez Canal he built a revolving cone of mirrors that created a wheel of spinning light nine miles wide, meant to dazzle and disorient enemy pilots so that their bombs would fall off-target.
In 1942 he worked in Operation Bertram, before the battle of El Alamein. His task was to make German Field Marshal Erwin Rommel think that the attack was coming from the south when British General Bernard Montgomery planned to attack from the north. In the north, 1,000 tanks were disguised as trucks. On the south, the Magic Gang created 2,000 fake tanks with convincing pyrotechnics. There was a fake railway line, fake radio conversations, and fake sounds of construction. They also built a fake water pipeline and made it look as if it would never be ready before attack.