Are they illegal? No. Are they highly regulated? Yes.
Contrary to popular belief, fully automatic weapons are NOT illegal. They are however HIGHLY regulated. Full auto weapons have been regulated with three different pieces of legislation. The first was the National Firearms Act of 1934, then the Gun Control Act of 1968, and finally the Hughes Amendment in 1986. In essence, what these three laws have done is to say respectfully that fully automatic firearms must be taxed and regulated, cannot be imported from outside the United States, and can no longer manufacture and/or register new/existing full auto weapons with the federal government (BATFE).
In order to legally own one, you must first find one that you wish to buy. For it to be legal, it must have been made and registered with the BATFE prior to 19 May 1986. These are what are known as transferrable NFA or Class III items.
Your next step will be to negotiate a price with the buyer. Most buyers have their prices set pretty firm and the going rate for a M16 varies by condition and model (M16A1, A2, AR-15 conversion, etc). A brand new, unfired, factory Colt M16A2 is going to run you about $18,000+ while a used AR-15 conversion will run you about $9,500-$13,000+. You will just have to shop around and look for the best deal out there.
Once you find one and negotiate a price you will need to pay the seller. Depending on if you are buying the item from out of state or not, you may also need to find a local Class III FFL/SOT to handle the transfer. NFA/Class III items CANNOT be shipped or carried across state lines without the proper prior approved paperwork. If buying out of state, you would need to have it transferred to a local seller who would then transfer it to you. Once you have found a FFL/SOT if needed, you will need to pay the seller. Unlike with other firearms where you can often do installment payments for years or put it on a credit card, most NFA sellers want full funds up front although some are willing to work with you and do half now, half when the paperwork comes back. At best, you are looking at half up front before he will even start the paperwork.
Once the seller is satisfied with the payment plan and has his funds, he will begin the paperwork. This requires a little bit of work on your end. You will need to get a few things in order for the process to be complete. You will need to get two sets of fingerprint cards done, two passport photos, and fill out a Form 4 (to include the signature of the CLEO of the area you live in) and write a check to the Department of the Treasury for the $200 transfer tax. It is this special tax that will allow you to legally own the weapon. Once you have all this together along with the required paperwork from the seller, you will ship it all to the BATFE who will then have one of their 10 or so inspectors sit down and review it. Any little error will cause it to be rejected and sent back. This is where the frustration begins as the wait starts. It generally takes anywhere from 50-90 days for them to process an application. The main thing that they will be doing is running an extensive background check on you through the FBI criminal database using all your information as well as your fingerprints.
Once the paperwork finally comes back, the seller can then legally ship/transfer the weapon to you. You CANNOT take posession of it before this time or it will be the same as being in possession of an unregistered machine gun which carries a stiff penalty in federal prison.
And that is all there is to it. Once you receive the tax stamp, always makes sure you keep a COPY with the weapon at all times no matter where it goes. Also, remember to keep the original in a SAFE place where nothing will happen to it as the BATFE does not replace lost, stolen, or destroyed tax stamps.
The above advice assumes you are buying in state. If buying out of state, the process is the same, except that you will be required to do two to three transfers. One from the seller to a Class III FFL/SOT if he is not already one, then one from the FFL/SOT in his state to an FFL/SOT in your state, and then from your local FFL/SOT to you. There is no wait time or transfer tax between FFL/SOT's. This means that you will basically only be waiting on the time it takes for two transfers if buying out of state.
If you want to be able tp purchase new full auto weapons, you will need to apply for a FFL/SOT permit from the BATFE. Getting one isn't really all that difficult, except that you need to deal in NFA items and not just buy them. If you only buy and don't sell, then the BATFE can get you on tax evasion. You must also get requests from law enforcement agencies or military units before purchasing them even with an FFL/SOT. This is because FFL/SOT is not exactly a free license to purchase full auto weapons. It merely means that you are an authorized dealer to provide them to law enforcement agencies. However, there is nothing that says you cannot take them out for some fun when not demoing them for the police.