Background: Methods described in the literature for designing shielding for treatment rooms for radiotherapy systems often involve assumptions that lead to overestimations of the wall thicknesses required to meet dose rate constraints outside the room. The Leksell Gamma Knife (LGK) has built-in shielding that results in primarily scattered photons leaking into the room. The field of leakage radiation, therefore, has a wide spectrum of energies, up to the primary energies of cobalt-60, and is highly anisotropic, making standard site planning methods difficult to adapt to the LGK. Monte Carlo (MC) simulations are an alternative for dose calculations but are computationally expensive. Purpose: The aim was to develop a dose calculation algorithm for fast estimations of dose rates outside the barriers of a treatment room. The algorithm could then be employed in iterative methods to optimize treatment room parameters such as wall thicknesses and position of the LKG unit. Methods: The algorithm uses pre-calculated MC simulation data in two steps. First, it uses phase spaces that describe single photons in the radiation field around the LGK. Using each photon's position and direction, they are raytraced to the outside of the room. Based on their energy, angle of incidence to the barrier, and the barrier's thickness, a depth-dose profile is sampled from a precalculated library of profiles. The contribution from each photon is added to the space outside the barriers, giving the total dose distribution. The barrier thicknesses are optimized by iteratively running the algorithm and finding the minimum thickness required to keep the resulting maximum dose rate outside below a given upper limit. Results: Comparisons between dose distributions from the dose algorithm and full MC simulations of two typical rooms show good agreement, with the maximum dose rate outside each barrier being estimated within what represents a 2 cm error in concrete barrier thickness. The algorithm is successfully used in optimizing the barrier thicknesses and the results show potential decreases in most barriers' thickness, compared to a conventional method. Conclusions: The algorithm is a promising alternative to conventional barrier design methods, eliminating several shortcomings of the latter whilst being significantly faster than a full MC simulation. The flexibility of the algorithm would further enable solving more complex cases, such as optimizing the LGK position or barrier material to further reduce material use and cost. K E Y W O R D S dose algorithm, gamma knife, shielding optimization 3852