Petra is approximately 134 miles (215 km) from the northern city of Madaba and most easily traveled by way of the Desert Highway. At its quickest, the ride takes three hours. If you want to make a proper road trip out of it, Route 65 is an alternate road to the west which runs alongside the Dead Sea. There are several attractions along the way that are worth including into your itinerary.
If you want a car but don't want to drive, consider hiring a local guide or driver. Alternatively, there are plenty of taxi stands to be found in town and sometimes a shared vehicle can mean a better deal on your fare. The cheapest option is traveling by minibus but be sure you have plenty of time in your schedule as they don't run on a very reliable timetable. While slightly out of the way, you could catch a taxi up to Amman and take a direct tourist bus from there.
For a trip that integrates both Madaba and Petra, see this 7-day Jordan itinerary.
By Private Transfer
Duration: 3-4 hours
Taking a car from Madaba to Petra allows for the most freedom and flexibility. Once you're away from crowded city streets and on the highways, you'll find the roads to be in good condition with plenty of signage. There are restaurants and gas stations on the way when you decide you need a break. If you don't plan to stop that often, your ride should be about three hours.
If your itinerary allows for additional stops, drive the Jordan Valley Highway, or Route 65. This corridor skirts the coast of the Dead Sea so you can stop for a soak in its famously salty waters or stay a night at one of its many resorts. You could also stretch your legs with a wilderness hike around Dana Biosphere Reserve or the historic Shobak Castle. While you can wander around the castle on your own (you will need to buy an entrance ticket or have your Jordan Pass) most of the trails at the reserve require a guide so plan ahead if that's a stop you want to make.
Duration: 3-4 hours
Taxi cabs are easy to find and a reliable way to get around. Your hotel can help you book one ahead of time or simply hail one on the street. This option is much cheaper than a rental car and depending on the number of passengers and expected stops, fares can sometimes be negotiated. Additionally, it may be worth your time to check ridesharing apps to see what's available at your departure time.
For public transportation, a minibus is about the only option. They run at different times throughout the day and won't leave until a bus is full so be prepared for a wait. Also, check ahead for Friday operations as the buses don't usually run on that day of the week. If you'd like, your hotel can usually book a ticket in advance for you. There is no direct tourist bus from Madaba but you could backtrack to Amman and catch one from the Abdali station. They're not as cheap as a minibus but the ride will be air-conditioned and considerably more comfortable.