All code is data. But not all data is code.
For example, you can take a digital photo and the numbers represent light intensity across a 2D rectangle. Nobody would dispute that this is data but not code.
Code is a special kind of data which controls behaviour.
... but it's not that simple. Arguably the digital photo controls the behaviour of whatever compression/decompression software processes it, and of the motion of the printer parts if you print it out.
So, wait, isn't controlling a printer exactly the same as controlling a loom? Ha! Got you there!
What is meant by "code" is context-dependent. It seems to have different meanings for different objects (a computer, a loom, a synthesiser, a 3D printer). So here is my attempted definition.
Code:
- is data that expresses a series of steps* in a certain well-defined language
- controls the behaviour of a (real or abstract) machine
- has the capacity to dictate a wide variety of behaviours, relative to the capabilities of the machine.
So I would say yes, a punched card contains code for a Jacquard loom. A digital image is only data for a computer. For an old-fashioned dumb printer, a digital image might be called code, but for modern printers which have advanced configuration and job handling protocols and font loading and typesetting... an actual image to print would probably be considered "trivial" and thus data.
*Code does not actually need to be sequential, but it has to express some kind of process. cf. dataflow architectures, lambda calculus
Edit: How about instructions like "forward, left, right" for the simulated robots that are often used to introduce kids to programming? I would say that for the "abstract machine" that is a robot, they are code, but for the computer, or even the app itself, they are data.
Edit: What about code for DSP chips and FPGAs? It's as far removed from a sequence of steps as you can get—and yet it controls the behaviour of a machine, and is capable of expressing even more behaviours than code for a CPU. It's code.
On the other hand, what about a wiring diagram for a motherboard? I wouldn't call it code... but why?
After some thinking, I realised that there is only one "sensible" way to connect the components together. Reconfiguring it doesn't change the behaviour, it just breaks it. E.g. if you switched the address bus and the data bus, the system just wouldn't work.