Mayor Marion Barry, facing a shortage of cash that will leave the District government unable to pay its bills by late June or early July, has decided to borrow another $40 million from the U.S. Treasury to keep the city solvent through the summer.

The loan would raise the total borrowed this year to $80 million. The money must either be repaid by Sept. 30 or be added to the city's cumulative deficit which Barry has publicly and frequently pledged would not be allowed to grow. Barry's more immediate concern, however, is to make sure that city payrolls are met and welfare checks distributed during a summer when the city's financial crisis is expected to be at its most acute.

Barry's top financial managers, pelted yesterday with questions at a City Council hearing about why the funds are needed and how they are going to be repaid, argued that the borrowing was a routine administrative step, taken only to ensure a smooth flow of cash through the city treasury during a time of the year when tax collections are traditionally slow.

Virtually every municipality, they said, gets short-term loans in anticipation of repaying them when tax revenues come in. The District is different only in that it does its borrowing at the Treasury, interest-free, while other communities must borrow from banks or issue interest-bearing short term notes.

The proposed loan is similar to loans the city has taken from the Treasury in past years, but this year it comes in the midst of a wide-ranging financial crisis. Pressed to maintain services in a time of inflation and mounting obligations while Barry tries to avoid a tax increase, the District government has been deferring payments to suppliers, holding up on pension commitments and asking Congress for new borrowing authority in an effort to stay solvent through the rest of this fiscal year.

The District has had unique authority to borrow from the Treasury on demand without paying any interest since the early years of this century, and the city has regularly invoked it. The District has borrowed money from the Treasury every year at least since 1961. The highest total in any previous year was $50 million in 1965. As a percentage of the total budget, that figure was actually much higher, representing 18.9 percent of all city spending, while this year's $80 million represents only 5.1 percent of the total budget.

The budget-cutting Reagan administration has asked Congress to terminate the city's authority to borrow interest-free at the end of the 1982 fiscal year, but has not sought to curtail the city's ability to borrow this year. Joseph Mullinix, deputy associate director of the Federal Office of Management and Budget, said yesterday that "we were envisioning a longer-term policy change" and that he knew of no plans to take "unilateral" action that would cut the city off at this time.

Barry and his top financial aides have said repeatedly that the city faces an acute cash crisis this summer.Most of the problem was created when the city used $20 million of this year's tax revenues to pay off an outstanding Treasury loan from an earlier year. It was then forced to use about $35 million more to repay a tax on the income of suburban professionals who work in the city, which was ruled illegal by the courts.

Those two items alone have left the District with a cash shortage of $55 million, which means that even though the city is not overspending this year's operating budget it is still short of cash.

In addition, the city is committed to putting a $30 million quarterly payment into city-managed pension funds on July 1. OMB has insisted that the District make that payment on time so that pension officials can invest the cash, but that obligation will come just when the city's income from tax collections is at its lowest point of the year.

This year the City Council enacted a law which required the mayor to receive council approval before borrowing. Barry has disputed the council's authority to enact such a law, and in March he borrowed without telling the council, which then approved the loan. This time he gave council "notice" of his intent to borrow, but did not commit himself to be bound by any council action.

Philip M. Dearborn, financial counselor to the mayor, Budget Director Gladys Mack and city controller Alphonse Hill refused to be pinned down on whether the mayor would make the loan without City Council approval. Council chairman Arrington Dixon demanded a "yes or no answer," but Mack said only that "the mayor intends to operate within the framework of the law."

Dearborn said outside the hearing room that the request was being made now, weeks before the anticipated crisis, "to give the council time to fool with it. It costs us nothing to draw the funds down early." In fact, it might even be advantageous, since the funds are interest-free from the Treasury and can be invested until they are used. "But it might be disastrous to draw them down too late," Dearborn said, because the city might miss a payroll or a welfare payment cycle.

Despite repeated prods from Dixon, Dearborn said it is imposible to list exactly what bills are to be paid with the $40 million. All revenue, whether from loans or from tax collections, goes into one "cash pool," from which all city bills are paid, he said. The important thing for the council to note, he said, is that approval of the borrowing does not raise the overall budget nor will it change how city money will be spent. Council approval of the loan request is probable, Dixon indicated.