You can press the microphone on/off button on the top of your device to disable the microphone before you go to sleep. Here's what it looks like for the Echo Dot:
Source: FASTILY of Wikimedia Commons, CC-BY-SA 4.0
After pressing the microphone off button, your device will look more like this:

Source: Hedwig Storch of Wikimedia Commons, CC-BY-SA 4.0
Notice the illuminated microphone off button and the red ring. While the ring is red, your device will not be listening at all, until you press the microphone on/off button again. The Amazon Echo will look largely the same, except it's significantly taller. The icon on the microphone on/off button is the same as in the pictures above.
Unfortunately, you can't turn off the Echo's microphone by voice—the button must be physically pressed. Also, you can't turn the microphone back on by voice, because—well—the microphone is off, and can't listen to you, because you told it not to!