Over time this can damage the spine and lead to the growth of new bone. In some cases this can cause parts of the spine to join up (fuse) and lose flexibility (ankylosis).
It's not known exactly what causes AS, but in many cases there seems to be a link with a particular gene known as HLA-B27.
Research has shown more than 9 out of 10 people with AS carry a particular gene known as human leukocyte antigen B27 (HLA-B27).
Having this gene doesn't necessarily mean you'll develop AS. It's estimated 8 in every 100 people in the general population have the HLA-B27 gene, but most don't have AS.
It's thought having this gene may make you more vulnerable to developing AS. The condition may be triggered by one or more environmental factors, although it's not known what these are.
Testing for this gene may be carried out if AS is suspected. However, this test isn't a very reliable method of diagnosing the condition because some people can have the HLA-B27 gene but not have ankylosing spondylitis.
Read about how ankylosing spondylitis is diagnosed.
Can ankylosing spondylitis be inherited?
AS can run in families, and the HLA-B27 gene can be inherited from another family member.
If you have AS and tests have shown you carry the HLA-B27 gene, the chance of any children you have developing the condition is less than 20%.
If you have AS but don't carry the HLA-B27 gene, the chance of any children you have developing the condition is less than 10%.
If you have a close relative who has AS, such as a parent or a brother or sister, you're three times more likely to develop the condition compared with someone who doesn't have a relative with the condition.