For many centuries, people developed many different accessories that could be attached to firearms, such as bayonets, telescopic sights, tactical lights etc. What was missing though was a standardized way to attach such accessories to a firearm. The US military decided to change all that and commissioned the Picatinny Arsenal in New Jersey to develop a standard for a mounting bracket that could be used to attach various devices. The Picatinny Arsenal developed a specification for a mounting rail called the MIL-STD-1913 rail, based on some work done by the A.R.M.S company back in the early 1980s. The specification was officially accepted by the US military on February 3rd 1995. This specification was also later adopted by NATO forces as the STANAG 2324 standard. Since the rail specification was developed by the Picatinny Arsenal, people often refer to the it as the "Picatinny rail".
Cross-sectional and side views of a picatinny rail. Click on images to enlarge. Images are in the public domain.
It consists of a rail with a number of raised ridges separated by spacing slots. The raised ridges are shaped like the letter 'T' in cross-section. Devices may be attached by sliding them on to the rail and then clamping them if needed with thumbscrews, bolts, levers etc.
Different models of picatinny rails made by various manufacturers. Click on images to enlarge
Originally, the picatinny rail was meant to be used for mounting telescopic sights and was placed on the rifle's receiver, roughly where the rear sight should be. Nowadays, manufacturers place multiple rails on the firearm, so that many accessories may be attached simultaneously. Incidentally, these rails do not need to be attached to a rifle, many pistols can be fitted with them too.
HK-416 with multiple picatinny rails. Click on image to enlarge.
Image is licensed under the Creative Commons Attribution-Share Alike 2.0 Generic license by user Dybdal at Wikipedia
In the above image, we see a Heckler and Koch HK416N assault rifle used by the Norwegian army. This firearm has multiple picatinny rails on it, as can be seen in the image above. The user has attached a telescopic sight as well as a vertical foregrip accessory to the firearm and there's room to attach other accessories as well, such as a tactical light, laser aiming module etc.
Many rifles and handguns now come with picatinny rails on them. While the original purpose was to use it to mount telescopic sights, there are now manufacturers of other accessories, such as carrying handles, tactical lights, bayonets, bipods, laser lights etc., who make their accessories compatible with picatinny rails. Therefore, the same accessory can be easily mounted on to multiple firearms.