According to the previous Code of Canon Law (promulgated 27 May 1917; effective 19 May 1918), it is illicit for a Catholic to be a Freemason, and vice versa. I quote from a Masonic webpage:
... Those who join a Masonic sect or other societies of the same sort, which plot against the Church or against legitimate civil authority, incur ipso facto an excommunication simply reserved to the Holy See. (c. 2335). [p. 924.]
Simply Reserved to the Holy See (4) 1. Masonic Societies (c. 2335). a. The censure is incurred if the society is one which plots against Church or State, openly or secretly, whether members are secret or not, bound by oath or not. Cappelo thinks Socialists are included. Communist party certainly is. Knights of Pythias, Odd Fellows, Sons of Temperance, are forbidden as intrinsically wrong, but not under censure (Holy Office, 20 June, 1895, 18 Jan., 1896).
b. Conditions for absolution: total withdrawal from the society, promise to have nothing to do with it and pay no more dues, to repair scandal as far as possible, to turn over insignia, etc., to withdraw name from rolls as soon as this can be done
without grave loss (Holy Office, 7 March 1883; Gasparri-Serédi, Fontes, n. 1080, Vol. IV, p. 412).
c. In the case of the Knights of Pythias, Odd Fellows, Sons of Temperance, no censure has been incurred. The conditions for absolution of the sin are the same as above except that, to avoid grave loss, a person may continue paying dues. The confessor must refer each case to the Apostolic Delegate or his Metropolitan (Holy Office, 18 Jan., 1896; Ecclesiastical Review, Vol. 14, p. 361). [p. 960.]
This stricture is not defunct. The new 1983 Code of Canon Law states:
Can. 1373 A person who publicly incites among subjects animosities or hatred against the Apostolic See or an ordinary because of some act of power or ecclesiastical ministry or provokes subjects to disobey them is to be punished by an interdict or other just penalties.
Can. 1374 A person who joins an association which plots against the Church is to be punished with a just penalty; however, a person who promotes or directs an association of this kind is to be punished with an interdict.
Both Codes imply that a person genuinely unaware of the anti-ecclesial intentions of the assocation they join, is not entirely guilty. Once, however, a person promotes such an organization, or knowingly continues in it once he or she is aware of its anti-ecclesial aims, he or she is culpable.
Although this Code does not reference the Masons by name, as the 1918 Code had, a 1983 CDF "Declaration on Masonic Associations" clarified exactly canon 1374, thus:
...the Church’s negative judgment in regard to Masonic association remains unchanged since their principles have always been considered irreconcilable with the doctrine of the Church and therefore membership in them remains forbidden. The faithful who enrol in Masonic associations are in a state of grave sin and may not receive Holy Communion.
Catherine Caridi, a Catholic canonist, addresses the question many may have, namely, "What's so bad about Freemasonry, anyway?" She answers thus:
Over 100 years ago, Pope Leo XIII addressed the aims of Freemasonry in his encyclical Humanum Genus. The pope pointed out that their “fundamental doctrine… is that human nature and human reason ought in all things to be mistress and guide,” which on the surface does not necessarily appear objectionable. But a consequence of this foundational belief is that “they deny that anything has been taught by God… And since it is the special and exclusive duty of the Catholic Church fully to set forth in words truths divinely received, to teach, besides other divine helps to salvation, the authority of its office, and to defend it…, it is against the Church that the rage and attack of the enemies are principally directed” (12).