Mastodon is free and open-source software for running self-hosted social networking services. It has microblogging features similar to Twitter, which are offered by a large number of independently run nodes, known as instances, each with its own code of conduct, terms of service, privacy policy, privacy options, and content moderation policies.
Simply put, it puts the control of data into the user's hands, not in a single corporation. Mastodon is just one of many platforms on the Fediverse.
The Fediverse is a network of interconnected servers, which communicate with each other based on decentralized networking protocols, primarily ActivityPub. These servers can be used for any number of different services, such as social media or file hosting. Some examples of popular services are Mastodon, PeerTube (video hosting, like YouTube), and Pixelfed (photo sharing, like Instagram). These services can interact with each other, so you can follow Pixelfed accounts from your Mastodon accounts, for example.
ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client-to-server API for creating, updating, and deleting content, as well as a federated server-to-server API for delivering notifications and subscribing to content.