What we call electronic flash or simply flash is burst of lights produced by flash of photons generated by an electrical charge that is accumulated in a component called a capacitor and then directed through a glass of tube containing xenon gas, which absorbs the energy and emits the brief flash. For most of the pop-up flash which comes built-in with most of the advanced DSLRs, the full burst of light lasts about 1/1000th of a second which is enough to provide illumination to capture a subject 10 feet away using aperture of f/4 at ISO 100. But, usually in daily practice, depending upon environment you are in and distance to your subject, you would change the Aperture, ISO and Shutter Speed to get the best result. As you noticed, the built-in flash is somewhat limited in range; and that is why professional photographers use external flash units like SB-600, SB-700, SB-800 or SB-900 extensively to meet different lighting challenges they face in every day shooting.
Most of the DSLRs come with built-in electronic flash and have accessory shoe where you can plug external flash units directly or via cable. An electronic flash whether built-in or external unit is triggered at the instant of exposure, during a period when the sensor is fully exposed (by opening the shutter). DSLR has a vertically traveling shutter that consists of two curtains (in most of the DSLRs). The first curtain opens and moves to the opposite side of the frame, at which point the shutter is completely open. Now, depending on what kind of flash sync mode is being used, flash can be triggered at this point (called first-curtain sync or front-curtain sync), making the flash exposure. Then, after a delay (defined by shutter speed which vary from 30 seconds to 1/250th second), a second curtain begins to move across the sensor plane, covering up the sensor again. If the flash is triggered just before the second curtain starts to close, we call it second-curtain sync or rare-curtain sync. Usually, in both cases, a shutter speed of 1/250th second is the maximum speed that can be used (which is called flash sync speed) unless you are using the high-speed 1/320th second sync.
There are few more flash sync modes available that you can use in your DSLR camera and you can learn more about them in my previous blogs choosing a flash sync mode on Nikon D90 and slow sync flash photography where I explained about Front Curtain Flash and Rear Curtain Flash in detail.