REGION — When faced with capital improvements, municipalities must often borrow money.

Cities and towns with the best credit ratings can expect to pay less interest on their loans than communities with lower ratings.

In Massachusetts, most municipalities hire Moody’s Investors Service or Standard and Poor’s to set a bond rate when they need to borrow money. This bond rate is a third-party opinion on the borrower’s likelihood of default.

The rating agencies analyze financial statements, management capability, fiscal stability, economic condition and other factors. Each town receives a written report from the agency when the rate is set.

Townsend, Ayer and Pepperell all have an Aa3 rating issued by Moody’s.

“Obligations rated Aa are judged to be of high quality and are subject to very low credit risk,” according to Moody’s website. “The modifier 3 indicates a ranking in the lower end of that generic rating category.”

The only higher rating is Aaa. The lowest rating issued by Moody’s is Caa.

Moody rated Townsend in 2014. “The Aa3 rating reflects the town’s above-average financial position, modest residential tax base with average wealth levels, low debt burden, and manageable low net pension liability,” the summary rating rationale reads.

The bond rating company withdrew Townsend’s rating from June 2013 to June 2014. This was because of a delay in completing the fiscal year 2012 audit, Town Administrator Andy Sheehan said.

“The suspension of the rating did not affect any outstanding borrowing and did not cost the town or the taxpayers a penny,” he said. “We made all required payments on time and no bond buyers were impacted.”

Townsend’s total debt is $4 million.

Both Ayer and Pepperell’s ratings date from 2012. Neither town has borrowed since then.

Ayer’s Aa3 rating dates from 2012. It has maintained the rating since at least 2010. The town has not borrowed money since 2012, so there is no newer rating, said Lisa Gabree, town accountant.

Ayer’s total debt is $18.9 million.

The financial picture in Pepperell has changed since it received a bond rating of Aa3 in 2012. The town had about $1.7 million in free cash and stabilization funds. The free cash has not yet been certified, but at most, this year’s total will be $1.35 million, said Town Administrator John Moak.

He does not know if the lower amount would be enough to change the town’s rating if it was done now. He was told that available cash is one of the factors the bond rating companies consider.

Pepperell’s total debt is $230,000.

Other towns were rated by Standard and Poor’s in 2014.

Shirley is rated AA-. It was upgraded from an A+ in March.

Standard and Poor’s changed its criteria around that time, said Town Administrator Patrice Garvin, “A lot of towns got an increase.”

“The stable outlook reflects our view of the town’s average local economy and its strong budgetary flexibility, Shirley’s very strong liquidity along with favorable debt profile further enhances the rating stability,” according to Standard and Poor’s rating summary.

Shirley total debt: $1 million.

Both Groton and Harvard have an AAA rating, the highest issued by Standard and Poor’s.

Groton’s rating was upgraded from AA+ to AAA in August.

“The town is extremely proud of this rating,” said Michael Hartnett, treasurer/accountant. Strong financial leadership, high per capita income and tax collections of almost 100 percent were some of the reasons for the increase.

Groton’s total debt is $19 million.

Over the past 10 years, Harvard’s bond rating has improved from AA- to AA+, said Lorraine Leonard, financial director. In May, the rating was upgraded further to AAA.

Harvard’s total debt is $10.3 million.

Standard and Poor’s website explains the ratings —

AAA — Extremely strong capacity to meet financial commitments. Highest Rating.

AA — Very strong capacity to meet financial commitments.”

The minus sign shows relative standing within the category.

Standard and Poor’s ratings go as low as D, payment default on financial commitments.

Follow Anne O’Connor on Twitter and Tout @a1oconnor.