There are two main rosters that are relevant: the 40-man roster and the 25-man roster. The 25-man roster is the list of players currently on the Major League team: the guys who sit in the dugout or bullpen, and either start the game or can be substituted mid-game by the manager. The 40-man roster consists of all of them plus some injured guys and some minor-league guys. It's perhaps the more important roster on the backend. (For one thing, the 40-man exists year-round, while the 25-man only exists during the season.)
So first I'll explain the ways someone can be added to or removed from the 40-man roster, and then I'll explain transactions that can happen within the 40-man roster. But first, let me explain "waivers", which are an important prerequisite to understanding some later concepts.
A team can test to see what sort of interest there is for a player by putting him on waivers. This is a process by which all teams in MLB can decide whether to place a claim on a player or not. Each team is given a chance (in reverse order of record) until either one team has claimed a player or until they've all said no. If Team B claims a player from Team A, Team A has a few choices: They can either just take the player back as if nothing happened, they can let the player go to Team B without getting anything in return (except Team B has to assume everything left on the player's salary contract, which sometimes is actually quite a lot for team A to get in return) or they can negotiate a trade with Team B. (Sometimes they could've negotiated a trade with Team B anyway, but not after August 1st.) If no one claims the player, then the player is said to have cleared waivers, which gives his team some more flexibility in terms of roster moves.
Now, then, WAYS TO MOVE ONTO OR OFF OF THE 40-MAN ROSTER:
First, a player can be signed to a major-league contract. This doesn't necessarily put him on the 25-man roster, but it by definition puts him on the 40-man. A minor-league contract means you're not on the 40-man roster.
If a team wants to call up a minor-league player to the majors who is not on the 40-man roster, they can purchase his contract. This converts his contract to a major-league one, and puts him on the 40-man roster.
If a team needs to get a player off the 40-man roster, and he's injured, they can place him on the 60-day disabled list. This obviously can only be done if the injury will keep the player out for at least 60 days (from the last date he played, not from the date the 60-day DL assignment is made). Activating him from the disabled list restores him to the 40-man roster.
If a team needs to get rid of a healthy player, they can always trade him (if he's cleared waivers or if it's before August 1) or release him. They can also outright him to the minors, but they can only do this if he's cleared waivers, and they need his permission to do this if he's been on a 25-man roster for enough years or if he's ever been outrighted before.
A player can be designated for assignment. This removes him from the 25- and 40-man rosters immediately, and puts him into a sort of limbo for up to 10 days while the team decides what to actually do with him (which will end up being one of the three things from the previous paragraph).
And one more way a player can be added to a 40-man roster is via the Rule 5 draft. At a certain point in the fall, all players not on 40-man rosters (with the exception of players who have only been in professional baseball for a couple of years or less) are available in this draft for any other team to take them for a small fee. A player taken in this draft must remain on the new team's 40-man roster without being optioned (see below) for one year. If they can do this for an entire year, they can keep the player; but if not, they have to offer the player back to the original team before optioning or releasing him.
TRANSACTIONS THAT HAPPEN WITHIN THE 40-MAN ROSTER:
The most common transaction is a player being optioned or "put on optional assignment" to a minor league team. A player can only be optioned 3 times in his career, or 4 times if they all happen early enough in his career. Additional options in the same year beyond the first don't count against this total because the player is said to be on an option year for the whole year in which an option happens. Even the expected minor-league assignment of young prospects on the 40-man at the start of the season, or activating someone from the 60-day disabled list and assigning them to the minors, count as optioning the player. Players with enough major-league experience can't be optioned without their permission.
And, of course, there's the 15-day disabled list. Players on this list stay on the 40-man but are removed from the 25-man for at least 15 days (from the date they last played, not the date they were assigned to the DL).
Of course, an optioned player can be recalled, or "called up" to the majors, at any time. The one exception is that a player who was optioned in the past 10 days can only be called up to replace an injured player. Many players are called up after September 1st, because the 25-man roster can actually have as many as 40 players on it from September 1st until the end of the regular season, and after that, choosing to not have a player on the postseason roster doesn't actually require optioning or DLing them.
I think that's everything. Clear?