Instructions written so a machine can carry them out. Also any system where one thing stands for another by agreement.
Old French code, from Latin codex/caudex (the trunk of a tree; a block of wood; and, since wooden tablets were bound for writing, a book of laws); instructions a machine carries out share the name with the oldest bound law-books.
The two senses share a hinge on trust rather than on mechanism — a machine does exactly what it is told whether or not the instruction was wise, and a cipher works only for as long as both sides keep faith with the same agreement, so code is the word for exactness that depends on nothing verifying it in the moment.