Sir Sidney Ruff-Diamond (Sid James) is Queen Victoria's Governor in the province of Khalabar near the Khyber Pass. The province is defended by the feared 3rd Foot and Mouth Regiment (The Devils in Skirts), who are said to not wear anything under their kilts. When Private Widdle (Charles Hawtrey) is found wearing underpants after an encounter with Bungdit Din (Bernard Bresslaw), a Burpa chief, the Khasi of Khalabar (Kenneth Williams) makes plans to use this information to incite an anti-British rebellion. He aims to dispel the "tough" image of the Devils in Skirts by revealing that contrary to popular belief, they do indeed wear underpants under their kilts.
A diplomatic operation ensues on the part of the British, who fail spectacularly to prove that the incident was an aberration. The Governor's wife (Joan Sims), in the hope of luring the Khasi into bed with her, takes a photograph of an inspection in which many of the soldiers present are found wearing underpants, and takes it to him. With this hard evidence in hand, the Khasi would be able to muster a ferocious Afghan invasion force, storm the Khyber Pass and reclaim India from British rule; but Lady Ruff-Diamond insists that he sleep with her before she parts with the photograph. He delays on account of her unattractiveness, eventually taking her away with him to Bungdit Din's palace.
Meanwhile, the Khasi's daughter (Angela Douglas) reveals to the British that the Governor's wife has eloped, and a team is dispatched to return her and the photo to British hands. Disguised as Afghan generals, the interlopers are unmasked amid a farcical orgy scene, imprisoned, and scheduled to be executed at sunset along with the Governor's wife. Unbeknownst to all, the Khasi's daughter aids their escape in disguise, but Lady Ruff-Diamond drops the photograph on leaving the palace. The group return to the Khyber Pass to find its guards massacred and their weapons comically mutilated, in a rare moment of (albeit tainted) poignancy. All attempts to hold off the advancing hordes fail miserably, and a hasty retreat is beaten to the Governor's Palace.
The Governor, meanwhile, has been entertaining, in numerical order, the Khasi's fifty-one wives, each one of them wishing to "right the wrong" that his own wife and the Khasi himself have supposedly committed against him (though no such wrong took place). After a browbeating from his wife, Sir Sidney calls a crisis meeting regarding the invasion, in which he resolves to "do nothing". A black tie dinner is arranged for that evening.
Dinner takes place during a prolonged penultimate scene, in which contrapuntal snippets of the Khasi's army demolishing the Palace exterior, and the officers and ladies ignoring the devastation as they dine. Shells shaking the building and plaster falling in the soup should not interrupt dinner; the British are not to be put off. Finally, at the Captain's suggestion, the gentlemen walk outside to be greeted by a bloody battle being waged in the courtyard. Still dressed in black tie, Sir Sidney orders the Regiment to form a line and lift their kilts, this time exposing their (implied) lack of underwear. The invading army is terrified, and retreats at once.
It contains much comedy specifically aimed at a British audience. For instance, on entering the Khasi's palace, a gong is struck, at which Kenneth Williams comments 'Rank stupidity' which is a reference to the strongman striking a gong at the start of Rank Organisation films. He also tries to refer to the British Queen by other names of London railway stations, not Victoria, e.g. Queen Waterloo, Euston. He also refers to the pending execution of the rescue team by the 'Death of a Thousand Cuts' by saying 'the British are used to cuts' referring to the cutbacks in Government spending before and probably during the time of the filming. Throughout the film tiffin is used as a euphemism for sexual intercourse, memorably the Khasi rejected an offer of tiffin at one point and said "unlike you British, we are not tiffin-mad".
The 3rd Foot and Mouth Regiment is the fictional Highland infantry regiment of the British Army portrayed in the film Carry On up the Khyber. It is a regiment of Highlanders, known locally as "the Devils in Skirts" for their tradition of not wearing anything under the kilt. The detachment at Khalabar is under the command of Captain Keene (played by Roy Castle), with Sergeant-Major MacNutt (played by Terry Scott) as his Second-in-Command.
The regimental tartans and bonnet badges designed for the Highland regiment in the film 1960 Tunes of Glory were reused by Pinewood's wardrobe department to kit out Carry On Up the Khyber's 3rd Foot and Mouth Regiment. Humorously the unnamed Highland regiment in Tunes of Glory could well have been the 3rd Foot and Mouth!
The remaining scenes were shot at Pinewood Studios. Governor Sir Sidney Ruff-Diamond's residence was actually Pinewood House, the site's headquarters.