A thermos does not know whether you want coffee hot or lemonade cold.
It does the same job in both cases.
It slows heat transfer.
Heat naturally moves from warmer places to cooler ones
Put hot coffee in a normal cup and heat begins moving from the coffee into the cooler room.
Put ice water in the same cup and heat from the room moves into the colder drink.
A thermos slows those exchanges.
The vacuum reduces conduction and convection
A typical vacuum bottle has an inner container separated from an outer wall.
Most of the air is removed from the space between them.
With very little matter in that gap, heat transfer by conduction becomes much harder.
Convection is also greatly reduced because there is not enough air in the space to circulate normally.
Reflective surfaces reduce radiation
Heat can also travel through electromagnetic radiation.
Reflective surfaces can reduce some of that transfer by reflecting thermal radiation rather than absorbing and emitting it as readily.
The stopper matters
The opening is one of the easiest places for heat to move.
An insulated stopper or lid reduces conduction and air exchange there.
A beautifully insulated bottle with the cap left off is mostly an expensive cup.
Why does the same bottle keep things cold?
Because “cold” is not a substance the bottle stores.
If the drink is colder than the room, heat wants to move inward.
The thermos slows that movement.
If the drink is hotter than the room, heat wants to move outward.
The thermos slows that too.
This is the same basic world of heat transfer behind why metal feels colder than wood, where the rate of heat movement changes what your skin feels.
Does a thermos keep a drink at exactly the same temperature forever?
No.
It slows heat transfer.
It does not eliminate it completely.
Over enough time, the contents still move toward the temperature of the surrounding environment.
So a thermos does not create heat or cold.
It simply makes heat much harder to move.
And that’s the short explanation.
Related explanations: Why does metal feel colder than wood?, Why do ice cubes crack in a drink?, and Why does a jar lid pop when opened?