The findings from the poll, carried out for Tam Baillie, Scotland's Commissioner for Children and Young People, have led to warnings that pupils may be putting their health at risk by delaying going to the toilet, or because of poor handwashing facilities in some schools.
The report includes an overview of potential health risks attached to poor provision of the facilities in schools, including gastroenteritis, threadworm and dysfunctional toilet habits.
Fewer than half (48%) of pupils said they always felt safe in their school's toilets, while 62% said there were enough toilets all or most of the time.
One-quarter of pupils (24%) said supplies of toilet paper were inadequate, 37% complained of a lack of soap and 33% said standards of cleanliness were poor or very poor.
Supplies of warm water and hand drying facilities were deemed good or very good by 60% and 53% respectively, but 30% of pupils said a lack of working locks on cubicles was a problem.
Mr Baillie said problems with toilet facilities were often cited in his consultations with school-age children. He added: "The inadequacy of school toilets in Scotland, particularly their lack of cleanliness and poor state of repair, was raised repeatedly."
Laws governing school toilet provision date to 1967 and need to be updated, he said.
In the survey of 2154 pupils in years S1-S6, 41% said they used toilets whenever they needed to, while 10% said they never used them and 46% said they avoided the toilets unless they really had to use them.
Some pupils complained the facilities were often locked before or after school and during lessons.
More than half (57%) of pupils said there were school rules about when they were allowed to use the toilet and 89% said they had to ask for permission before going to the toilet during class. Only 36% said they were always allowed, with 18% saying permission was never given. A total of 30% said they were always or sometimes embarrassed to ask, while 18% said they were always or sometimes annoyed about it.
Eileen Prior, director of the Scottish Parent Teacher Council, said: "This is a major issue. Parents are concerned about children not being allowed to use toilets, and about the health risks when basic sanitary requirements are sometimes missing."