When Marion Barry became mayor last month, some top aides looked to the city's $40 million cash balance that Walter E. Washington had bragged about to pay for some new Barry programs. They soon discovered that the money was not there to spend.

The balance was far exceeded by $115 million in bills and payroll costs the city owed as the result of a timehonored practice of running up bills in one fiscal year and not paying them until the next.

Washington, who has boasted of the $40 million balance in several public speeches, recommended that the money be put into a new revolving fund to help pay city bills when funds run low.

The Barry administration was looking to use some of the $40 million for a $12 million summer jobs program for youth and for various other programs not fully funded by Congress last year.

The City Council began to make other plans for the money. John A. Wilson (D-Ward 2), the new chairman of the council's Finance and Revenue Committee proposed legislation to give $20 million of the cash balance back to taxpayers as rebates.

When Barry took office some of his high-ranking aides inspected the books. What they found was that there indeed was $40 million in the city's bank account when the fiscal year ended last Sept. 30 -- but at the same time the city owed $115 million in bills for such things as supplies, building contracts and payroll costs.

The city carried the debt over to the next fiscal year and the $115 million now is being paid.

One year earlier, on Sept. 30, 1977, the city had owed $105 million in such debts, and its cash balance was only $4 million.

The city uses a cash accounting system modeled after the system used by the U.S. government. It is in the process of shifting to a more sophisticated system used by many cities.

The way the city reckons its finances now is similar to the individual who deals with his personal finances simply by figuring the balance in his checking account at any given time, ignoring the rent bill that may be due next week or the electricity bill that may be past due.

Over the years, the District of Columbia has entered a new fiscal year owing many of its creditors for goods already delivered as well as wages that were earned by employes in previous fiscal years.

Yesterday, Mayor Barry served notice that such practice will have to stop.

"While it has been customary in the past for the District to carry forward unpaid obligations of this general magnitude, we are dependent upon the Congress funding it in the following year's appropriation," Barry declared, "and we do not yet know how financial analysts will view the practice when we go to the bond market in another year or two."

The city currently borrows funds from the U.S. Treasury rather than from the private market.

Because of such debts, Barry said he intended "to be cautious and to maintain a reasonable balance between the District budget and revenues available to support that budget."

Despite the large sum owed from the past, Barry said the District of Columbia ended the 1978 fiscal year under the ex-mayor "in the strongest financial position that it has enjoyed in recent years..."

At the District Building yesterday, Barry had his first meeting with Rep. Charles Wilson (D-Texas), the new chairman of the House D.C. Appropriations Subcommittee, which reviews the city's budget. Wilson replaced veteran Rep. William H. Natcher (D-Ky.).

Both Barry and Wilson said no decisions were reached. Wilson said he would endorse the city's proposal to establish a formula under which the annual federal payment in support of the city budget would be calculated and therefore could be predicted by the budget-makers. Lacking a formula, the level of the payment is set each year by Congress.

The meeting was the last of a series by Barry with congressional leaders dealing with District of Columbia matters.