The title is misleading. You're not fixing anything except the vehicle you're working on. The master cylinder is what we're changing. The job is pretty easy unless this is in a van or other vehicle with a cowl hanging over or if there are parts in the way. You need to deal with them first. Snce I have no way of knowing of what you're working on, you have to figure this out. I have no control over your work, the quality of parts you use or any other circumstance of your situation. You need to be satisfied and comfortable with your skill level before you proceed or drive your newly repaired vehicle in traffic. If there's any doubt, call a mechanic. Death, injury, or property damage can result from anything fixed improperly and brakes are no exception. Do any repairs at your own risk.
The master cylinder on any car, truck or motorcycle with hydraulic brakes (or clutch) is just a cylinder with a couple of pistons inside that press fluid into into steel lines. This in turn displaces pistons that squeeze pads or shoes onto a spinning drum or disk inside the road wheel. The wheels slow and stop transferring the moving energy of your ride into heat. That's all there is to it. Even if you have anti lock brakes, traction or stability control, the brakes work the same way. The reason it works is because the fluid isn't compressible and transfers its volume somewhere else. As long as the parts holding the fluid inside are intact and nothing can leak out or in, you have brakes. As with any system like this there are weak links. In the case of the braking system, it's the seals that fail first. If you live where there's salt on the roads, the lines themselves can rust too. In the case of the master cylinder, it's because the seals holding the fluid in or those pushing the fluid into the lines have failed.
When the brake pedal is spongy, you'll need to look around the car for leaks. Check inside the wheels and around the left side of the body, all along the lines and hoses. If there's any leakage, fix these first before condemning the master cylinder. It could still be bad, but look for the obvious first. So there are no other leaks, the pedal is still spongy, or the hydraulic system "lets go" at a stop and/or you see signs of fluid leaks at the master cylinder or brake booster. The master cylinder and brake booster both live toward the rear of the engine compartment on the left side of the vehicle for the most part. Most vehicles have power brakes and hence a brake booster. If you have an older car or truck with manual brakes, the master cylinder will be right on the firewall. This is very rare nowadays. I've owned or co-owned about 20 cars and trucks and only one, a 1975 Chevy Nova, had manual brakes.
There are several schools of thought to do this job. I'm giving you mine and you can take it leave it. I prefer to bench bleed because there's never an assistant around when you need one. With this method there's a lot less walking back and forth and bending down. I'm getting older and having to bend into tight spaces a lot; my knees protest every time I do it. If you have a suction gun or turkey baster, use it to suck the fluid out of the reservoir. If not, just undo the lines with the appropriate sized line wrench and leave the cap or cover on, placing a rag underneath it. Use a 15mm or 5/8 inch (these are the most common sizes) to remove the nuts holding the master cylinder from the brake booster. There are two studs, but sometimes there are two nuts on one of them. Makes sure all the nuts are off before you try freeing the cylinder from its home, otherwise you could break the stud or one of the ears off your core. That would be bad. Use a rag to hold the master cylinder as you take it out from under the hood. Be careful; brake fluid eats paint and plastic. Take the part and dump out as much fluid as you can, making sure it's clean. Trust me, it'll make life easier taking it to the auto parts store.
Speaking of the auto parts store, make sure the unit you buy has a reservoir. If it doesn't, you'll have to reuse the one off the old part. Remove the roll pins, screws or other device used to hold it on. If they're roll pins, use a punch and a hammer being careful not to damage the plastic reservoir or aluminum cylinder. Clean the newly removed part with brake cleaner or denatured alcohol. You can also use soap and water, but it must be dry before you install it and you need compressed air to get the moisture out. Don't be too picky getting it clean, but get as much of the old fluid out as you can.
Parts are parts and from my experience, it really doesn't matter if the part you buy is new or re manufactured. New is obviously better, but if the part is made in China walk away. If you're a Monty Python fan, run away! Don't buy the dad blamed part and put in you car, because you will be taking it out within a week. Autozone sold me one of these beauties and it failed the moment I pressed on the brake pedal. The few dollars you save are not worth it. It literally cost me four more dollars to get a better part at Advance that I didn't have to pull out again. Again, do not buy a brake part made or rebuilt in Chinaland. You've been warned.
Use the correct brake fluid. Most cars and trucks use D.O.T. 3 or 4 and in fact the fluid will probably be compatible with both (these are glycol based). This fluid is also hygroscopic meaning it absorbs and disperses water, which helps keep wear on seals and lines in check. D.O.T. 5 is a silicone based fluid that doesn't absorb water, but still allows it to settle in low areas of the system. This could allow the lines to rust from the inside out and as a result, needs to be changed much more frequently. It's usually used in racing and some custom builds. Mixing glycol and silicone fluids will kill the seals and ruin your brakes. My advice is not to use it unless your braking system calls for it.
Put the reservoir on the new master cylinder using clean brake fluid (do not use ANY oil to do this or you'll wreck them) to lubricate the o rings, and if the new part has a reservoir skip this step. Carefully put the new part in a vise and follow the instructions on the included bleeding kit. Usually, these are two plugs that thread into the bungs where the lines go and are attached to lines that are directed back into the reservoir. Fill the reservoir with fluid, but not over the "full" or "max" line and using a Phillips screwdriver, gently push into the plunger until the air is purged out of the part.
Take your hoses, fluid and all as one unit and bolt it to the brake booster. Remove the plugs from the master cylinder, one at a time and thread the lines in. Step on the brake pedal and make sure it's firm. and if it isn't you'll have to bleed each wheel individually, starting with the one farthest away from the part you replaced. I just cap off the lines I took off and let the fluid leak out a bit before I tighten them up and I've never had an issue with air getting into the lines. Air always rises, so bleeding the brake system after replacing the master cylinder isn't necessary. If the fluid is more than two years old, then you should bleed it as soon as possible anyway. Maranatha!