Ian Fleming, the creator of James Bond, served with British Naval Intelligence during World War II, and his service influenced the character and his stories.
Fleming was recruited into the Royal Navy in 1939 by Rear Admiral John Godfrey, Head of Naval Intelligence. Fleming entered as a lieutenant and quickly promoted to lieutenant commander. Although initially tasked as Admiral Godfrey's assistant, Commander Fleming had greater ambitions. He is widely believed to be the author of the "Trout Memo" circulated by Godfrey that compared intelligence gathering to a fisherman casting for trout. In the memo, he independently came up the plan to use a corpse with false documents to deceive the Germans, originally conceived by another agent and later used in Operation Mincemeat.
"Oh, no. We dropped our secret plans."
Fleming was obsessed with collecting intelligence and came up with numerous ways to do so, some seemingly right out of spy novels. One such mission, Operation Ruthless, called for acquiring a German bomber, crashing it into the English Channel, and then having the crew attack and subdue the German ship that would come to rescue them. Mercifully, it was called off. Fleming was also the mastermind of an intelligence gathering unit known as (No. 30 Commando or 30 Assault Unit, 30 AU). Instead of traditional combat skills, members of 30 AU were trained in safe-cracking, lock-picking, and other spycraft and moved with advancing units to gain intelligence before it could be lost or destroyed.
Fleming was in charge of Operation Goldeneye and involved with the T-Force. These would also influence his work. Operation Goldeneye was a scheme to monitor Spain in the event of an alliance with Germany and to conduct sabotage operations should such an agreement take place. Fleming would later name his Jamaican home where he wrote the James Bond novels "Goldeneye." It would also be the title of seventeenth James Bond movie. As for the T-Force, or Target Force, Fleming sat on the committee that selected targets, specifically German scientific and technological advancements before retreating troops destroyed them. The seizure by the T-Force of a German research center at Kiel which housed advanced rocket motors and jet engines was featured prominently in the James Bond novel "Moonraker."
The movie was much less grounded in reality.
In the actual creation of the character James Bond, Fleming drew inspiration from himself and those around him. Fleming said the character of James Bond was an amalgamation of all the secret agent and commando types he met during the war. In particular, Bond was modeled after Fleming's brother Peter, who conducted work behind enemy lines, Patrick Dalzel-Job, who served in the 30 Assault Unit Fleming created, and Bill "Biffy" Dunderdale, who was the Paris station chief for MI6 and was known for his fancy suits and affinity for expensive cars. Fleming used his habits for many of Bond's. He was known to be a heavy drinker and smoker. Bond purchased the same specialty cigarettes Fleming smoked and even added three gold rings to the filter to denote his rank as a Commander in the Royal Navy, something Fleming also did.
Bond's code number, 007, comes from a means of classifying highly secretive documents starting with the number 00. The number 007 comes from the British decryption of the Zimmerman Note, labeled 0075, that brought America into World War I. Bond received his name from a rather innocuous source, however, an ornithologist. Bond's looks are not Fleming's but rather were inspired by the actor/singer Hoagy Carmichael, with only a dash of Fleming's for good measure.
Fleming did draw on those around him for other characters in the James Bond novels. Villains had a tendency to share a name with people Fleming disliked while other characters got their names from his friendly acquaintances. The character of M, James Bond's boss, was based on Fleming's boss Rear Admiral Godfrey. The inspiration for the single-letter moniker came from Maxwell Knight, the head of MI5, who was known to sign his memos with only his first initial, M. Also, the fictional antagonistic organization SMERSH, takes its name from a real Russian organization called SMERSH that was active from 1943-1946. In the fictional version, SMERSH was an acronym of Russian words meaning "Special Methods of Spy Detection" and was modeled after the KGB; the real SMERSH was a portmanteau in Russian meaning "Death to Spies" and was a counterintelligence organization on the Eastern Front during WWII.
Cover of a 1943 SMERSH Manual
Finally, the plots for many of the Bond novels came from real-world missions carried out by the Allies. "Moonraker" is based on the exploits of the 30 AU in Kiel, Germany, while "Thunderball" has loose connections to Fleming's canceled operation Ruthless. Fleming also ties in his fictional world to the historical one after the war and during the Cold War.
Fleming's novels became very popular during his life and have remained so long after his death in 1964. His work spawned one of the most successful movie franchises in history.