The answer depends on what kind of nonprofit we're talking about.
The 501(c)(4), which is called a social welfare organization, may engage in a variety of political activities, some of which are unrestricted and others that are restricted to some degree. Lobbying for legislative change is treated liberally, while advocating for a particular political candidate is more restricted. But political activity should be only part of the purpose of the 501(c)(4) in order to remain tax exempt.
In most cases, contributions to a 501(c)(4) are not tax deductible. On the other hand, donations and the names of donors to a 501(c)(4) are not subject to disclosure rules, making them popular and controversial, during political campaigns.
Examples of 501(c)(4) organizations include AARP and the NRA. Both have social purposes beyond lobbying, but do engage in extensive politically-oriented activities. AARP lobbies on the behalf of older Americans in addition to providing services and education to those citizens. The NRA is a membership organization that provides services to gun owners and lobbies for pro-gun legislation.The balance between social welfare and lobbying is what makes this nonprofit designation so difficult to define and regulate.
A 501(c)(3), on the other hand, is not allowed to engage in political activity and only limited lobbying. The organization can engage in general voter education about issues, even those that could affect its cause, as long as all points of view are represented. A forum with all candidates or both sides of a ballot initiative are examples of acceptable political activity. Although a 501(c)(3) may not take political sides, it may spend up to 20% of its operating budget on so-called lobbying efforts if it follows the rules of "non partisanship." It's tricky ground though, so organizations need to know the rules thoroughly and tread very carefully.
To make the landscape of nonprofits even more confusing, it is not unusual to have both of these classifications closely affiliated with one another. For instance, the NRA is affiliated with the NRA Foundation, which operates as a 501(c)(3) which can provide a tax deduction for contributions. AARP also is affiliated with a foundation for fundraising purposes. Some 501(c)(3) charities are affiliated with 501(c)(4) organizations for lobbying purposes. Planned Parenthood is such one charity. Its lobbying arm is the Planned Parenthood Action Fund.
It's really no wonder that many of us are confused about who's who, and who is allowed to do what when it comes to nonprofits.