Gareth Jones, past president of the National Association of Head Teachers Cymru, said: "Some schools play the figures game and reorganise to make a class of 30."
He said there were also fears that school closures and mergers, along with tighter school budgets, could drive class sizes up in the long term.
Mr Jones, who will retire from his post as head of Ysgol Derwen in Flintshire this Christmas, said the result of juggling pupil numbers meant more mixed-age classes in Wales - something that was unpopular with staff and parents.
"Many teachers would prefer to teach 31 single-age pupils rather than 29, or even 25, who are mixed age," he said.
His criticisms follow the release of the latest Assembly government figures, based on a head count in September, which show that after exceptions allowed by law, just four out of 3,994 infant classes in Wales had more than 30 pupils. Within junior schools, 58 such classes exceeded the 30 limit.
Education minister Jane Hutt is celebrating after almost hitting a 2001 target of having every infant class in Wales with 30 pupils or fewer. "I'm considering what steps may be necessary to secure the target in the future," she added in response to the junior class figures.
But opposition AMs are less than happy with progress since 1999. Alun Cairns, Conservative education spokesman, said during a recent Assembly debate: "Such a strict limit has taken away the freedom of heads and governors to manage in a way that best suits their needs.
"A school is forced to mix and split pupils between age groups. I do not think it is right for politicians to direct heads over this."
The Senedd debate was called by Lib Dem education spokeswoman Kirsty Williams, who argued that class sizes should be a maximum of 25 at infants and juniors.
"If the government was serious about reducing sizes there would have been a target in the One Wales document," she said.
Ms Williams claims an upper limit of 25 would benefit 48,000 infants and 80,000 juniors.
"We would increase funding in the delegated budget," she said. "I think the settlement will have a knock-on effect on schools as most education money goes on funding staff salaries."
The Lib Dems had voted unanimously to cap primary class sizes to 25 if it had won May's Assembly elections.
Mr Jones also fears a continuing drive for smaller classes could be threatened by tight budgets.
"Unless there's a full commitment of resources, it's difficult to implement the policy," he said.
A financial emphasis on the foundation stage for three to seven-year-olds will put a huge strain on school budgets, he said. And there is concern about falling rolls and school mergers.
"We're struggling - Flintshire is the worst-funded authority in the country," added Mr Jones.
Ms Hutt said: "The government pledged to cut class sizes after introducing a September head count in 1999.
"However, short-term exceptional circumstances means there will always be a small percentage of infant classes of more than 30.
"Of the four classes in breach of the law on the day of the count this year, all are expected to comply with the limit before next term."