Change from a vending machine comes from a mechanism that tracks its coin stock. Here is how it works.
A machine gives change from tubes that collect coins inserted by customers, or from a hopper – a coin store with a payout mechanism. The coin mechanism knows each tube's level and picks denominations to pay the right amount. When coins run short, the machine displays an exact-change message.
Coin tubes
Each tube holds one denomination. Coins accepted by the validator go into a tube, and once it is full, into the cash box.
The hopper
A hopper is a store with a rotating mechanism that pays coins out one at a time. It is used in machines with heavy cash turnover, among others.
When change runs out
The operator refills tubes during service visits. Telemetry can flag low coin levels. Common customer questions are answered on the FAQ (publisher's site) page.
FAQ
Why does the machine ask for exact change? Because the tubes lack the coins needed for change.
Does the machine give change for notes? Usually in coins, if it has a note acceptor and enough coins.