Lothian and Borders Police launched the investigation after the documents were discovered during routine monitoring of internal communications.
The force said a 51-year-old officer was suspended while further enquiries were carried out, while a total of 16 others face misconduct charges. Four civilian staff are also being investigated.
All those involved belong to G Division, which employs 249 police officers and 47 police staff and covers the Scottish Borders. The group is made up of both men and women.
Deputy Chief Constable Bill Skelly said the content of the emails was a serious matter and that some officers and staff had fallen below expected standards of behaviour.
He said: "It is of huge disappointment to me, the force, and I am sure, the communities we serve, that emails of a racist and sexist nature were circulated on our system.
"I consider this to be very serious and have instructed that a 51-year-old police officer is suspended and that further enquiries should be carried out. Initial work has identified another 20 individuals – 16 officers and four police staff – who appear to be involved.
"They have been spoken to and advised that they are subject to misconduct enquires.
"While these enquires are ongoing it would be inappropriate to comment further."
He added that guidelines were in place to ensure that people using police systems did not send inappropriate material. He said: "The vast majority of Lothian and Borders police employees are dedicated to their communities and act at all times with the utmost respect.
"Unfortunately there are occasions when a very small minority fall well below the standards we expect.
"I would like to reassure the public that when this happens we consider their behaviour unacceptable and deal with the issue with the seriousness it deserves. All staff of Lothian and Borders Police receive extensive training and there are clear guidelines in place on email and internet use."
Lothian and Borders Police is now in consultation with its partner organisations and representatives of community groups to decide on what additional measures they can bring in to improve online behaviour among its staff.
Contextual targeting label: