It's no secret that the Reagan administration would like to bring costs at the Department of Housing and Urban Development "under control," a policy reflecting, depending on one's attitude, prudent fiscal management or niggardliness toward the needy.

But quite apart from whether it's a good idea, the task of figuring out what the costs are so they can be cut is proving difficult. The forest of programs that has grown up in 40-plus years of federal housing aid contains fiscal thickets in which the unexpected can lurk.

Take, for instance, the 221(g)(4) program. Not exactly a household name, 221(g)(4) was written into the National Housing Act in 1954 to encourage lenders to make loans for multi-family housing.

The program provides that a lender who makes such a loan can come back to HUD after 20 years and, if the loan is not delinquent, exchange it for debentures paying current market rates.

In times of stable interest rates, the provision seemed innocuous. It offered lenders some protection if rates rose and it gave them the assurance that down the line they would be able to trade in qualified loans for more liquid debentures--for example, bonds.

Interest rates, however, are no longer stable, and the gap between current market rates and those on the loans--some of which are as low as 5 1/4 percent--has grown large. The result, as one observer put it, is the potential for a "very large hit on the government."

But nobody knows exactly how large. The General Accounting Office has looked at the volume of eligible loans. It calculates that if every one were turned in and the interest rate HUD had to pay averaged 10 percent (it is now 9 3/8), the department's "net cash outlay" could come to more than $6.9 billion by the year 2013.

It seems unlikely, though, that lenders will turn in anything approaching that number of loans. Loans may be turned in only when they are between 20 and 21 years old, so a certain number of lenders probably are going to miss the boat. Some loans will fall into delinquency and become ineligible to be turned in. Others will have been refinanced or paid off.

HUD officials say that of the multi-family loans written in 1963, five are eligible for this "assignment option." Of those from 1964, four remain, and from 1965, eight.

The cost of the program remains imponderable, though. And because no one can predict interest rates 20 years out, the mortgage insurance premiums HUD requires in the 221 program have ignored the assignment option. Interest rates, one HUD official said, are "an uninsurable risk."

HUD officials say they believe that the program is no longer necessary. Mortgage lenders today can easily sell a non-delinquent loan into the secondary market, and most do, eliminating both interest rate risk and the liquidity problem, officials say.

For the past two years, HUD has proposed legislation eliminating the assignment option. But the housing authorization bill didn't pass last year, and this year's Senate version, which eliminates the program, is bogged down. (The House version of the bill would not eliminate the program.)

HUD officials said that they don't expect any controversy over eliminating the provision. "The problem is," said one, "we can't get a housing bill."