In most ATMs it is stored in sealed, tamper-proof trays which have a security mechanism that the ATM allows to dispense. When the ATMs are stocked, the courier company simply exchanges cassettes. There are no wrapped stacks of cash visible. So essentially what happens is, the ATM is initially loaded with x amount of cash. When the level drops below a certain level, the courier is dispatched to refill the ATM. They go exchange the cassettes and the pulled cassettes are taken to a secure location where the remaining cash is counted and the totals reconciled with what the ATM says it dispensed. If the totals don't match, they WILL find out why via surveillance tapes and security seals. The secure part of the ATM where the cash is built inside a safe which is alarmed and actively monitored. That is why you see reports of ATM theft. You're less likely to get caught if you steal the entire ATM and take it to a location where you have time and privacy to force entry.
Historical fact - before the ATMs moved to Windows XP, nearly all of them ran on OS/2, as recently as 2004.