There are few things more disheartening than going to bake chocolate chip cookies or banana bread only to realize that the brown sugar in your pantry is rock solid. But in order to figure out the best way to stop brown sugar from hardening, you need to first understand why brown sugar gets hard in the first place. Brown sugar is essentially white sugar that's been coated with bitter molasses, according to Serious Eats; that molasses is what gives brown sugar its distinctive color and softer, more malleable texture. But when that brown sugar is exposed to air, the molasses evaporates, and that is what makes brown sugar harden. As the folks at The Kitchn explain, "Individual particles of sugar literally become glued to each other as the film between them dries out and the brown sugar hardens into a solid mass."
So how do you prevent your brown sugar from gumming up and hardening into a cinderblock of sucrose? You have to learn how to store your brown sugar properly, keeping it from drying out. The most obvious way to prevent brown sugar from getting hard is by storing it in an air-tight container. You want the container to be on the smaller side, so there's not too much air trapped inside the container, but the shape doesn't really matter—as long as it doesn't allow any air to pass through.
If you want to be extra-certain that your brown sugar isn't going to dry out, you can also invest in a terra cotta brown sugar saver. It's a small disk made of clay that you soak in water for about fifteen minutes before placing in your airtight container of brown sugar. The idea is that the moisture from the disk helps to keep that molasses moist, preventing the sugar crystals from clumping up. Food52 also recommends using a marshmallow to keep brown sugar soft, instead of a terra cotta disk; a slice of bread apparently also does the trick.
Now, if you messed up and didn't transfer your brown sugar from that flimsy cardboard box to an airtight container, and you're stuck with a giant hunk of crystals, never fear. It's fairly easy to soften brown sugar, even if you're in a rush. Domino Sugar recommends putting the brown sugar in an oven-safe container, then baking at 250°F until soft. Use the sugar that you need, but be warned that any sugar you don't use will harden up again as soon as it cools. You can also use the microwave, covering a bowl of brown sugar with two pieces of damp paper towels then tightly covering the whole thing with plastic wrap; nuke it for about a minute, then stir.
It's never too late to start storing your brown sugar correctly, though. For long-term recovery of brown sugar, Domino Sugar recommends moving your hardened brown sugar into an air-tight container, and adding in a piece of bread or a couple of damp paper towels until the whole thing rehydrates. Then you can just keep your brown sugar in that container, and away from air, until you use it all up.