ELI5: How do countries devalue their own currency and why would they want to?

r/

I’ve read that sometimes countries intentionally devalue their currency. But I don’t really understand how that works. How can a government just decide that its money is worth less? Don’t the markets decide that?

Also, why would they want to make their own money weaker? Wouldn’t that just make life more expensive for their people?