1. Windows 11 (newer versions): Settings, System, Power and battery, Lid and power button controls.
Or Control Panel, Power Options, "Choose what closing the lid does".
2. Choose for On battery and Plugged in: Do nothing, Sleep, Hibernate or Shut down.
3. "Do nothing" lets you use the laptop closed with an external monitor and keyboard.
4. The power button can be set to Shut down, so pressing it doesn't just sleep.
Before putting a laptop in a bag, make sure it's really asleep or shut down. A laptop that stays on in a bag can overheat (see our laptop travel tip).