The Navajo were not the first Native American Code Talkers to use code to communicate in wars. In WWI, other Native American tribes had been used as code talkers, but after the war, German spies were sent to learn Native American languages.
Philip Johnston introduced the Navajo Code Talkers idea in 1942. He knew that Navajo was perfect for a code to conceal the understanding of US secrets and operations. Despite some concern about spy activity that might learn the code, Maj. Gen. Clayton B. Vogel approved Johnston's proposal to use the Navajo Code Talkers in WWII.
“Johnston believed Navajo answered the military requirement for an indecipherable code because Navajo is an unwritten language of extreme complexity. Its syntax and tonal qualities, not to mention dialects, make it unintelligible to anyone without extensive exposure and training. It has no alphabet or symbols, and is spoken only on the Navajo lands of the American Southwest.”
(“Navajo Code Talkers," April 16, 2020)
The Marines recruited Navajo men to become code talkers. In the words of Code Talker Peter MacDonald, “[The] Marine Corps recruited 29 young Navajos, not telling them what they are... being recruited for, because this was a top-secret operation. They were just asked, ‘You want to join the Marines? You want to fight the enemy? Come join the Marines.’ So they volunteered.”

The Navajo men memorized a book of code containing over 250 words. The Code Talkers were put in simulated battles to make sure they were ready for combat communication. The Code Talkers were capable of encoding, transmitting and decoding a message in 20 seconds. Machines at the time could take up to 30 minutes, yet the Code Talkers were able to do it in a fraction of the time. Because of their success in quick communication and the complexity of the code, 15 of the original 29 Navajo Code Talkers were sent overseas to serve in WWII and many more followed.
(The original 29 Navajo Code Talkers are sworn in at Camp Wingate, New Mexico, Mashable.com, Alex Arbuckle)

(Navajo Code for planes, cia.gov, November 6, 2008)

(Navajo Code for ships, cia.gov, November 6, 2008)
“As part of their training, Navajo code talker recruits had to learn a unique codebook that had to be developed for them to convey the many essential military terms and concepts of their combat messages. The codebook was strictly classified and could be used only in the classroom. It could never be taken into the field. The code talkers thus acquired a new military dialect of the Navajo language that was unintelligible to regular native Navajo speakers. The code talkers had to memorize the new usages of their language and become adept at using them quickly while under the stress of combat.”
("Navajo Code Talkers Play Instrumental Role in World War II.," 2017)
Not everyone accepted the idea of the Navajo Code Talkers serving with white soldiers. Some thought the Marines would be unable to trust the reliability of the Navajo language. Even though the Navajo were key to victory on the battlefield, the soldiers that received credit were the white men of the Marine divisions, instead of the Navajo who fought alongside the white Marines in battle.
One colonel stated that the supposed primary advantage of the code talkers over the encrypted system— speed— was actually of little benefit in the field. When speed was of the essence, messages were usually sent uncoded because the enemy would not have time to intercept them and respond. The colonel also was reluctant to endorse a proposal that would have "combat directing officers depending on an order being translated" in a language that they themselves had no chance of understanding.
("Semper Fidelis, Code Talkers," National Archives, 2001)