The back pain and stiffness related to ankylosing spondylitis (AS) can make getting to sleep seem like searching for a mythical creature in a fantasy world called slumberland. And if you do find sleep, staying in that blissful state is whole other challenge.

But a good mattress can give you a leg up in the battle. Here’s what to look for in a mattress to help you sleep better with AS.

Sleep disturbances are common with AS. Yet getting good rest is so important. As if you didn’t know that already!

A lack of adequate sleep can exacerbate AS pain the next day, which can then make it even harder for you to fall or stay asleep the next night. In short, chronic pain fuels sleep issues, and sleep issues fuel chronic pain. Talk about a vicious cycle that can make you want to scream.

But the right mattress — one that’s in good condition and doesn’t torque your spine — can ramp up your comfort when you’re trying to get your Zzz’s. It can interrupt that cycle of pain that leads to loss of sleep.

Nothing lasts forever, and mattresses have a pretty short lifespan. A mattress is considered old and in need of replacing after 5 to 9 years, depending on the type and level of wear.

An old mattress can sag or bow, which can greatly mess with your spine. And if you’re sleeping on something that’s contributing to less than satisfactory slumber, you may want to invest in a new bed.

When you start to look at upgrading your mattress, the options out there can seem overwhelming at first. The cool thing is that many mattress companies nowadays have a no-risk try-out period. That means you can try sleeping on it and return it for free if your spine isn’t happy.

Knowing what kind of mattresses are out there and their pros and cons can also help.

Foam. Foam (also called memory foam) mattresses are known for their pressure-relieving feel that conforms to your body and “bounces” back when you change positions. Foam mattresses are great for side sleepers because they support your curves for spinal alignment.

They come in a variety of firmness levels to fit your comfort needs. Another great thing about foam mattresses is that they often nix motion transfer. If you shift a lot in your sleep, you won’t risk disturbing your sleep mate — or vice versa.

Latex. Latex mattresses are similar to foam options, except that they’re, of course, made of latex.

Latex generally offers a bit more support than foam, and the material retains less heat. So if you run hot, you may prefer an option like latex over foam, unless of course you have a latex allergy (which is not uncommon).

Gel. Gel mattresses are like foam and latex in that they conform to your body and provide that bounce back. They come in a variety of firmness options.

The added bonus of gel mattresses is that they actually have a cooling effect. So if you have AS-related night sweats, a gel mattress can keep you cool while you sleep.

Innerspring. Innerspring mattresses have coils that compress when you’re on the mattress and release when you get up. Coil mattress technology has been around for ages, but it has improved over the years to avoid those annoying squeaks.

You’ll also find subtypes, like pocketed coils, which provide extra support but help mitigate motion transfer.

Hybrid. A hybrid mattress combines the traditional support of an innerspring mattress with the plush feel of foam, latex, or gel.

In some cases, the coils are even encased in foam for added cloud-like softness that also disperses weight. Hybrid mattresses tend to offer a lot of customization so you can get the exact kind of sleep experience you want.

For AS, a mattress that has that just-right Goldilocks level of balance between firmness and softness is typically best. A mattress that’s too firm won’t mold to your body, and one that’s too soft won’t properly support your tender spine.

Look for a mattress that’ll evenly distribute your weight to help relieve pressure on your joints. When you’re researching options, check the manufacturer’s recommendations for weight. Many companies offer specific mattresses for larger, taller, and curvier folks.

The right mattress for you will largely depend on your preferences. Think about whether you sleep hotter than a Hot Pocket. If so, a gel option, or a hybrid with gel, may be a good fit.

Many mattress options can also be paired with an adjustable base. If you prefer to prop up your torso or legs, an adjustable base will cradle you without adding pressure on your joints. It’s a good idea to discuss your mattress options with your doctor or physical therapist.

How you receive your mattress may also be important. Many manufacturers now offer a bed-in-a-box option. This type of mattress is easily shipped to your home in a box, and it decompresses when it’s removed from the package.

Most of these brands offer a no-risk-trial period for 30 days or more, and they’ll collect the mattress free of charge if you dislike it. Other manufactures offer a white-glove delivery service that will set up your bed for you. This is important if lifting or maneuvering is a struggle for your spine.

A better mattress is just the first step to getting better sleep with AS. For one thing, it may help eliminate the need for you to use a pillow, which can unnecessarily crane your neck.

Experts recommend that people with AS sleep on their back, but if this isn’t comfortable for you, you have to go with what works. But sleeping on your stomach should be avoided since it messes with spinal alignment and can leave you feeling stiff and sore when you wake up.

If joint pain in your limbs is plaguing your sleep, relieve some of that pressure by sliding a pillow under or between your knees, depending on your sleep position. Pillows can cushion any joint. Don’t be afraid to get a little creative!

For multiple reasons, AS can contribute to night sweats in some people, which can disrupt sleep. If this is you, sleep with layers you can peel off, rather than just a giant comforter, and invest in cooling sheets made of breathable fabrics.

Create a bedtime routine that helps you wind down. Maybe that means taking a warm bath, drinking a favorite cup of herbal tea, or listening to a meditation app.

Finally, you may also want to invest in a noise machine that blocks out city sounds, like that early morning garbage truck. As an added bonus, every time you flip that machine on, your mind will know it’s time for bed.

Sleep seems like it comes so naturally to some. But if you have AS, you might know all too well what it’s like to have insomnia.

AS pain can keep you from falling asleep or it can jolt you awake in the middle of the night. But the right mattress can become your secret bedtime weapon, and better sleep is always worth the investment.