Briefly defined as the 'art or practice of preparing or reading messages in a form intended to prevent their being read by those not privy to secrets of the form and the science of devising methods and means for this,' by Webster's Lexicon.
Until the mid 19th century, this was a subfield of communications field dominated by theologians, spies and lurking courtiers. David Kahn's 1967 classic The Codebreakers treats this pre-history very well in a few chapters (pp. 71-156). Needless to say, upto mid-19th century code making truly was as much an art as it was a science: an obscurant's patchwork of the odd mathematical formulas, antique word and letter tables, unique and inspired clockwork, and often pseudo-philosophical literature.
While enormously entertaining for historians of the secret society, the dark arts were of little or no interest to common folk; encryption and the use of cipher systems attracted the odd criminal agent, a subset of the diplomatic corps to various nations and a curious mix of scientists and hobbyists.
The sea change began with the use of the electric telegraph. An entire technical infrastructure arose between financial institutions and centres of political power to transmit intelligence quickly. The means of transmission were themselves impossible to secure. Hence the need to encrypt.
The Swiss (given the importance of secure finance and private banking) were particularly quick to innovate here. If the US and UK were the pioneers of telegraphy, various Swiss firms soon became expert producers of niche electro-mechanical encryption devices. Some communiques called for something a bit more sophisticated than Morse Code.
And of course, there was the military value of secure communications. Two world wars dramatically changed the significance of the field forever, proving what some analysts and engineers had been saying for some time; information could be treated and manipulated 'as physical,' that it had to be considered another front of the conflict, that its collection in every obscure and occluded form had to be taken very seriously.
The mobilization and armament of data did not cease there. As the Cold War spread first through Europe and then the rest of the world; encryption of private communications and cryptanalysis became a staple expenditure of both sides.